Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb(x) push_back(x)
  3. #define all(x) x.begin(),x.end()
  4. using namespace std;
  5. typedef long long ll;
  6. typedef pair <ll,ll> pll;
  7. int n;
  8.  
  9. int str1[212345];
  10. int str0[212345];
  11. int stc1[212345];
  12. int stc0[212345];
  13.  
  14. void adj1(int pos, int val, int st[212345]){
  15. val%=2;
  16. pos+=n;
  17. st[pos] = val;
  18. for(pos = pos>>1; pos>0; pos = pos>>1){
  19. st[pos] = st[pos<<1] & st[(pos<<1)+1];
  20. }
  21. }
  22.  
  23. void adj0(int pos, int val, int st[212345]){
  24. val = (val+1)%2;
  25. pos+=n;
  26. st[pos] = val;
  27. for(pos = pos>>1; pos>0; pos = pos>>1){
  28. st[pos] = st[pos<<1] & st[(pos<<1)+1];
  29. }
  30. }
  31.  
  32. bool resp(int com, int fim, int st[212345]){
  33. com+=n;
  34. fim+=n;
  35. bool ans = 1;
  36. while(com<=fim){
  37. // cout << com << " " << fim << endl;
  38. if((com%2)){ans = ans & st[com]; com++;}
  39. if(!(fim%2)){ans = ans & st[fim]; fim--;}
  40. com = com >> 1;
  41. fim = fim >> 1;
  42. }
  43. return ans;
  44. }
  45.  
  46. int main(){
  47. int q;
  48. cin >> n >> q;;
  49. for(int i=0; i<n; i++){
  50. int a; scanf("%d",&a);
  51. adj1(i,a,str1);
  52. adj0(i,a,str0);
  53. }
  54. for(int i=0; i<n; i++){
  55. int a; scanf("%d",&a);
  56. adj1(i,a,stc1);
  57. adj0(i,a,stc0);
  58. }
  59. while(q--){
  60. int a,b,c,d;
  61. scanf("%d %d %d %d",&a,&b,&c,&d);
  62. a--; b--; c--; d--;
  63. if(a > c)swap(a,c);
  64. if(b > d)swap(b,d);
  65. bool ans = 1;
  66. if(str1[a+n]){
  67. ans = ans & resp(a,c,str1);
  68. ans = ans & resp(b,d,stc1);
  69. }else{
  70. ans = ans & resp(a,c,str0);
  71. ans = ans & resp(b,d,stc0);
  72. }
  73. if(ans){
  74. printf("YES\n");
  75. }else{
  76. printf("NO\n");
  77. }
  78. }
  79. /*for(int i=0; i<2*n; i++){
  80. cout << str1[i] << " ";
  81. }
  82. cout << endl;
  83. for(int i=0; i<2*n; i++){
  84. cout << str0[i] << " ";
  85. }
  86. cout << endl;
  87. cout << resp(0,3,str1) << endl;
  88. cout << resp(0,3,str0) << endl;
  89. cout << resp(2,3,str0) << endl;
  90. cout << resp(4,6,str1) << endl;
  91. cout << resp(8,12,str0) << endl;
  92. cout << resp(9,12,str0) << endl;
  93. cout << resp(8,12,str1) << endl;
  94. cout << resp(9,12,str1) << endl;
  95. cout << resp(13,13,str1) << endl;
  96. */
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement