Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.1 kB
2
Indexable
Never
#pragma GCC optimize("O2,no-stack-protector,unroll-loops")
#define ll long long
#define pb push_back
#define ipar(arr, n) vector<ll> arr(n); for(int i=0;i<n;i++) cin>>arr[i];
#include <cmath>
#include <bits/stdc++.h>
#define pii pair<int, int>;
#define pll pair<ll, ll>;
using namespace std;

ll maxfreq(ll l,ll r,vector<ll>c){
    ll f=1;
    unordered_map<ll,ll>feq;
    for(ll i=l;i<=r;i++){
        feq[c[i]]++;
    }
    for(auto it:feq){
        f=max(f,it.second);
    }
    return f;
}

void solve(){
    ll n,q; cin>>n>>q;
    ipar(c,n);
    vector<ll>az(n+1,0);
    vector<ll>pre(n+1,0);
    for(ll i=0;i<n;i++){
        az[i+1]=az[i]+(c[i]==1); //1 indexing
        pre[i+1]=pre[i]+c[i]-1;
    }

    while(q--){
        ll l,r; cin>>l>>r;
        ll zc=az[r]-az[l-1];
        ll s=pre[r]-pre[l-1];

        if(s>=zc && l!=r){
            cout<<"yes"<<"\n";
        }else{
            cout<<"no"<<"\n";
        }
    }
}


signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
	cin>>t;
	while(t--) solve();
}
Leave a Comment