Advertisement
a53

lumini

a53
May 13th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream f("lumini.in");
  4. ofstream g("lumini.out");
  5. #define L 1010
  6. struct fulger
  7. {
  8. long long poz;
  9. int fr;
  10. } lin[L], col[L], diag[2*L];
  11. int nLin, nCol, nDiag, n;
  12.  
  13. int cauta(fulger a[], int n, long long v)
  14. {
  15. int s=1, d=n, m;
  16. while(s<=d)
  17. {
  18. m=(s+d)/2;
  19. if(a[m].poz==v)return m;
  20. else if(v<a[m].poz)d=m-1;
  21. else s=m+1;
  22. }
  23. return s;
  24. }
  25.  
  26. void insereaza(fulger a[], int &n, long long v)
  27. {
  28. if(n==0)
  29. {
  30. a[++n].poz=v;
  31. a[n].fr=1;
  32. return;
  33. }
  34. int pozitie=cauta(a,n,v), i;
  35. if(pozitie<=n && a[pozitie].poz==v)a[pozitie].fr++;
  36. else
  37. {
  38. i=n;
  39. while(i>0 && a[i].poz>v)a[i+1]=a[i--];
  40. a[i+1].poz=v;
  41. a[i+1].fr=1;
  42. n++;
  43. }
  44. }
  45.  
  46. int main()
  47. {
  48. f>>n;
  49. int x, y, z, i, Q;
  50. f>>Q;
  51. for(i=1; i<=Q; i++)
  52. {
  53. f>>x;
  54. if(x==1)f>>y, insereaza(lin, nLin, y);
  55. else if(x==2)f>>y, insereaza(col, nCol, y);
  56. else f>>y>>z, insereaza(diag, nDiag, 1LL*y+1LL*z-1);
  57. }
  58. lin[nLin+1].poz=col[nCol+1].poz=diag[nDiag+1].poz=n+1;
  59. for(i=2; i<=nLin+1; i++)lin[i].fr+=lin[i-1].fr;
  60. for(i=1; i<=nCol+1; i++)col[i].fr+=col[i-1].fr;
  61. for(i=1; i<=nDiag+1; i++)diag[i].fr+=diag[i-1].fr;
  62. f>>Q;
  63. for(i=1; i<=Q; i++)
  64. {
  65. f>>x>>y;
  66. int far=1-(x%2+y%2)%2;
  67. int p=cauta(lin,nLin, x);
  68. if(lin[p].poz>x)p--;
  69. if(lin[p].fr%2)far=!far;
  70. p=cauta(col,nCol, y);
  71. if(col[p].poz>y)p--;
  72. if(col[p].fr%2)far=!far;
  73. p=cauta(diag,nDiag, 1LL*x+1LL*y-1);
  74. if(diag[p].poz>1LL*x+1LL*y-1)p--;
  75. if(diag[p].fr%2)far=!far;
  76. g<<far<<' ';
  77. }
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement