QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370227 | #6540. Beautiful Sequence | Graphcity | WA | 1ms | 4024kb | C++20 | 1.8kb | 2024-03-28 23:15:43 | 2024-03-28 23:15:44 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=3e5;
inline int read()
{
char ch=getchar();
int f=1,x=0;
while(ch>'9' || ch<'0')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
int n,m,a[Maxn+5],cnt[Maxn+5],id[Maxn+5];
int t[Maxn*4+5],sum[Maxn*4+5];
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
inline void push_up(int p)
{
sum[p]=sum[ls(p)]+sum[rs(p)];
t[p]=min(t[ls(p)],sum[ls(p)]+t[rs(p)]);
}
inline void Build(int l,int r,int p)
{
if(l==r) {t[p]=sum[p]=(cnt[l]>1?0:1); return;}
int mid=(l+r)>>1; Build(l,mid,ls(p)),Build(mid+1,r,rs(p)),push_up(p);
}
inline void Modify(int l,int r,int p,int pos,int k)
{
if(pos>r) return;
if(l==r) {sum[p]+=k,t[p]=sum[p]; return;}
int mid=(l+r)>>1;
if(pos<=mid) Modify(l,mid,ls(p),pos,k);
else Modify(mid+1,r,rs(p),pos,k);
push_up(p);
}
inline void Clear() {For(i,1,n) cnt[i]=0; m=0;}
inline void Solve()
{
vector<int> vx; n=read(); For(i,1,n) vx.push_back(a[i]=read());
sort(vx.begin(),vx.end()),vx.erase(unique(vx.begin(),vx.end()),vx.end()),m=vx.size();
For(i,1,n) a[i]=lower_bound(vx.begin(),vx.end(),a[i])-vx.begin()+1,cnt[a[i]]++;
if(m==1) {printf("%d\n",n); Clear(); return;}
Build(1,m-1,1),iota(id+1,id+m+1,1);
sort(id+1,id+m+1,[&](int a,int b){return cnt[a]>cnt[b];});
int ans=m; For(_,1,m)
{
int i=id[_]; Modify(1,m-1,1,i,-(cnt[i]>1?0:1)-1);
if(t[1]<0) Modify(1,m-1,1,i,(cnt[i]>1?0:1)+1);
else ans--;
} printf("%d\n",n-ans); Clear();
}
int main()
{
// freopen("1.in","r",stdin);
int T=read();
while(T--) Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
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: 0ms
memory: 4024kb
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: 1ms
memory: 3672kb
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 8 10 10 12 14 10 9 11 10 9 10 10 9 11 11 11 9 9 12 10 9 10 10 11 10 11 11 10 10 10 8 10 10 10 10 11 13 10 12 11 11 9 10 9 11 11 10 9 8 11 9 11 8 10 9 9 9 11 11 12 9 10 10 10 10 9 10 11 10 10 10 9 10 11 10 10 10 10 9 9 10 8 11 9 11 10 11 11 12 9 9 9 9 12 11 10 11 10 10 10 10 9 9 10 8 9 10 10 11 9 ...
result:
wrong answer 2nd numbers differ - expected: '9', found: '8'