Guest User

Problem C

a guest
Oct 28th, 2019
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int int64_t
  5.  
  6.  
  7. signed main() {
  8.   ios_base::sync_with_stdio(false);
  9.   cin.tie(NULL);
  10. int n,q;
  11. cin>>n>>q;
  12. int r[n],c[n];
  13. for(int i=0;i<n;i++)
  14. {
  15.      cin>>r[i];
  16.      r[i]=r[i]%2;
  17. }
  18. for(int i=0;i<n;i++)
  19. {
  20.      cin>>c[i];
  21.      c[i]=c[i]%2;
  22. }
  23. vector<int> row(n),column(n);
  24. int k=0;
  25. row[0]=0;
  26. for(int i=1;i<n;i++)
  27. {
  28.    if(r[i]==r[i-1])
  29.    {
  30.         row[i]=k;
  31.        
  32.    }
  33.    else
  34.    {
  35.    k++;
  36.    row[i]=k;
  37.    }
  38.  
  39. }
  40. k=0;
  41. for(int i=1;i<n;i++)
  42. {
  43.         if(c[i-1]==c[i])
  44.         {
  45.              column[i]=k;
  46.              
  47.              
  48.         }
  49.         else
  50.         {
  51.              k++;
  52.              column[i]=k;
  53.         }
  54. }
  55.  
  56. while(q--)
  57. {
  58.      int xi,yi,xf,yf;
  59.      cin>>xi>>yi>>xf>>yf;
  60.      xi--;
  61.      yi--;
  62.      xf--;
  63.      yf--;
  64.      if((row[xi]==row[xf])&&(column[yi]==column[yf]))
  65.      cout<<"YES"<<endl;
  66.      else
  67.      cout<<"NO"<<endl;
  68.      
  69.  
  70. }
  71.  
  72.     return 0;
  73. }
Add Comment
Please, Sign In to add comment