Submission #3363652
Source Code Expand
#include <bits/stdc++.h>
#define INF 1<<19
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
class segtree{
public:
static const int N=1<<19;
int dp[1<<20];
int cnt[1<<20];
segtree(){
for(int i=0;i<N*2;i++){
dp[i]=INF;
cnt[i]=0;
}
}
void update(int k,int v){
k+=N-1;
dp[k]=v;
if(v==INF){
cnt[k]=0;
}else{
cnt[k]=1;
}
while(k>0){
k=(k-1)/2;
dp[k]=min(dp[k*2+1],dp[k*2+2]);
cnt[k]=cnt[k*2+1]+cnt[k*2+2];
}
}
int query(int a,int b,int k=0,int l=0,int r=N){
if(b<=l || r<=a)return INF;
if(a<=l && r<=b)return dp[k];
int mid=(l+r)/2;
int vl=query(a,b,k*2+1,l,mid);
int vr=query(a,b,k*2+2,mid,r);
return min(vl,vr);
}
int query2(int a,int b,int k=0,int l=0,int r=N){
if(b<=l || r<=a)return 0;
if(a<=l && r<=b)return cnt[k];
int mid=(l+r)/2;
int vl=query2(a,b,k*2+1,l,mid);
int vr=query2(a,b,k*2+2,mid,r);
return vl+vr;
}
};
segtree seg[4];
int bit[300005];
int main(void){
int q;
string a,b;
cin >> q >> a >> b;
int n=a.size();
for(int i=0;i<n;i++){
if(a[i]=='1'){
bit[i]^=1;
}
if(b[i]=='1'){
bit[i]^=2;
}
}
for(int i=0;i<n;i++){
seg[bit[i]].update(i,i);
}
for(int i=0;i<q;i++){
char c;
scanf(" %c",&c);
if(c=='Q'){
int pos[4];
for(int j=0;j<4;j++){
pos[j]=seg[j].dp[0];
}
if(min(pos[1],pos[2])>pos[3]){
printf("%d\n",n-pos[3]);
}else if(pos[1]<pos[2]){
if(seg[0].query(pos[1],n)>seg[3].query(pos[1],n)){
printf("%d\n",n-pos[1]);
}else if(seg[2].query(pos[1],n)>seg[3].query(pos[1],n)){
int v=seg[3].query(pos[1],n);
printf("%d\n",n-v+seg[1].query2(0,v));
}else{
int v=seg[2].query(pos[1],n);
if(seg[0].query(v,n)==INF){
printf("%d\n",n-v+seg[1].query2(0,v));
}else{
printf("%d\n",n-v+seg[1].query2(0,v)-1);
}
}
}else{
if(seg[0].query(pos[2],n)==INF || seg[0].query(pos[2],n)>seg[3].query(pos[2],n)){
printf("%d\n",n-pos[2]);
}else{
printf("%d\n",n-pos[2]-1);
}
}
}else{
int a;
scanf("%d",&a);
a=n-a-1;
seg[bit[a]].update(a,INF);
if(c=='A'){
bit[a]^=1;
}else{
bit[a]^=2;
}
seg[bit[a]].update(a,a);
}
}
return 0;
}
Submission Info
Submission Time
2018-10-07 21:06:49+0900
Task
I - A + B
User
ryoissy
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
2302 Byte
Status
RE
Exec Time
209 ms
Memory
35848 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:73:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c",&c);
^
./Main.cpp:104:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a);
^
Judge Result
Set Name
All
Score / Max Score
0 / 100
Status
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
WA
13 ms
33024 KB
00-gray1-2.txt
WA
13 ms
33024 KB
00-gray1-3.txt
WA
13 ms
33024 KB
00-gray1-4.txt
WA
13 ms
33024 KB
00-gray1-5.txt
WA
13 ms
33024 KB
00-gray1-6.txt
WA
13 ms
33024 KB
00-gray1-7.txt
WA
14 ms
33024 KB
00-gray2-1.txt
WA
13 ms
33024 KB
00-gray2-2.txt
WA
13 ms
33024 KB
00-gray2-3.txt
WA
13 ms
33024 KB
00-gray2-4.txt
WA
13 ms
33024 KB
00-gray2-5.txt
WA
13 ms
33024 KB
00-gray2-6.txt
WA
13 ms
33024 KB
00-gray2-7.txt
WA
14 ms
33024 KB
00-gray3-1.txt
WA
13 ms
33024 KB
00-gray3-2.txt
WA
13 ms
33024 KB
00-gray3-3.txt
WA
13 ms
33024 KB
00-gray3-4.txt
WA
13 ms
33024 KB
00-gray3-5.txt
WA
13 ms
33024 KB
00-gray3-6.txt
WA
14 ms
33024 KB
00-gray3-7.txt
WA
14 ms
33024 KB
00-gray4-1.txt
WA
13 ms
33024 KB
00-gray4-2.txt
WA
13 ms
33024 KB
00-gray4-3.txt
WA
13 ms
33024 KB
00-gray4-4.txt
WA
13 ms
33024 KB
00-gray4-5.txt
WA
14 ms
33024 KB
00-gray4-6.txt
WA
14 ms
33024 KB
00-gray4-7.txt
WA
15 ms
33024 KB
00-gray5-1.txt
WA
13 ms
33024 KB
00-gray5-2.txt
WA
13 ms
33024 KB
00-gray5-3.txt
WA
13 ms
33024 KB
00-gray5-4.txt
WA
14 ms
33024 KB
00-gray5-5.txt
WA
14 ms
33024 KB
00-gray5-6.txt
WA
15 ms
33024 KB
00-gray5-7.txt
WA
17 ms
33024 KB
00-gray6-1.txt
WA
13 ms
33024 KB
00-gray6-2.txt
WA
13 ms
33024 KB
00-gray6-3.txt
WA
14 ms
33024 KB
00-gray6-4.txt
WA
14 ms
33024 KB
00-gray6-5.txt
WA
15 ms
33024 KB
00-gray6-6.txt
WA
16 ms
33024 KB
00-gray6-7.txt
WA
20 ms
33024 KB
00-gray7-1.txt
WA
13 ms
33024 KB
00-gray7-2.txt
WA
14 ms
33024 KB
00-gray7-3.txt
WA
14 ms
33024 KB
00-gray7-4.txt
WA
15 ms
33024 KB
00-gray7-5.txt
WA
16 ms
33024 KB
00-gray7-6.txt
WA
19 ms
33024 KB
00-gray7-7.txt
WA
27 ms
33024 KB
00-sample1.txt
AC
13 ms
33024 KB
50-random00.txt
WA
144 ms
33664 KB
50-random01.txt
WA
127 ms
33664 KB
50-random02.txt
RE
110 ms
33024 KB
50-random03.txt
WA
126 ms
33664 KB
50-random04.txt
WA
128 ms
33664 KB
50-random05.txt
RE
161 ms
34696 KB
50-random06.txt
RE
158 ms
34568 KB
50-random07.txt
RE
167 ms
34824 KB
50-random08.txt
RE
158 ms
34568 KB
50-random09.txt
WA
196 ms
35848 KB
50-random10.txt
WA
72 ms
33664 KB
50-random11.txt
WA
76 ms
33664 KB
50-random12.txt
WA
73 ms
33664 KB
vsparallel00.txt
WA
208 ms
34568 KB
vsparallel01.txt
WA
208 ms
34568 KB
vsparallel02.txt
WA
209 ms
34568 KB