QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#777106 | #7685. Barkley II | doyo | WA | 49ms | 6512kb | C++20 | 1.8kb | 2024-11-23 22:45:03 | 2024-11-23 22:45:04 |
Judging History
answer
#include <bits/stdc++.h>
#define N 500001
#define FOR(i,j,k) for(int i=j;i<=k;++i)
#define For(i,j,k) for(int i=j;i>=k;--i)
#define int long long
using namespace std;
struct note{long long l,r;int id; int ans;}q[N*2];
vector<int> pos[N];
void work(){
int i,j,s1,s2,L=1,R=0;
int n,m,numq=0;
long long sum = 0;
cin >> n >> m;
vector<int> c(n + 1);
vector<int> cnt(m + 1);
vector<int> b(n + 1); //belong属于哪个块
//vector<int> ans(numq + 1);
s1=sqrt(n);s2=1;
FOR(i,1,n) pos[i].clear();
for(i=1,j=1;i<=n;i++,j++){
if(j==s1+1){j=1;s2++;}
cin >> c[i]; b[i]=s2;
pos[c[i]].push_back(i);
}//分块
FOR(i,1,n){
int lft = 1;
for(auto pl:pos[i]){
++numq;
q[numq].id = i;
q[numq].l = lft;
q[numq].r = pl-1;
if(q[numq].l>q[numq].r) --numq;
lft = pl+1;
}
++numq;
q[numq].id = i;
q[numq].l = lft;
q[numq].r = n;
if(q[numq].l>q[numq].r) --numq;
}
auto cmp=[&](note x,note y) -> bool{
if(b[x.l]^b[y.l]) return b[x.l]<b[y.l];
else if(b[x.l]&1) return x.r<y.r;
else return x.r>y.r;
}; //奇偶分块
int ans = 0;
sort(q+1,q + m + 1,cmp);
for(i=1;i<=m;i++){
while(L<q[i].l){
if(cnt[c[L]] == 1) sum--;
cnt[c[L++]]--;
}
while(L>q[i].l){
cnt[c[--L]]++;
if(cnt[c[L]] == 1) sum++;
}
while(R<q[i].r){
cnt[c[++R]]++;
if(cnt[c[R]] == 1) sum++;
}
while(R>q[i].r){
if(cnt[c[R]]== 1) sum--;
cnt[c[R--]]--;
}
q[i].ans = sum-q[i].id;
ans = max(q[i].ans,ans);
//ans[q[i].id] = sum;
}
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--){
work();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5932kb
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: 49ms
memory: 6512kb
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 2 4 3 7 4 4 4 5 2 3 6 6 7 5 7 6 5 5 6 2 6 8 7 2 5 5 6 2 2 3 4 5 3 3 7 3 2 5 6 1 3 5 3 3 3 8 6 6 5 7 4 4 5 4 6 6 6 3 7 3 6 3 3 7 7 6 6 7 4 3 3 4 4 6 3 4 6 6 4 5 5 9 4 5 7 5 3 5 2 2 5 6 6 8 4 3 4 5 5 5 7 7 3 2 6 5 3 5 4 4 5 6 6 5 6 7 7 4 5 7 4 7 3 7 6 6 6 5 4 2 5 4 2 3 6 5 2 6 5 5 4 3 5 6 6 6 ...
result:
wrong answer 303rd numbers differ - expected: '5', found: '6'