Submission #444633

#TimeUsernameProblemLanguageResultExecution timeMemory
444633shrimbFountain (eJOI20_fountain)C++17
0 / 100
233 ms38272 KiB
#include"bits/stdc++.h" #define int long long #define endl '\n' using namespace std; pair<int,int> sparse[100001][20]; // {node, capacity} signed main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; for (int i = 1 ; i <= n ; i++) { for (int j = 0 ; j < 20 ; j++) sparse[i][j] = {-1, INT_MAX}; } pair<int,int> arr[n + 1]; vector<pair<int,int>> v; // {radius, index} set<int> s; for (int i = 1 ; i <= n ; i++) { cin >> arr[i].first >> arr[i].second; v.push_back({arr[i].first, i}); } sort(v.begin(), v.end()); for (int i = n - 1 ; i >= 0 ; i--) { auto it = s.lower_bound(v[i].second); sparse[v[i].second][0] = {(it == s.end() ? -1 : *it), arr[v[i].second].second}; s.insert(v[i].second); } for (int i = n ; i >= 1 ; i--) { for (int j = 1 ; sparse[i][j-1].first != -1 ; j++) { sparse[i][j] = {sparse[sparse[i][j-1].first][j-1].first, sparse[i][j-1].second + sparse[sparse[i][j-1].first][j-1].second}; } } while (q--) { int s, x; cin >> s >> x; int used = 0; for (int i = 19 ; i >= 0 ; i--) { if (sparse[s][i].second < x) { s = sparse[s][i].first; x -= sparse[s][i].second; } if (s == -1) break; } cout << (s == -1 ? 0 : s) << endl; } }

Compilation message (stderr)

fountain.cpp: In function 'int main()':
fountain.cpp:40:13: warning: unused variable 'used' [-Wunused-variable]
   40 |         int used = 0;
      |             ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...