Submission #1094868

#TimeUsernameProblemLanguageResultExecution timeMemory
1094868KerimHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
652 ms176216 KiB
#include "bits/stdc++.h" using namespace std; const int N = 1e6+6; int arr[N], d[N], ans[N]; vector<int> queries[N]; int l[N], r[N], k[N], s[N<<2]; void upd(int p, int v, int nd, int x, int y){ if (x == y){ s[nd] = v; return; } int mid = (x+y) >> 1; if (p <= mid) upd(p, v, nd<<1, x, mid); else upd(p, v, nd<<1|1, mid+1, y); s[nd] = max(s[nd<<1], s[nd<<1|1]); } int tap(int l, int r, int nd, int x, int y){ if (l > y or x > r) return 0; if (l <= x and y <= r) return s[nd]; int mid = (x+y) >> 1; return max(tap(l, r, nd<<1, x, mid), tap(l, r, nd<<1|1, mid+1, y)); } int main(){ // freopen("file.in", "r", stdin); int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", arr+i); stack<int> st; for (int i = 1; i <= n; i++){ while (!st.empty() and arr[st.top()] <= arr[i]) st.pop(); if (st.empty()) d[i] = -1; else d[i] = st.top(); st.push(i); } int q; scanf("%d", &q); for (int i = 1; i <= q; i++){ scanf("%d%d%d", l+i, r+i, k+i); queries[r[i]].push_back(i); } for (int j = 1; j <= n; j++){ int i = d[j]; if (~i) upd(i, arr[i]+arr[j], 1, 1, n); for (auto ind: queries[j]) ans[ind] = tap(l[ind], r[ind], 1, 1, n) <= k[ind]; } for (int i = 1; i <= q; i++) printf("%d\n", ans[i]); }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
sortbooks.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%d", arr+i);
      |   ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
sortbooks.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |   scanf("%d%d%d", l+i, r+i, k+i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...