QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#443715 | #6540. Beautiful Sequence | Firmino | WA | 2ms | 9848kb | C++14 | 1.2kb | 2024-06-15 16:21:13 | 2024-06-15 16:21:16 |
Judging History
answer
#include <iostream>
#include <algorithm>
using namespace std;
int read(){
int re=0,c=getchar();
while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') re=(re<<3)+(re<<1)+(c^48),c=getchar();
return re;
}
const int maxn=3e5+5;
struct P{
int v,id;
}ps[maxn];
int n,lg[maxn],a[maxn],sz[maxn],del[maxn],lp[maxn],rp[maxn],cd,tc,flag;
void init(){
a[n+1]=cd=0;
}
bool cmp(P x,P y){return x.v<y.v;}
void solve(){
n=read();
init();
for (int i=1;i<=n;i++) a[i]=read();
/*tc++;
if(tc==33){
cout<<n<<endl;
for (int i=1;i<=n;i++) cout<<a[i]<<" ";
cout<<endl;
}*/
sort(a+1,a+n+1);
int st=1;
for (int i=2;i<=n+1;i++){
if(a[i]!=a[i-1]) sz[++cd]=i-st,st=i;
}
for (int i=1;i<=cd;i++) del[i]=0,lp[i]=i-1,rp[i]=i+1,ps[i]=(P){sz[i],i};
sort(ps+1,ps+cd+1,cmp);
int ans=n-cd+1,dr=cd-1;
for (int i=1;i<=cd;i++){
int lc=0,tp=dr;
while(tp>ps[i].id&&lc<ps[i].v) lc++,tp=lp[tp];
if(lc<ps[i].v) continue;
ans++;
while(lc) del[dr]=1,dr=lp[dr],lc--;
del[ps[i].id]=1,lp[rp[ps[i].id]]=lp[ps[i].id],rp[lp[ps[i].id]]=rp[ps[i].id];
if(dr==ps[i].id) dr=lp[dr];
}
cout<<ans<<endl;
}
int main(){
int t=read();//if(t==300) flag=1;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9848kb
input:
2 6 1 1 2 3 3 4 5 1 2 2 3 3
output:
4 4
result:
ok 2 number(s): "4 4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 9748kb
input:
2 5 1 2 2 3 3 20 1 1 1 1 1 1 4 5 8 8 8 8 9 9 9 9 10 10 10 10
output:
4 17
result:
ok 2 number(s): "4 17"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 9672kb
input:
300 14 1 1 1 2 2 2 3 3 3 4 5 5 6 6 14 1 1 1 2 2 3 3 4 4 5 5 6 7 7 14 1 1 2 2 3 4 4 4 5 5 5 6 6 6 14 1 1 2 2 3 3 3 4 5 5 5 6 6 6 14 1 1 1 1 1 1 2 2 2 2 2 3 3 3 14 1 1 1 1 1 1 1 1 1 1 1 1 1 1 14 1 2 2 3 4 5 5 6 6 6 7 8 8 8 14 1 2 2 2 2 2 3 4 5 6 7 8 9 10 14 1 2 2 3 4 4 4 5 6 6 6 6 6 7 14 1 1 2 2 2 3 3...
output:
10 9 11 11 12 14 10 9 10 11 9 9 10 9 11 11 10 9 9 12 10 9 10 9 10 10 11 10 11 11 9 8 10 10 9 10 10 13 10 12 11 10 9 10 9 10 11 10 10 8 11 10 10 9 10 9 10 10 11 11 11 9 10 10 9 9 9 10 11 11 10 10 10 9 10 9 10 9 10 9 9 10 8 10 8 11 9 11 11 12 8 9 10 8 12 11 10 11 9 10 11 10 10 8 10 9 10 10 9 10 9 10 1...
result:
wrong answer 9th numbers differ - expected: '11', found: '10'