fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3. #define MIN(a,b) ((a)<=(b)?(a):(b))
  4.  
  5. int A[4][100005],Carry[2][400],N,N2;
  6.  
  7. int Read(int ind) { char ch=0; int a=0; while(ch<33) ch=getchar_unlocked(); while(ch>33) { A[ind][N-3-a++]=ch-'0'; ch=getchar_unlocked(); } A[ind][N-1]=A[ind][N-2]=0; }
  8.  
  9. int Update(int pos,int bit,int ind) { A[ind][pos]=bit; CalBlock((pos/N2)*N2,MIN(N,((pos/N2)+1)*N2),pos/N2); }
  10.  
  11. int CalBlock(int from,int to,int bno)
  12. {
  13. int i,j,c[2]={0,1};
  14. for(j=from;j<to;j++) for(i=0;i<2;i++) { A[2+i][j]=A[0][j]^A[1][j]^c[i]; c[i]=(c[i]&(A[0][j]^A[1][j]))|(A[0][j]&A[1][j]); }
  15. Carry[0][bno]=c[0]; Carry[1][bno]=c[1];
  16. }
  17.  
  18. void solve(int k)
  19. {
  20. int i,c=0; for(i=0;i<(k/N2);i++) c=Carry[c][i];
  21. printf("%d",A[2+c][k]);
  22. }
  23.  
  24. int Pprocess()
  25. {
  26. int i,j,p; N2=sqrt(N);
  27. for(i=0;((i+1)*N2)<N;i++) CalBlock(i*N2,(i+1)*N2,i);
  28. if(i*N2<N) CalBlock(i*N2,N,N2);
  29. }
  30.  
  31. int main()
  32. {
  33. int Q;
  34. scanf("%d%d",&N,&Q); N+=2;
  35. Read(0); Read(1); Pprocess();
  36. while(Q--)
  37. {
  38. char q[10]; int i,j; scanf("%s",q);
  39. if(q[0]=='s') { scanf("%d%d",&i,&j); Update(i,j,q[4]=='b'); }
  40. else { scanf("%d",&i); solve(i); }
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0s 3816KB
stdin
5 5  
00000  
11111  
set_a 0 1  
get_c 5  
get_c 1  
set_b 2 0  
get_c 5
stdout
100