제출 #964688

#제출 시각아이디문제언어결과실행 시간메모리
964688pccFountain (eJOI20_fountain)C++17
100 / 100
248 ms40788 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define pii pair<int,int> #define fs first #define sc second #define tlll tuple<ll,ll,ll> const int mxn = 1e5+10; int N,Q; vector<int> tree[mxn]; ll cap[mxn],dia[mxn]; vector<int> st; int par[mxn][20]; ll sum[mxn][20]; void dfs(int now){ sum[now][0] = cap[now]; for(int i = 1;i<20;i++){ par[now][i] = par[par[now][i-1]][i-1]; sum[now][i] = sum[now][i-1]+sum[par[now][i-1]][i-1]; } for(auto nxt:tree[now]){ par[nxt][0] = now; dfs(nxt); } return; } ll calc(int now,int cnt){ for(int i = 19;i>=0;i--){ if(sum[now][i]<cnt){ cnt -= sum[now][i]; now = par[now][i]; } } if(now == N+1)return 0; else return now; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>N>>Q; cap[N+1] = dia[N+1] = 1e9+10; for(int i = 1;i<=N;i++)cin>>dia[i]>>cap[i]; for(int i = 1;i<=N+1;i++){ while(!st.empty()&&dia[st.back()]<dia[i]){ tree[i].push_back(st.back()); st.pop_back(); } st.push_back(i); } par[N+1][0] = N+1; dfs(N+1); while(Q--){ int a,b; cin>>a>>b; cout<<calc(a,b)<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...