QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#291539 | #7969. 套娃 | Famiglistmo | WA | 22ms | 14980kb | C++14 | 3.0kb | 2023-12-26 21:32:26 | 2023-12-26 21:32:27 |
Judging History
answer
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define mid ((l+r)>>1)
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e5+5;
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
int read(){
int s=0,w=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();};
while(isdigit(ch))s=s*10+(ch^48),ch=getchar();
return s*w;
}
struct Tree{
int mn,mnp;
}t[N<<2];
int a[N],mn[N],mx[N];
vector<int>vec[N],A[N],B[N];
vector<pii>cur;
int visl[N],visr[N];
int n;
void pushup(int rt){
t[rt].mn=min(t[ls].mn,t[rs].mn);
if(t[rt].mn==t[rs].mn)t[rt].mnp=t[rs].mnp;
if(t[rt].mn==t[ls].mn)t[rt].mnp=t[ls].mnp;
}
void build(int l,int r,int rt){
if(l==r)return t[rt].mnp=l,void();
build(l,mid,ls),build(mid+1,r,rs),pushup(rt);
}
void alter(int l,int r,int rt,int id,int v){
if(l==r)return t[rt].mn+=v,void();
if(id<=mid)alter(l,mid,ls,id,v);
else alter(mid+1,r,rs,id,v);
pushup(rt);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;++i)
cin>>a[i],vec[a[i]].push_back(i);
if(vec[0].empty()){
for(int i=1;i<=n;++i)putchar('1'),putchar(' ');
return 0;
}
for(int i=1;i<=n;++i)
mn[i]=n+1,mx[i]=0;
mn[0]=1;
for(int i=0;i<(int)vec[0].size();++i){
int x=vec[0][i];
cur.push_back(pii(x,x));
if(i)
mx[0]=max(mx[0],x-vec[0][i-1]-1);
else mx[0]=max(mx[0],x-1);
}
mx[0]=max(mx[0],n-vec[0].back());
for(int v=1;v<=n;++v){
// cerr<<"v: "<<v<<endl;
// for(auto it:cur)
// cerr<<it.fi<<" "<<it.se<<endl;
vector<pii>nex;
for(auto it:cur) {
int l=it.fi,r=it.se;
if(visl[l]==v||visr[r]==v)continue;
visl[l]=visr[r]=v;
auto L=lower_bound(vec[v].begin(),vec[v].end(),r);
auto R=lower_bound(vec[v].begin(),vec[v].end(),l);
int left=0,right=n+1;
if(L!=vec[v].begin())
left=*--L,nex.push_back(pii(min(left,l),r));
if(R!=vec[v].end())
right=*R,nex.push_back(pii(l,max(r,right)));
if(left<l&&r<right)
mn[v]=min(mn[v],r-l+1),
mx[v]=max(mx[v],right-left-1);
}
sort(nex.begin(),nex.end(),[](pii x,pii y)
{ return x.se-x.fi<y.se-y.fi; });
swap(cur,nex);
}
// cerr<<"result:\n";
// for(int i=0;i<=n;++i)
// cerr<<mn[i]<<" "<<mx[i]<<endl;
for(int i=0;i<=n;++i)
if(mn[i]<=mx[i])
A[mn[i]].push_back(i),
B[mx[i]+1].push_back(i);
build(0,n+1,1);
for(int i=1;i<=n;++i){
for(auto x:A[i])alter(0,n+1,1,x,1);
for(auto x:B[i])alter(0,n+1,1,x,-1);
cout<<t[1].mnp<<' ';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 10608kb
input:
6 0 0 0 1 2 3
output:
2 3 4 0 0 0
result:
ok single line: '2 3 4 0 0 0 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 10500kb
input:
100 0 10 21 9 4 1 14 0 8 1 4 6 10 0 0 4 18 0 12 5 2 5 15 1 6 2 0 4 14 5 1 2 23 1 8 1 24 8 8 9 5 2 12 2 3 7 6 11 12 12 6 12 4 4 5 0 7 4 9 12 1 7 4 7 12 2 10 2 4 8 7 1 4 0 13 9 13 2 2 3 9 14 7 9 15 10 10 6 2 12 3 11 6 3 4 7 9 6 11 1
output:
2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok single line: '2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '
Test #3:
score: -100
Wrong Answer
time: 22ms
memory: 14980kb
input:
100000 127 145 474 139 36 135 75 670 76 433 206 214 283 56 214 440 147 280 244 190 181 565 31 550 261 93 526 404 125 390 17 552 5 364 53 337 52 506 277 279 15 248 46 61 826 69 166 297 171 289 150 175 111 151 317 342 166 13 199 152 308 19 156 347 205 166 45 115 177 235 422 425 109 4 658 232 347 370 4...
output:
2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 ...
result:
wrong answer 1st lines differ - expected: '2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '2 2 3 3 3 3 3 3 3 3 4 4 4 4 4 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '