QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276504 | #7685. Barkley II | 1677118046 | WA | 64ms | 21176kb | C++17 | 2.3kb | 2023-12-05 22:07:29 | 2023-12-05 22:07:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int nn=5e5+10;
const int n2=4e7+10;
typedef long long ll;
int A[nn];
struct node{
int lson,rson,num; //num维护区间值没出现+1,出现了更换位置
}tree[n2];
int cnt;
int root[nn];
int build(int l,int r){
int now=++cnt;
tree[now].num=0;
tree[now].lson=0;
tree[now].rson=0;
if(l==r)return now;
int mid=(l+r)/2;
tree[now].lson=build(l,mid);
tree[now].rson=build(mid+1,r);
return now;
}
int update(int l,int r,int pos,int pre,int val){//只修改一个故不用更新
int now=++cnt;
tree[now]=tree[pre];
tree[now].num+=val;
if(l==r){
return now;
}
int mid=(l+r)/2;
if(pos<=mid){
tree[now].lson=update(l,mid,pos,tree[pre].lson,val);
}else{
tree[now].rson=update(mid+1,r,pos,tree[pre].rson,val);
}
return now;
}
int query(int l,int r,int now,int pos){//pos这里表示截止位置,每一个now表示一个R,在R的情况下搜pos即为l,大于等于l的位置里的和都加起来
if(l==r){
return tree[now].num;
}
int mid=(l+r)/2;
if(mid>=pos){
return query(l,mid,tree[now].lson,pos)+tree[tree[now].rson].num;
}else{
return query(mid+1,r,tree[now].rson,pos);
}
}
int n,t,m;
map<ll,ll>vis;
int len;vector<int>XX[nn];
void init(){
cnt=0;
cin>>n>>m;
vis.clear();
for(int i=1;i<=m+1;i++)XX[i].clear();
for(int i=1;i<=n;i++){
cin>>A[i];
}
root[0]=build(1,n);
for(int i=1;i<=n;i++){
if(!vis.count(A[i])){
root[i]=update(1,n,i,root[i-1],1);
vis[A[i]]=i;
}else{
int pre=vis[A[i]];
vis[A[i]]=i;
root[i]=update(1,n,pre,root[i-1],-1);
root[i]=update(1,n,i,root[i],1);
}
}
}
void solve(){
init();
for(int i=1;i<=n;i++){
XX[A[i]].push_back(i);
}
int an=-1e9+10;
for(int i=1;i<=m+1;i++){
if(XX[i].empty()){
an=max(an,query(1,n,root[n],1)-i);
break;
}else{
int sz=XX[i].size();
for(int j=0;j<sz;j++){
//方向统一向右
if(j==0){//考虑左边部分
an=max(an,query(1,n,root[XX[i][j]-1],1)-i);
}
if(j!=sz-1){
an=max(an,query(1,n,root[XX[i][j+1]-1],XX[i][j]+1)-i);
}else{
an=max(an,query(1,n,root[n],XX[i][j]+1)-i);
}
}
}
}
cout<<an<<"\n";
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin>>t;
while(t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 20112kb
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: 0
Accepted
time: 64ms
memory: 21176kb
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:
ok 50000 numbers
Test #3:
score: -100
Wrong Answer
time: 63ms
memory: 19352kb
input:
100000 5 4 4 3 1 3 1 5 4 2 2 1 3 4 5 9 7 8 7 1 3 5 3 3 2 2 3 1 5 7 1 4 2 4 7 5 4 4 4 4 2 3 5 3 2 1 2 2 2 5 5 2 1 2 5 4 5 9 1 8 4 4 7 5 6 2 6 4 6 2 5 5 1 2 4 4 4 5 3 2 1 1 1 3 5 5 5 4 5 2 5 5 4 3 3 3 2 1 5 3 3 1 3 2 3 5 7 1 5 2 2 7 5 6 2 2 6 5 6 5 10 6 3 3 1 7 5 8 1 6 8 4 3 5 4 1 2 1 3 3 5 7 2 2 4 3 ...
output:
1 1 2 1 2 2 0 2 2 2 1 0 2 1 1 2 2 2 3 0 3 1 2 2 3 3 1 3 0 0 3 2 2 0 2 2 1 0 2 2 3 3 3 1 3 2 2 3 2 3 2 1 2 3 1 3 3 1 2 3 1 1 2 2 2 2 0 1 0 1 0 2 1 3 0 2 2 3 2 2 1 3 1 3 1 1 1 3 1 1 4 0 1 3 2 2 2 0 3 2 4 3 3 2 1 0 4 4 3 2 1 2 1 2 3 2 3 4 4 3 0 0 1 4 1 3 3 2 3 1 3 4 3 1 2 2 3 2 3 2 3 3 1 3 1 1 4 1 1 3 ...
result:
wrong answer 2377th numbers differ - expected: '-1', found: '0'