QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#679537 | #7685. Barkley II | jimmyywang | WA | 115ms | 35412kb | C++14 | 2.1kb | 2024-10-26 17:49:30 | 2024-10-26 17:49:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define f(i,a,b) for(int i=a;i<=b;i++)
ll T;
ll n,m;
ll a[500010];
ll t[500010];
#define lb(x) (x&(-x))
void add(ll k){
while(k<=n)t[k]++,k+=lb(k);
}ll ask(ll k){
ll res=0;while(k)res+=t[k],k-=lb(k);
return res;
}
ll pre[500010];
ll pos[500010];
vector<ll>e[500010];
vector<ll>in;
#define pb push_back
struct node{ll id,x,o;};
ll cnt;
ll res[4000010];
ll w[4000010];
vector<node>q[500010];
int main(){
cin>>T;while(T--){
cin>>n>>m;
in.clear();
f(i,1,n){
cin>>a[i];
pos[i]=0,t[i]=0;
}
f(i,1,n){
pos[i]=pre[a[i]]+1;
pre[a[i]]=i;e[a[i]].pb(i);
if(e[a[i]].size()==1){
in.pb(a[i]),in.pb(a[i]+1);
e[a[i]].pb(0),e[a[i]].pb(n+1);
}
}cnt=0;sort(in.begin(),in.end());
for(int qwq=0;qwq<in.size();qwq++){
ll x=in[qwq];
if(qwq&&x==in[qwq-1])continue;
if(!e[x].size()){
w[++cnt]=x,q[n].pb({cnt,1,1});
// cout<<x<<" "<<1<<" "<<n<<endl;
continue;
}sort(e[x].begin(),e[x].end());
for(int i=0;i<e[x].size()-1;i++){
ll l=e[x][i]+1,r=e[x][i+1]-1;
if(l<=r){
w[++cnt]=x;
q[r].pb({cnt,l,1});
q[l-1].pb({cnt,l,-1});
// cout<<x<<" "<<l<<" "<<r<<endl;
}
}
}
// f(i,1,n)cout<<pos[i]<<" ";cout<<endl;
f(i,1,n){
add(pos[i]);
for(int j=0;j<q[i].size();j++){
res[q[i][j].id]+=ask(q[i][j].x)*q[i][j].o;
}
}f(i,1,cnt)res[i]-=w[i];
ll mx=-0x3f3f3f3f;f(i,1,cnt)mx=max(mx,res[i]);
// f(i,1,cnt)cout<<res[i]<<" "<<w[i]<<endl;
cout<<mx<<endl;
f(i,1,n)pre[a[i]]=0,e[a[i]].clear();
f(i,0,n+1)q[i].clear();
f(i,1,cnt)res[i]=w[i]=0;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 33980kb
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: 115ms
memory: 35412kb
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 1 2 4 2 4 3 3 4 4 4 5 2 3 0 3 4 5 7 6 3 3 2 2 4 5 7 2 3 0 6 2 2 3 2 5 3 3 3 3 2 5 2 1 3 5 3 3 3 8 4 2 5 4 4 2 5 4 2 2 4 3 3 3 2 3 1 7 7 6 3 5 4 3 3 4 -1 6 3 4 3 3 4 0 3 1 4 5 4 5 3 1 2 2 1 4 4 6 4 3 4 2 1 5 4 7 3 -1 6 5 3 5 4 4 5 4 6 5 6 7 4 4 5 4 4 3 3 4 3 -2 3 2 1 2 5 1 2 1 6 5 2 2 5 5 4 3 -2 6 ...
result:
wrong answer 2nd numbers differ - expected: '5', found: '1'