제출 #704528

#제출 시각아이디문제언어결과실행 시간메모리
704528thrasherr_1Fountain (eJOI20_fountain)C++17
30 / 100
1570 ms5864 KiB
#include <bits/stdc++.h> using namespace std ; #define ff first #define ss second #define ll long long #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define ones(x) __builtin_popcount(x) #define remove(v) v.erase(unique(all(v)), v.end()) #define rep(i, a, b) for(int i = a; i <= b; i++) #define per(i, a, b) for(int i = a; i >= b; i--) #ifdef local #include "C:\debug.h" #else #define dbg(x...) 42 #endif #define int ll const int N = 1e5 + 2 ; int n , q , d[N] , c[N] , pr[N] ; int up(int v , int cp) { if(v > n) return 0 ; cp -= c[v] ; if(cp <= 0) return v ; return up(pr[v] , cp) ; } void solve(){ cin >> n >> q ; rep(i , 1 , n) { cin >> d[i] >> c[i] ; } stack<pair<int,int>> s ; s.push({LLONG_MAX , n + 1}) ; per(i , n , 1){ while(sz(s) && s.top().first <= d[i]) s.pop() ; pr[i] = s.top().second ; s.push({d[i] , i}) ; } rep(i , 1 , q) { int f , l ; cin >> f >> l ; int last = up(f , l) ; if(last > n) last = 0 ; cout << last << "\n" ; } } signed main () { ios::sync_with_stdio(false) ; cin.tie(0) ; int test = 1 ; // cin >> test ; for(int i = 1 ; i <= test ; i++) { solve() ; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...