Submission #436109

#TimeUsernameProblemLanguageResultExecution timeMemory
436109cpp219Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
1365 ms92336 KiB
#pragma GCC optimization O2 #pragma GCC optimization "unroll-loop" #pragma target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; typedef pair<ll,ll> LL; const ll N = 1e6 + 9; const ll inf = 1e9 + 7; struct Query{ ll l,k,id; }; vector<Query> v[N]; stack<ll> st; ll n,Q,ans[N],a[N],l,r,k,bit[N]; void upd(ll p,ll val){ for (ll i = p;i > 0;i -= i & -i) bit[i] = max(bit[i],val); } ll Get(ll p){ ll res = 0; for (ll i = p;i <= n;i += i & -i) res = max(res,bit[i]); return res; } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "test" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n>>Q; for (ll i = 1;i <= n;i++) cin>>a[i]; a[0] = inf; for (ll i = 1;i <= Q;i++){ cin>>l>>r>>k; v[r].push_back({l,k,i}); } st.push(0); for (ll i = 1;i <= n;i++){ while(a[st.top()] <= a[i]) st.pop(); if (st.top()) upd(st.top(),a[st.top()] + a[i]); st.push(i); for (auto j : v[i]){ ll id = j.id; ans[id] = (Get(j.l) <= j.k); } } for (ll i = 1;i <= Q;i++) cout<<ans[i]<<"\n"; }

Compilation message (stderr)

sortbooks.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
sortbooks.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
sortbooks.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:40:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   40 |     for (ll i = 1;i <= n;i++) cin>>a[i]; a[0] = inf;
      |     ^~~
sortbooks.cpp:40:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   40 |     for (ll i = 1;i <= n;i++) cin>>a[i]; a[0] = inf;
      |                                          ^
sortbooks.cpp:48:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   48 |         if (st.top()) upd(st.top(),a[st.top()] + a[i]); st.push(i);
      |         ^~
sortbooks.cpp:48:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   48 |         if (st.top()) upd(st.top(),a[st.top()] + a[i]); st.push(i);
      |                                                         ^~
sortbooks.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen(task".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...