제출 #827422

#제출 시각아이디문제언어결과실행 시간메모리
827422Rayyan1108Fountain (eJOI20_fountain)C++17
0 / 100
524 ms524288 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> void print(ll Z) { cout << Z << endl; } struct threeVar { ll first, second, third; }; ll ps[100090]; ll binser(ll L, ll R, ll X, ll Y) { while (L < R) { ll mid = (L+R)/2; if(ps[mid] - Y == X) { return mid; } else if(ps[mid] - Y > X) { return binser(L, mid, X, Y); } else { return binser(mid+1, R, X, Y); } } return L; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll N, Q; cin >> N >> Q; pll arr[N+4]; vector<threeVar> V[N+2]; bool isST2 = 1; ps[0] = 0; for(int i=1; i<=N; i++) { cin >> arr[i].first >> arr[i].second; if(arr[i].first <= arr[i].second) { isST2 = 0; } ps[i] = ps[i-1] + arr[i].second; } if(!isST2) { for(int i=1; i<=N; i++) { V[i].push_back({arr[i].first, arr[i].second, i}); for(int j=1; j<i; j++) { if(arr[i].first > V[j].back().first) { if(!V[j].empty()) { V[j].push_back({arr[i].first, V[j].back().second + arr[i].second, i}); } } } } while(Q--) { ll X, Y; cin >> X >> Y; if(!V[X].empty()) { ll Z = V[X].back().second; if(Y > Z) { print(0); } else { ll ans = V[X][0].third; bool firstTime = 1; for(auto i: V[X]) { if(i.second < Y) { ans = i.third; } else if(i.second == Y) { ans = i.third; break; } else { if(firstTime) { firstTime = 0; ans = i.third; } else {break;} } } print(ans); } } } } else { while (Q--) { ll X, Y; cin >> X >> Y; if(Y > ps[N] - ps[X-1]) { print(0); continue; } ll ans = binser(1, N, Y, ps[X-1]); print(ans); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...