标签:back ons ack clu mes code scan include while
#include<bits/stdc++.h> using namespace std; const int N = 300010; vector<int>p[N]; int ans[N]; int main() { int t; scanf("%d",&t); while(t --) { int n,x; scanf("%d",&n); for(int i = 1;i <= n;i ++) p[i].clear(),ans[i] = -1; //重置数组 for(int i = 1;i <= n;i ++)//读入数据 { scanf("%d",&x); p[x].push_back(i); } int r = n + 1; for(int i = 1;i <= n;i ++) { int l = 0,now = 0; for(int j = 0;j < (int)p[i].size();j ++) { l = max(l,p[i][j] - now ); //相邻两个数字之间的距离 now = p[i][j]; } l = max(l , n - now + 1); //最后一个数字距离末尾的距离 if(l < r) { for(int j = l;j < r;j ++) ans[j] = i; //i 由小到大遍历,确保答案正确 r = l; } } for(int i = 1;i <= n;i ++) printf("%d ",ans[i]); puts(""); } return 0; }
C.k-Amazing Numbers(cf div2 673)
标签:back ons ack clu mes code scan include while
原文地址:https://www.cnblogs.com/zyz010206/p/13762525.html