Submission #1094877

#TimeUsernameProblemLanguageResultExecution timeMemory
1094877KerimHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
615 ms176212 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] = max(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++){ d[i] = -1; for (int j = i; j >= 1; j--) if (arr[j] > arr[i]){ d[i] = j; break; } // 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 != -1){ s[i] = max(s[i], arr[i]+arr[j]); // upd(i, arr[i]+arr[j], 1, 1, n); } for (auto ind: queries[j]){ int mx = 0; for (int h = l[ind]; h <= r[ind]; h++) mx = max(mx, s[h]); // ans[ind] = mx <= k[ind]; if (mx <= k[ind]) ans[ind] = 1; // ans[ind] = tap(l[ind], r[ind], 1, 1, n) <= k[ind]; } } for (int i = 1; i <= q; i++) printf("%d\n", ans[i]); return 0; }

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:51:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
sortbooks.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |   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...