Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb(x) push_back(x)
- #define all(x) x.begin(),x.end()
- using namespace std;
- typedef long long ll;
- typedef pair <ll,ll> pll;
- int n;
- int str1[212345];
- int str0[212345];
- int stc1[212345];
- int stc0[212345];
- void adj1(int pos, int val, int st[212345]){
- val%=2;
- pos+=n;
- st[pos] = val;
- for(pos = pos>>1; pos>0; pos = pos>>1){
- st[pos] = st[pos<<1] & st[(pos<<1)+1];
- }
- }
- void adj0(int pos, int val, int st[212345]){
- val = (val+1)%2;
- pos+=n;
- st[pos] = val;
- for(pos = pos>>1; pos>0; pos = pos>>1){
- st[pos] = st[pos<<1] & st[(pos<<1)+1];
- }
- }
- bool resp(int com, int fim, int st[212345]){
- com+=n;
- fim+=n;
- bool ans = 1;
- while(com<=fim){
- // cout << com << " " << fim << endl;
- if((com%2)){ans = ans & st[com]; com++;}
- if(!(fim%2)){ans = ans & st[fim]; fim--;}
- com = com >> 1;
- fim = fim >> 1;
- }
- return ans;
- }
- int main(){
- int q;
- cin >> n >> q;;
- for(int i=0; i<n; i++){
- int a; scanf("%d",&a);
- adj1(i,a,str1);
- adj0(i,a,str0);
- }
- for(int i=0; i<n; i++){
- int a; scanf("%d",&a);
- adj1(i,a,stc1);
- adj0(i,a,stc0);
- }
- while(q--){
- int a,b,c,d;
- scanf("%d %d %d %d",&a,&b,&c,&d);
- a--; b--; c--; d--;
- if(a > c)swap(a,c);
- if(b > d)swap(b,d);
- bool ans = 1;
- if(str1[a+n]){
- ans = ans & resp(a,c,str1);
- ans = ans & resp(b,d,stc1);
- }else{
- ans = ans & resp(a,c,str0);
- ans = ans & resp(b,d,stc0);
- }
- if(ans){
- printf("YES\n");
- }else{
- printf("NO\n");
- }
- }
- /*for(int i=0; i<2*n; i++){
- cout << str1[i] << " ";
- }
- cout << endl;
- for(int i=0; i<2*n; i++){
- cout << str0[i] << " ";
- }
- cout << endl;
- cout << resp(0,3,str1) << endl;
- cout << resp(0,3,str0) << endl;
- cout << resp(2,3,str0) << endl;
- cout << resp(4,6,str1) << endl;
- cout << resp(8,12,str0) << endl;
- cout << resp(9,12,str0) << endl;
- cout << resp(8,12,str1) << endl;
- cout << resp(9,12,str1) << endl;
- cout << resp(13,13,str1) << endl;
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement