YL 模拟赛总结 14
Problem
省流:三道题写了 tj
T1
见 tj。
T2
见 tj。
T3
见 tj。
T4
二分求出左右端点即可。
#include<bits/stdc++.h>
using namespace std;
int n,q;
int p[200031];
int main(){
    //freopen("haybales.in","r",stdin);
    //freopen("haybales.out","w",stdout);
    cin>>n>>q;
    for(int i=1;i<=n;i++) cin>>p[i];
    sort(p+1,p+n+1);
    while(q--){
        int a,b; cin>>a>>b;
        int l=lower_bound(p+1,p+n+1,a)-p,r=upper_bound(p+1,p+n+1,b)-p-1;
        cout<<r-l+1<<'\n';
    }
    return 0;
}
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号