跳到正文

题解

题解:P10642 [BalticOI 2022 Day1] Art Collection

shinzAnmono约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月23日
篇幅
约 2 分钟
题目
P10642

版本

  1. v1当前

考虑以下两个询问:

  • {1,2,…,n}\{1,2,\ldots,n\}
  • {2,…,n,1}\{2,\ldots,n,1\}

设第一个询问返回的答案为 xx,第二个询问返回的答案为 yy,可以发现 xx 即为原排列中子序列 (i,1)(i,1) 的个数加上中间 2,3,…,n2,3,\ldots,n 的答案,第二个询问同理,设 (i,1)(i,1) 的个数为 AA,(1,i)(1,i) 的个数为 BB,则 A+B=n−1,A−B=x−yA+B=n-1,A-B=x-y。可以求出 AA,那么我们就确定了 11 的位置,其他同理。

考虑询问以下序列:

  • {1,2,…,n}\{1,2,\ldots,n\}
  • {2,…,n,1}\{2,\ldots,n,1\}
  •           ⋮\ \ \ \ \ \ \ \ \ \ \vdots
  • {n,1,…,n−1}\{n,1,\ldots,n-1\}

我们发现相邻两个序列只有首尾不同,所以可以通过重复利用,达到 nn 次询问,即可通过本题。

C++
#include<iostream>
#include<algorithm>
#include<vector>
const int sz=4010;
void answer(std::vector<int>);
int publish(std::vector<int>);
int f[sz];
void solve(int N){
    std::vector<int>P(N);
    for(int i=1;i<=N;i++){
        std::vector<int>R;
        for(int j=i;j<=N;j++)R.push_back(j);
        for(int j=1;j<i;j++)R.push_back(j);
        f[i]=publish(R);
    }
    for(int i=1;i<=N;i++)P[(N+f[i]-f[i%N+1]-1)/2]=i;
    answer(P);
}
原文