#include <bits/stdc++.h>
#define ll long long
#define fast1 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define int long long
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,avx")
#pragma GCC optimize("unroll-loops")
int n,m,k,q;
int d[100005];
int c[100005];
int pre[100005];
void solve()
{
cin>>n>>q;
for(int i=1;i<=n;i++)
cin>>d[i]>>c[i];
if(n<=1000)
{
while(q--)
{
int a,b;
cin>>a>>b;
for(int i=a;i<=n;i++)
{
b-=c[i];
if(b<=0)
{
cout<<i<<endl;
break;
}
int son=i;
while(d[i+1]<=d[son])
i++;
}
if(b>0)
cout<<0<<endl;
}
}
else
{
pre[1]=c[1];
for(int i=2;i<=n;i++)
pre[i]=pre[i-1]+c[i];
while(q--)
{
int a,b;
cin>>a>>b;
int cvp=lower_bound(pre+a,pre+1+n,b+pre[a-1])-pre;
if(cvp<=n)
cout<<cvp<<endl;
else cout<<cvp<<endl;
}
}
}
signed main()
{
fast1
//freopen ("lca.gir","r",stdin);
//freopen ("lca.cik","w",stdout);
int t=1;
//cin>>t;
while(t--)
{
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
6088 KB |
Output is correct |
2 |
Correct |
73 ms |
6336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
66 ms |
6088 KB |
Output is correct |
9 |
Correct |
73 ms |
6336 KB |
Output is correct |
10 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |