QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#254959 | #7685. Barkley II | sfjh | WA | 57ms | 9896kb | C++14 | 1.4kb | 2023-11-18 14:20:27 | 2023-11-18 14:20:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define fer(i,a,b) for(int i=a;i<=b;i++)
#define fdr(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
const int N=5e5+10;
int n,m;
int a[N],c[N];
int pos[N],p[N];
int lowbit(int x){
return x&(-x);
}
int getsum(int x){
int ans=0;
while(x>0){
ans+=c[x];
x-=lowbit(x);
}
return ans;
}
void add(int x,int k){
while(x<=n){
c[x]+=k;
x+=lowbit(x);
}
}
bool cmp(array<int,3> A,array<int,3> B){
return A[1]<B[1];
}
void solve(){
cin>>n>>m;
vector<array<int,3>> v;
fer(i,1,n) cin>>a[i],pos[i]=0,p[i]=0,c[i]=0;
fer(i,1,n){
if(pos[a[i]]&&a[i]<=n&&i-pos[a[i]]>=2){
v.pb({pos[a[i]]+1,i-1,a[i]});
}
pos[a[i]]=i;
}
fer(i,1,n){
if(n>=pos[i]){
if(pos[i]) v.pb({1,pos[i]-1,i});
v.pb({pos[i]+1,n,i});
}
}
sort(v.begin(),v.end(),cmp);
int num=v.size();
int nw=1,ans=0;
fer(i,0,num-1){
int l=v[i][0],r=v[i][1],mex=v[i][2];
// cout<<l<<' '<<r<<' '<<mex<<endl;
}
fer(i,0,num-1){
int l=v[i][0],r=v[i][1],mex=v[i][2];
while(nw<=r){
if(p[a[nw]]){
add(p[a[nw]],-1);
}
add(nw,1);
p[a[nw]]=nw;
nw++;
}
ans=max(ans,getsum(r)-getsum(l-1)-mex);
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9896kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
2 3
result:
ok 2 number(s): "2 3"
Test #2:
score: -100
Wrong Answer
time: 57ms
memory: 9636kb
input:
50000 10 19 12 6 1 12 11 15 4 1 13 18 10 8 8 7 6 7 6 2 2 3 4 8 10 6 3 2 6 6 5 2 3 4 5 6 10 11 6 3 7 9 2 1 2 10 10 4 10 6 6 1 2 6 1 1 3 4 2 1 10 9 8 5 3 9 1 7 5 5 1 1 10 5 1 4 3 2 5 4 5 3 5 2 10 14 3 8 12 10 4 2 3 13 7 3 10 14 5 5 12 2 8 1 13 9 8 5 10 7 5 5 6 6 1 5 3 7 3 4 10 7 5 1 4 6 1 6 4 3 7 5 10...
output:
6 5 4 4 4 5 3 5 2 4 4 5 2 4 2 6 5 5 3 5 5 2 4 3 4 4 3 2 4 5 5 2 3 3 4 5 3 3 7 3 2 5 6 2 3 2 3 4 3 4 4 4 4 4 4 4 5 3 5 4 2 4 2 3 6 3 3 2 6 3 4 4 4 3 4 4 1 4 4 4 4 4 4 5 1 4 4 5 4 3 4 5 3 2 4 6 4 4 6 3 4 3 3 3 3 3 3 2 3 3 3 5 2 4 2 5 5 3 3 2 4 4 6 4 4 4 3 4 6 2 5 5 3 4 3 3 4 3 4 3 4 3 5 5 4 3 3 6 6 3 ...
result:
wrong answer 5th numbers differ - expected: '2', found: '4'