Submission #689800

#TimeUsernameProblemLanguageResultExecution timeMemory
689800nguyentunglamHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
833 ms94116 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 1e6 + 10; int a[N], k[N], bit[N], ans[N]; int n, m; vector<pair<int, int> > query[N]; void up(int pos, int val) { while (pos) { bit[pos] = max(bit[pos], val); pos -= pos & -pos; } } int get(int pos) { int ret = 0; while (pos <= n) { ret = max(ret, bit[pos]); pos += pos & -pos; } return ret; } int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } cin >> n >> m; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= m; i++) { int l, r; cin >> l >> r >> k[i]; query[r].push_back({l, i}); } stack<int> st; for(int i = 1; i <= n; i++) { while (!st.empty() && a[st.top()] <= a[i]) st.pop(); if (!st.empty()) up(st.top(), a[st.top()] + a[i]); st.push(i); for(auto [l, id] : query[i]) ans[id] = get(l); } for(int i = 1; i <= m; i++) cout << (ans[i] <= k[i]) << endl; }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:29:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:30:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:33:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:34:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...