Submission #1964416


Source Code Expand

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<set>
using namespace std;
char A[310000];
char B[310000];
int p[310000];
int q[310000];
int bit[310000];
set<int>zero;
set<int>two;
set<int>bb;
int sum(int a,int b){
    if(a)return sum(0,b)-sum(0,a-1);
    int ret=0;
    for(;b>=0;b=(b&(b+1))-1)ret+=bit[b];
    return ret;
}
void add(int a,int b){
    for(;a<310000;a|=a+1)bit[a]+=b;
}
char in[2];
int main(){
    int a;
    scanf("%d",&a);
    scanf("%s%s",A,B);
    int as=strlen(A);
    int bs=strlen(B);
    two.insert(-1);
    zero.insert(-1);
    for(int i=0;i<as;i++){
        p[i]=A[as-1-i]-'0';
    }
    for(int i=0;i<bs;i++){
        q[i]=B[bs-1-i]-'0';
    }
    int sz=max(as,bs)+1;
    for(int i=0;i<sz;i++){
        if(p[i]+q[i]==2)two.insert(i);
        if(p[i]+q[i]==0)zero.insert(i);
        if(q[i])bb.insert(i);
        if(p[i])add(i,1);
    }
    for(int i=0;i<a;i++){
        scanf("%s",in);
        if(in[0]=='Q'){
            int at=*(bb.rbegin());
            int val=sum(at,sz);
            int ret=val+at;
            if(p[at]==0){
                int nt=*(--(two.lower_bound(at)));
                int nz=*(--(zero.lower_bound(at)));
        //      printf("%d %d\n",nt,nz);
                if(nt>nz){
                    ret++;
                }
            }
            printf("%d\n",ret);
        }else if(in[0]=='A'){
            int t;scanf("%d",&t);
            if(p[t]==0){
                if(q[t]+p[t]==0)zero.erase(t);
                p[t]=1;
                if(q[t]+p[t]==2)two.insert(t);
                add(t,1);
            }else{
                if(q[t]+p[t]==2)two.erase(t);
                p[t]=0;
                if(q[t]+p[t]==0)zero.insert(t);
                add(t,-1);
            }
        }else{
            int t;scanf("%d",&t);
            if(q[t]==0){
                if(q[t]+p[t]==0)zero.erase(t);
                q[t]=1;
                if(q[t]+p[t]==2)two.insert(t);
                bb.insert(t);
            }else{
                if(q[t]+p[t]==2)two.erase(t);
                q[t]=0;
                if(q[t]+p[t]==0)zero.insert(t);
                bb.erase(t);
            }
        }
    }
}

Submission Info

Submission Time
Task I - A + B
User tozangezan
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2256 Byte
Status AC
Exec Time 241 ms
Memory 19328 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:26:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&a);
                   ^
./Main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s%s",A,B);
                      ^
./Main.cpp:46:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",in);
                       ^
./Main.cpp:61:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             int t;scanf("%d",&t);
                                 ^
