Submission #590617

#TimeUsernameProblemLanguageResultExecution timeMemory
590617Do_you_copyHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
851 ms92524 KiB
#include <bits/stdc++.h> #define taskname "test" #define fi first #define se second #define pb push_back #define faster ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; using ll = long long; using pii = pair <int, int>; using pil = pair <int, ll>; using pli = pair <ll, int>; using pll = pair <ll, ll>; using ull = unsigned ll; mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count()); ll min(const ll &a, const ll &b){ return (a < b) ? a : b; } ll max(const ll &a, const ll &b){ return (a > b) ? a : b; } //const ll Mod = 1000000009; //const ll Mod2 = 999999999989; //only use when required const int maxN = 1e6 + 1; int n, qq; int a[maxN]; struct TQuery{ int l, k, idx; }; vector <TQuery> q[maxN]; int bit[maxN]; int ans[maxN]; void update(int x, int val){ for (; x; x -= x & -x){ bit[x] = max(bit[x], val); } } int get(int x, int val){ int res = 0; for (; x <= n; x += x & -x){ res = max(res, bit[x]); } return res; } void Init(){ cin >> n >> qq; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= qq; ++i){ int l, r, k; cin >> l >> r >> k; q[r].pb({l, k, i}); } vector <int> S; for (int i = 1; i <= n; ++i){ while (!S.empty() && a[S.back()] <= a[i]){ S.pop_back(); } if (!S.empty()){ update(S.back(), a[i] + a[S.back()]); } S.pb(i); for (auto &j: q[i]){ //from j -> i if (get(j.l, i) <= j.k) ans[j.idx] = 1; else ans[j.idx] = 0; } } for (int i = 1; i <= qq; ++i) cout << ans[i] << "\n"; } int main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); //freopen(taskname".out", "w", stdout); } faster; ll tt = 1; //cin >> tt; while (tt--){ Init(); } }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(taskname".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...