Submission #467757

#TimeUsernameProblemLanguageResultExecution timeMemory
467757LumosFountain (eJOI20_fountain)C++17
60 / 100
422 ms6288 KiB
//amira #include <bits/stdc++.h> using namespace std; #define endl "\n" #define f first #define s second #define pb push_back #define pii pair<int,int> #define ll long long #define pll pair <ll,ll> #define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); const int M = 1e9+7; const int N = 2e5 + 111; const ll INF = 1e10 + 1; const int K = 205; ll n,q,d[N],w[N],nxt[N],p[N]; int main() { #ifdef MM freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif stack <ll> st; cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> d[i] >> w[i]; p[i] = p[i - 1] + w[i]; } if (n <= 1000 && q <= 2000) { for (int i = n; i >= 1; i--) { while (!st.empty() && d[st.top()] <= d[i]) { st.pop(); } if (st.empty()) nxt[i] = n + 1; else nxt[i] = st.top(); st.push(i); } for (int i = 1; i <= q; i++) { ll id,l; cin >> id >> l; ll final = id, cur = id; //cout << "case " << i << endl; while (cur < n + 1 && w[cur] < l) { l -= w[cur]; cur = nxt[cur]; //cout << l << ' ' << cur << endl; } if (cur == n + 1) cout << 0 << endl; else cout << cur << endl; } return 0; } for (int i = 1; i <= q; i++) { ll id,l; cin >> id >> l; ll pos = lower_bound(p+1,p+1+n, l + p[id - 1]) - p; if (pos == n + 1) cout << 0 << endl; else cout << pos << endl; } return 0; }

Compilation message (stderr)

fountain.cpp: In function 'int main()':
fountain.cpp:44:7: warning: unused variable 'final' [-Wunused-variable]
   44 |    ll final = id, cur = id; //cout << "case " << i << endl;
      |       ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...