이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <stack>
#define nmax 100000
using namespace std;
struct fountain{
int l, d;
} v[nmax + 5];
int ans[nmax+5], n, q;
void build(){
stack<int> s;
for(int i=1; i<=n; i++){
if(s.size() == 0)
s.push(i);
else{
while(!s.empty() && v[i].l > v[s.top()].l){
ans[s.top()] = i;
s.pop();
}
s.push(i);
}
}
while(!s.empty()){
ans[s.top()] = -1;
s.pop();
}
}
int main() {
cin>>n>>q;
for(int i=1; i<=n; i++){
cin>>v[i].l>>v[i].d;
}
build();
for(int t=0; t<q; t++){
int l, i, ok = true;
cin>>i>>l;
while(true){
l -= v[i].d;
if(l <= 0)
break;
if(i == -1){
ok = false;
break;
}
i = ans[i];
}
cout<<max(i, ok)<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |