Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #### Zeinab
- #include<bits/stdc++.h>
- using namespace std;
- #define nl "\n"
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define RV return void
- #define sz(x) int(x.size())
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define cin(v) for(auto&x:v) cin >> x;
- #define cout(v) for(auto&x:v) cout << x << " ";
- void solve(){
- int n ; cin >> n;
- vector < int > v(n);
- cin(v);
- map < int , int > mp;
- mp[0] = 0;
- int Xor =0;
- vector < pair < int , int > > pref(n+1);
- for(int i =0 ; i < n ; i++){
- Xor ^= v[i];
- if(mp.find(Xor) != mp.end()){
- pref[mp[Xor]].fi ++; // open interval
- pref[i].se ++; // close interval
- }
- mp[Xor] = i+1;
- }
- for(int i =1 ; i < n ; i++){
- pref[i].fi += pref[i-1].fi;
- pref[i].se += pref[i-1].se;
- }
- int q , l , r; cin >> q;
- while(q--){
- cin >> l >> r;
- l-- , r--;
- int val = pref[r].fi , val2 = pref[r].se ;
- if(l) {
- val -= pref[l-1].fi;
- val2 -= pref[l-1].se;
- }
- cout << ( val > 0 and val2 > 0 ? "YES" : "NO") << nl;
- }
- }
- int main(){
- ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
- int t=1;
- // cin >> t ;
- for(int i=1 ; i <= t ; i++){
- // cout << "Case #"<< i <<": ";
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement