제출 #1122648

#제출 시각아이디문제언어결과실행 시간메모리
1122648dreamboyFountain (eJOI20_fountain)C++20
60 / 100
1595 ms2120 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> using namespace std; //using namespace __gnu_pbds; #define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define russian setlocale(LC_ALL,"Russian_Russia.20866"); #define file freopen("onlyone.in", "r", stdin), freopen("onlyone.out", "w", stdout); #define ll long long #define big __int128 #define ull unsigned long long #define ld long double #define pll pair<ll, ll> #define pli pair<ll, int> #define pii pair<int, int> #define all(s) s.begin(), s.end() #define pb push_back #define ins insert #define sz(x) x.size() #define F first #define S second #define lb lower_bound #define ub upper_bound #define mem(x) memset(x, 0, sizeof(x)) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 100010; const int B = 448; const ll mod = 1e9 + 7; const ll P = 263; const ld pi = acos(-1); const ll inf = (ll)1e18; const ll ntr = (ll)-1e18; ll add(ll a, ll b) { if(a + b < 0) return a + b + mod; if(a + b >= mod) return a + b - mod; return a + b; } ll sub(ll a, ll b) { return (a - b + mod) % mod; } ll mul(ll a, ll b) { return a * 1LL * b % mod; } ll binpow(ll a, ll n) { ll res = 1; while(n) { if (n & 1) res = mul(res, a); a = mul(a, a); n >>= 1; } return res; } ll inv(ll x) { return binpow(x, mod - 2); } int n, q; int d[N], c[N], p[N]; void solve() { cin >> n >> q; for(int i = 1; i <= n; i++) { cin >> d[i] >> c[i]; p[i] = p[i - 1] + c[i]; } bool sb2 = true; for(int i = 1; i < n; i++) { sb2 &= (d[i] < d[i + 1]); } while(q--) { int k, v; cin >> k >> v; if(sb2) { int l = k - 1, r = n + 1; while(r > l + 1) { int mid = (l + r) / 2; if(p[mid] - p[k - 1] >= v) r = mid; else l = mid; } cout << (r == n + 1 ? 0 : r) << '\n'; } else { int s = 0, pred = -1, ans = 0; for(int i = k; i <= n; i++) { if(d[i] > pred) { s += c[i]; pred = d[i]; } if(s >= v) { ans = i; break; } } cout << ans << '\n'; } } } signed main() { speed; //file int test = 1; //cin >> test; while(test--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...