제출 #1124291

#제출 시각아이디문제언어결과실행 시간메모리
1124291MansurtFountain (eJOI20_fountain)C++20
0 / 100
46 ms3140 KiB
#include <bits/stdc++.h> #define ll long long const ll N = 2*1e5+5; const ll mod = 1e9 + 7; using namespace std; ll d[N], c[N], pref[N]; ll mul(ll a, ll b) { return (a % mod * b % mod) % mod; } ll bpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } ll n,q,r,v; void sub() { while(q--) { cin >> r >> v; ll prev = -12; bool fnd = false; for (int i = r; i <= n; i++) { if (d[i] <= prev) continue; v -= c[i]; if (v <= 0) { fnd = true; cout << i << '\n'; break; } prev = d[i]; } if (!fnd) { cout << 0 << '\n'; } } } void sub2() { while(q--) { cin >> r >> v; ll l = r-1, r = n+1; while(r - l > 1) { ll mid = (l+r)/2; if (pref[mid] - pref[l-1] >= v) r = mid; else l = mid; } cout << (r == n + 1 ? 0 : r) << '\n'; } } int main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> q; bool flag = false; for (int i = 1; i <= n; i++) { cin >> d[i] >> c[i]; pref[i] = pref[i-1] + c[i]; if (d[i] <= d[i-1]) flag = true; } if (flag) sub(); else sub2(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...