제출 #1335060

#제출 시각아이디문제언어결과실행 시간메모리
1335060tsengangFountain (eJOI20_fountain)C++20
0 / 100
207 ms6976 KiB
#include <bits/stdc++.h>
#define ll int
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define ertunt return
using namespace std;
ll mod = 1e9+7;
vector<ll> adj[600007];
vector<ll>vis(200005);
vector<ll> f(600005), inv(600005);
ll modpow(ll a, ll b){
    ll r = 1;
    while(b){
        if(b & 1){
            r *= a;
            r %= mod;
        }
        a *= a;
        a %= mod;
        b >>= 1;
    }
    ertunt r;
}
ll nCk(ll n, ll k){
    if(k < 0 || k > n) ertunt 0;
    ertunt f[n] * inv[k] % mod * inv[n - k] % mod;
}
int main(){
	ll n,q;
	cin >> n >> q;
	vector<ll>pref(n+1,0);
	for(ll i = 1; i <= n; i++){
		ll x,y;
		cin >> x >> y;
		pref[i] = pref[i-1]+y;
	}
	while(q--){
		ll x,y;
		cin >> x >> y;
		ll t=y+pref[x-1];
		auto it=lower_bound(pref.begin()+x,pref.end(),t)-pref.begin();
		if(it>n) cout<<0<<"\n";
		else if(pref[it]==t) cout<<it<<"\n";
		else cout<<it-1<<"\n";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...