Submission #1092880

#TimeUsernameProblemLanguageResultExecution timeMemory
1092880SunbaeFountain (eJOI20_fountain)C++17
30 / 100
83 ms9776 KiB
#include <bits/stdc++.h> #define z exit(0) using namespace std; typedef long long ll; const int N = 1e5 + 5; vector<int> v[N]; ll qs[N]; int d[N], st[N], idx[N], C[N], vis[N], nxt[N], sz, c; signed main(){ int n, q; scanf("%d %d", &n, &q); for(int i = 0; i<n; ++i) scanf("%d %lld", d+i, qs+i); for(int i = n-1; i>=0; --i){ while(sz > 0 && d[st[sz-1]] <= d[i]) --sz; nxt[i] = (sz > 0) ? st[sz-1] : n; st[sz++] = i; } for(int i = 0; i<n; ++i){ if(vis[i]) continue; for(int j = i; j<n; j = nxt[j]){ vis[j] = 1; v[C[j] = c].push_back(j); } ++c; } for(int i = 0; i<c; ++i){ sz = v[i].size(); for(int j = 0; j<sz; ++j){ idx[v[i][j]] = j; if(j > 0) qs[v[i][j]] += qs[v[i][j-1]]; } } while(q--){ int i, w; scanf("%d %d", &i, &w); --i; c = C[i]; ll rem = (idx[i] > 0) ? qs[v[c][idx[i]-1]] : 0; int low = idx[i], high = v[c].size() - 1, ans = -1; while(low <= high){ int mid = low + ((high-low)>>1); ll tmp = qs[v[c][mid]] - rem; if(tmp >= w) ans = v[c][mid], high = mid-1; else if(tmp < w) low = mid+1; } printf("%d\n", ans + 1); } }

Compilation message (stderr)

fountain.cpp: In function 'int main()':
fountain.cpp:10:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  int n, q; scanf("%d %d", &n, &q);
      |            ~~~~~^~~~~~~~~~~~~~~~~
fountain.cpp:11:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  for(int i = 0; i<n; ++i) scanf("%d %lld", d+i, qs+i);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:33:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   int i, w; scanf("%d %d", &i, &w); --i;
      |             ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...