./Main.cpp:74:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
             int t;scanf("%d",&t);
                ...

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 66
Set Name Test Cases
All 00-gray1-1.txt, 00-gray1-2.txt, 00-gray1-3.txt, 00-gray1-4.txt, 00-gray1-5.txt, 00-gray1-6.txt, 00-gray1-7.txt, 00-gray2-1.txt, 00-gray2-2.txt, 00-gray2-3.txt, 00-gray2-4.txt, 00-gray2-5.txt, 00-gray2-6.txt, 00-gray2-7.txt, 00-gray3-1.txt, 00-gray3-2.txt, 00-gray3-3.txt, 00-gray3-4.txt, 00-gray3-5.txt, 00-gray3-6.txt, 00-gray3-7.txt, 00-gray4-1.txt, 00-gray4-2.txt, 00-gray4-3.txt, 00-gray4-4.txt, 00-gray4-5.txt, 00-gray4-6.txt, 00-gray4-7.txt, 00-gray5-1.txt, 00-gray5-2.txt, 00-gray5-3.txt, 00-gray5-4.txt, 00-gray5-5.txt, 00-gray5-6.txt, 00-gray5-7.txt, 00-gray6-1.txt, 00-gray6-2.txt, 00-gray6-3.txt, 00-gray6-4.txt, 00-gray6-5.txt, 00-gray6-6.txt, 00-gray6-7.txt, 00-gray7-1.txt, 00-gray7-2.txt, 00-gray7-3.txt, 00-gray7-4.txt, 00-gray7-5.txt, 00-gray7-6.txt, 00-gray7-7.txt, 00-sample1.txt, 50-random00.txt, 50-random01.txt, 50-random02.txt, 50-random03.txt, 50-random04.txt, 50-random05.txt, 50-random06.txt, 50-random07.txt, 50-random08.txt, 50-random09.txt, 50-random10.txt, 50-random11.txt, 50-random12.txt, vsparallel00.txt, vsparallel01.txt, vsparallel02.txt
Case Name Status Exec Time Memory
00-gray1-1.txt AC 2 ms 2304 KB
00-gray1-2.txt AC 2 ms 2304 KB
00-gray1-3.txt AC 2 ms 2304 KB
00-gray1-4.txt AC 2 ms 2304 KB
00-gray1-5.txt AC 2 ms 2304 KB
00-gray1-6.txt AC 2 ms 2304 KB
00-gray1-7.txt AC 2 ms 2304 KB
00-gray2-1.txt AC 2 ms 2304 KB
00-gray2-2.txt AC 2 ms 2304 KB
00-gray2-3.txt AC 2 ms 2304 KB
00-gray2-4.txt AC 2 ms 2304 KB
00-gray2-5.txt AC 2 ms 2304 KB
00-gray2-6.txt AC 2 ms 2304 KB
00-gray2-7.txt AC 2 ms 2304 KB
00-gray3-1.txt AC 2 ms 2304 KB
00-gray3-2.txt AC 2 ms 2304 KB
00-gray3-3.txt AC 2 ms 2304 KB
00-gray3-4.txt AC 2 ms 2304 KB
00-gray3-5.txt AC 2 ms 2304 KB
00-gray3-6.txt AC 2 ms 2304 KB
00-gray3-7.txt AC 2 ms 2304 KB
00-gray4-1.txt AC 2 ms 2304 KB
00-gray4-2.txt AC 2 ms 2304 KB
00-gray4-3.txt AC 2 ms 2304 KB
00-gray4-4.txt AC 2 ms 2304 KB
00-gray4-5.txt AC 2 ms 2304 KB
00-gray4-6.txt AC 2 ms 2304 KB
00-gray4-7.txt AC 3 ms 2304 KB
00-gray5-1.txt AC 2 ms 2304 KB
00-gray5-2.txt AC 2 ms 2304 KB
00-gray5-3.txt AC 2 ms 2304 KB
00-gray5-4.txt AC 2 ms 2304 KB
00-gray5-5.txt AC 2 ms 2304 KB
00-gray5-6.txt AC 3 ms 2304 KB
00-gray5-7.txt AC 3 ms 2304 KB
00-gray6-1.txt AC 2 ms 2304 KB
00-gray6-2.txt AC 2 ms 2304 KB
00-gray6-3.txt AC 2 ms 2304 KB
00-gray6-4.txt AC 2 ms 2304 KB
00-gray6-5.txt AC 3 ms 2304 KB
00-gray6-6.txt AC 3 ms 2304 KB
00-gray6-7.txt AC 5 ms 2304 KB
00-gray7-1.txt AC 2 ms 2304 KB
00-gray7-2.txt AC 2 ms 2304 KB
00-gray7-3.txt AC 2 ms 2304 KB
00-gray7-4.txt AC 2 ms 2304 KB
00-gray7-5.txt AC 3 ms 2304 KB
00-gray7-6.txt AC 5 ms 2304 KB
00-gray7-7.txt AC 8 ms 2304 KB
00-sample1.txt AC 2 ms 2304 KB
50-random00.txt AC 79 ms 2944 KB
50-random01.txt AC 80 ms 2944 KB
50-random02.txt AC 80 ms 2944 KB
50-random03.txt AC 82 ms 2944 KB
50-random04.txt AC 85 ms 2944 KB
50-random05.txt AC 225 ms 17792 KB
50-random06.txt AC 209 ms 17024 KB
50-random07.txt AC 241 ms 18560 KB
50-random08.txt AC 214 ms 16896 KB
50-random09.txt AC 216 ms 19328 KB
50-random10.txt AC 66 ms 5120 KB
50-random11.txt AC 66 ms 4992 KB
50-random12.txt AC 67 ms 4992 KB
vsparallel00.txt AC 182 ms 18176 KB
vsparallel01.txt AC 178 ms 18176 KB
vsparallel02.txt AC 175 ms 18176 KB