Submission #1130232

#TimeUsernameProblemLanguageResultExecution timeMemory
1130232sheina906Fountain (eJOI20_fountain)C++20
0 / 100
1209 ms301372 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define f first #define s second struct str { ll ad; vector<pll> beg; stack<ll> s; str(): ad(0) {} void rem() { ad -= beg.back().f - ad; beg.pop_back(); s.pop(); } void add(ll c, ll d, ll i) { while (!s.empty() && s.top() <= d) rem(); ad += c; beg.push_back({c-ad, i}); s.push(d); } ll qr(ll x) { if (x > beg[0].f + ad) return 0; ll l = 0, h = beg.size()-1; ll m = (l+h)/2 + ((l+h)&1); while (l < h) { if (beg[m].f + ad >= x) l = m; else h = m-1; m = (l+h)/2 + ((l+h)&1); } return beg[m].s; } }; int main() { freopen("in", "r", stdin); ll n, qr; cin >> n >> qr; vector<pll> v(n); for (pll &p : v) cin >> p.f >> p.s; vector<pair<pll, ll>> q(qr); vector<ll> ans(qr); for (ll i = 0; i < qr; i++) { cin >> q[i].f.f >> q[i].f.s; q[i].s = i; } sort(q.begin(), q.end()); reverse(q.begin(), q.end()); ll l = n; str s; for (ll i = 0; i < qr; i++) { while (l >= q[i].f.f) { s.add(v[l-1].s, v[l-1].f, l); l--; } ans[q[i].s] = s.qr(q[i].f.s); } for (ll i : ans) cout << i << '\n'; return 0; }

Compilation message (stderr)

fountain.cpp: In function 'int main()':
fountain.cpp:59:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     freopen("in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...