QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#258190#5543. The Only Modehank55663#WA 15ms5324kbC++143.1kb2023-11-19 15:53:532023-11-19 15:53:53

Judging History

你现在查看的是最新测评结果

  • [2023-11-19 15:53:53]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:5324kb
  • [2023-11-19 15:53:53]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define pdd pair<double,double>
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acos(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
vector<pair<pair<pii,int>,pii> >  a;
int ans;
int S[200005];
void add(int x,int v){
    x+=100001;
    for(int i =x;i<200005;i+=i&-i){
        S[i]=min(S[i],v);
    }
}
int query(int x){
    x+=100001;
    int res=1e9;
    for(int i =x;i>0;i-=i&-i){
        res=min(res,S[i]);
    }
    return res;
}
void reset(int x){
    x+=100001;
    for(int i =x;i<100005;i+=i&-i){
        S[i]=1e9;
    }
}
void cdq(int l,int r){
    if(l==r)return;
    int mid=(l+r)/2;
    cdq(l,mid);
    cdq(mid+1,r);
    vector<pair<pair<pii,int> ,pii> > v;
    int x=l,y=mid+1;
    vector<int> re;
    while(x!=mid+1||y!=r+1){
    //    printf("%d %d %d %d\n",x,y,l,r);
     //   getchar();
        int op;
        if(x==mid+1){
            op=1;
        }
        else if(y==r+1){
            op=0;
        }else if(a[x].x.x.y<=a[y].x.x.y){
            op=0;
        }else{
            op=1;
        }
        if(op==0){
            assert(x<a.size());
            v.pb(a[x]);
            if(a[x].y.x==0){
                re.pb(a[x].x.y);
                add(a[x].x.y,a[x].y.y);
            }
            x++;
        }
        else{
            assert(y<a.size());
            v.pb(a[y]);
            if(a[y].y.x==1){
                
                ans=max(ans,a[y].y.y-query(a[y].x.y));
                //if(a[y].y.y-query(a[y].x.y)==5){
                  //  printf("@@ %d %d%d %d %d %d %d\n",l,r,a[y].x.x.x,a[y].x.x.y,a[y].x.y,a[y].y.x,a[y].y.y);
               // }
            }
            y++;
        }
    }
    for(int i = 0;i<v.size();i++){
        a[l+i]=v[i];
    }
    for(auto it:re)reset(it);
}
void solve(int T){
    int n;
    scanf("%d",&n);
    int aa[100005];
    for(int i = 0;i<n;i++){
        scanf("%d",&aa[i]);
    }
    for(int i = 0;i<4;i++){
        vector<pair<pair<pii,int>,pii> > v;
        int x=0,y=0,z=0;
        
        for(int j = 0;j<n;j++){
            v.pb(mp(mp(mp(x-1,y-1),z-1),mp(1,-j+1)));
            if(aa[j]==0)x--,y--,z--;
            else if(aa[j]==1)x++;
            else if(aa[j]==2)y++;
            else z++;
            v.pb(mp(mp(mp(x,y),z),mp(0,-j)));
        }
        sort(v.begin(),v.end());
        for(auto it:v){
        //    printf("%d %d %d %d %d\n",it.x.x.x,it.x.x.y,it.x.y,it.y.x,it.y.y);
        }
      //  printf("\n");
        a=v;
        ans=0;
        for(int i = 0;i<200005;i++)S[i]=1e9;
        cdq(0,v.size()-1);
        printf("%d ",ans);
        for(int j =0;j<n;j++){
            aa[j]=(aa[j]+3)%4;
        }
    }
    printf("\n");
} 

int main(){
    int t=1;
     //scanf("%d",&t);
    for(int i = 1;i<=t;i++){
     //   cerr<<i<<endl;
        solve(i);
    }
}
/*
1227076727
1919786269
1261786217
1924134973
1051246577

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4812kb

input:

7
1 2 2 0 3 0 3

output:

4 1 5 3 

result:

ok single line: '4 1 5 3 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 4812kb

input:

12
2 0 1 0 2 1 1 0 2 3 3 3

output:

4 9 1 9 

result:

ok single line: '4 9 1 9 '

Test #3:

score: 0
Accepted
time: 0ms
memory: 4784kb

input:

2
0 2

output:

1 0 1 0 

result:

ok single line: '1 0 1 0 '

Test #4:

score: 0
Accepted
time: 1ms
memory: 4864kb

input:

12
3 0 2 2 1 0 2 1 3 3 2 3

output:

1 5 11 8 

result:

ok single line: '1 5 11 8 '

Test #5:

score: 0
Accepted
time: 1ms
memory: 4772kb

input:

1
1

output:

0 1 0 0 

result:

ok single line: '0 1 0 0 '

Test #6:

score: -100
Wrong Answer
time: 15ms
memory: 5324kb

input:

4207
3 1 0 3 2 0 3 1 1 1 1 3 0 1 1 0 2 2 3 0 1 1 0 1 0 2 0 1 0 0 3 3 1 0 1 3 3 0 2 0 2 0 1 0 2 3 2 3 0 0 0 0 1 2 1 2 0 2 2 0 3 3 2 2 0 2 2 0 3 0 1 3 1 1 0 2 3 0 1 2 1 2 0 0 1 1 0 3 3 2 0 2 1 3 0 1 0 3 0 0 0 2 2 2 0 1 1 0 3 1 1 3 3 2 2 1 3 3 1 3 2 0 2 3 2 2 1 0 2 3 0 1 0 0 1 1 1 3 3 1 3 3 3 0 0 0 3 2...

output:

2330 2304 4207 1360 

result:

wrong answer 1st lines differ - expected: '2330 1520 4207 1359', found: '2330 2304 4207 1360 '