Submission #1096838

#TimeUsernameProblemLanguageResultExecution timeMemory
1096838lmaobruhHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
643 ms101972 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ii pair<int, int> #define all(x) x.begin(), x.end() #define fo(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i) #define fd(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define fi first #define se second const int N = 1e6+5; int n, m, a[N], l[N], ans[N], k[N]; ll t[N]; vector<ii> g[N]; void upd(int p, ll v) { for (; p; p -= p & -p) chmax(t[p], v); } ll get(int p) { ll tot = 0; for (; p <= n; p += p & -p) chmax(tot, t[p]); return tot; } void sol() { cin >> n >> m; fo(i,1,n) cin >> a[i]; fo(i,1,m) { static int l, r; cin >> l >> r >> k[i]; g[r].pb({l, i}); } fo(i,1,n) { l[i] = i-1; while (l[i] && a[i] >= a[l[i]]) l[i] = l[l[i]]; if (l[i]) upd(l[i], a[l[i]] + a[i]); for (ii q : g[i]) ans[q.se] = (get(q.fi) <= k[q.se]); } fo(i,1,m) cout << ans[i] << '\n'; } signed main() { cin.tie(0) -> sync_with_stdio(0); if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin); int tc = 1, test = 0; // cin >> tc; while (++test <= tc) sol(); }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:51:37: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |     if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin);
      |                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...