이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <iostream>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
vector<int> val, par;
int32_t main(){
int n, q, a, b;
cin>>n>>q;
stack<pii> st;
val.resize(n+1, LLONG_MAX/2);
par.resize(n+1, 0);
for (int i=1; i<=n; ++i){
cin>>a>>val[i];
while (!st.empty()&&st.top().first<a)par[st.top().second]=i, st.pop();
st.push(mp(a, i));
}
while (q--){
cin>>a>>b;
while (val[a]<b){
b-=val[a];
a=par[a];
}
cout<<a<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |