Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define pb push_back
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int n, q;
- cin >> n >> q;
- vector<ll int> a(n);
- vector<ll int> pre(n), one(n);
- for(int i=0; i<n; i++)
- {
- cin >> a[i];
- pre[i] = a[i];
- one[i] = (a[i] == 1);
- }
- for(int i=1; i<n; i++)
- {
- pre[i] += pre[i - 1];
- one[i] += one[i - 1];
- }
- while (q--)
- {
- ll int l, r;
- cin >> l >> r;
- l--, r--;
- if (l == r)
- {
- cout<<"NO\n";
- continue;
- }
- ll int sum = pre[r];
- ll int cnt = one[r];
- if(l > 0)
- {
- sum -= pre[l - 1];
- cnt -= one[l - 1];
- }
- sum -= 2 * cnt;
- ll int rem = r - l + 1 - cnt;
- if (sum >= rem)
- cout << "YES\n";
- else
- cout << "NO\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement