Submission #1282486

#TimeUsernameProblemLanguageResultExecution timeMemory
1282486swishy123Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
0 / 100
1667 ms37848 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int def = 4e6+1; const int maxk = 18; const ll inf = 1e18; int st[def]; void update(int l, int r, int crr, int i, int v){ if (l == r){ st[crr] = max(v, st[crr]); return; } if (r < i || l > i) return; int mid = (l + r) / 2; update(l, mid, crr * 2 + 1, i, v); update(mid + 1, r, crr * 2 + 2, i, v); st[crr] = max(st[crr * 2 + 1], st[crr * 2 + 2]); } int get(int l, int r, int ql, int qr, int crr){ if (l > qr || r < ql) return 0; if (l >= ql && r <= qr) return st[crr]; int mid = (l + r) / 2; return max(get(l, mid, ql, qr, crr * 2 + 1), get(mid + 1, r, ql, qr, crr * 2 + 2)); } void solve(){ int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; stack<pair<int, int>> st; vector<int> pos(n, -1); for (int i = 0; i < n; i++){ while (st.size() && st.top().first <= a[i]) st.pop(); if (st.size()) pos[i] = st.top().second; st.push({a[i], i}); } vector<tuple<int, int, int, int>> qr; for (int i = 0; i < q; i++){ int l, r, k; cin >> l >> r >> k; l--; r--; qr.push_back({r, l, k, i}); } sort(qr.begin(), qr.end()); int j = 0; vector<int> res(q, -1); for (int i = 0; i < q; i++){ auto [r, l, k, indx] = qr[i]; while (j <= r){ if (pos[j] != -1) update(0, n - 1, 0, pos[j], a[pos[j]] + a[j]); j++; } int val = get(0, n - 1, l, r, 0); res[indx] = val <= k; } for (int i = 0; i < q; i++) cout << res[i] << endl; } /* */ main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (ifstream("input.txt").good()){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } int t = 1; while (t--){ solve(); cout << "\n"; } }

Compilation message (stderr)

sortbooks.cpp:85:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   85 | main(){
      | ^~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         freopen("output.txt", "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...