Submission #1260164

#TimeUsernameProblemLanguageResultExecution timeMemory
1260164minggaFountain (eJOI20_fountain)C++20
100 / 100
291 ms18424 KiB
// Author: caption_mingle #include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define ll long long const int mod = 1e9 + 7; const int inf = 2e9; const int N = 1e5 + 7; int n, q, d[N], c[N], nxt[N][20], cap[N][20]; signed main() { cin.tie(0) -> sync_with_stdio(0); #define task "" if(fopen(task ".INP", "r")) { freopen(task ".INP", "r", stdin); freopen(task ".OUT", "w", stdout); } cin >> n >> q; for(int i = 1; i <= n; i++) cin >> d[i] >> c[i]; vector<int> st; st.pb(0); d[0] = inf; for(int i = n; i > 0; i--) { while(d[st.back()] <= d[i]) st.pop_back(); nxt[i][0] = st.back(); cap[i][0] = c[st.back()]; st.pb(i); } for(int j = 1; j < 20; j++) { for(int i = 0; i <= n; i++) { int u = nxt[i][j - 1]; nxt[i][j] = nxt[u][j - 1]; cap[i][j] = cap[i][j - 1] + cap[u][j - 1]; } } for(int i = 1; i <= q; i++) { int r, v; cin >> r >> v; if(v <= c[r]) { cout << r << ln; continue; } v -= c[r]; for(int j = 19; j >= 0; j--) { if(v >= cap[r][j]) { v -= cap[r][j]; r = nxt[r][j]; } } if(v) r = nxt[r][0]; cout << r << ln; } cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }

Compilation message (stderr)

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