제출 #1150217

#제출 시각아이디문제언어결과실행 시간메모리
1150217dostsHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
1288 ms136500 KiB
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3,unroll-loops") using namespace std; #define int long long #define pii pair<int,int> #define ff first #define ss second #define sp << " " << #define all(cont) cont.begin(),cont.end() #define vi vector<int> const int inf = 1e17,N = 2e6+1,MOD = 1e9+7,BL = 1000; struct ST { vi t,lazy; ST(int nn) { t.assign(4*nn+1,0); lazy.assign(4*nn+1,0); } void push(int node,bool leaf) { t[node]+=lazy[node]; if (!leaf) { lazy[2*node]+=lazy[node]; lazy[2*node+1]+=lazy[node]; } lazy[node] = 0; } void update(int node,int l,int r,int L,int R,int v) { push(node,l==r); if (l > R || r < L) return; if (l >= L && r <= R) { lazy[node]+=v; push(node,l==r); return; } int m = (l+r) >> 1; update(2*node,l,m,L,R,v),update(2*node+1,m+1,r,L,R,v); t[node] = max(t[2*node],t[2*node+1]); } int query(int node,int l,int r,int L,int R) { push(node,l==r); if (l > R || r < L) return 0;; if (l >=L && r <= R) return t[node]; int m = (l+r) >> 1; return max(query(2*node,l,m,L,R),query(2*node+1,m+1,r,L,R)); } }; void solve() { int n,q; cin >> n >> q; vi a(n+1); for (int i=1;i<=n;i++) { cin >> a[i]; } vi ans(q+1); vector<pair<pii,int>> qs[n+1]; for (int i=1;i<=q;i++) { int l,r,k; cin >> l >> r >> k; qs[r].push_back({{l,k},i}); } ST st(n+1); stack<pii> stk; stk.push({-inf,0}); for (int i=1;i<=n;i++) { while (stk.top().ff > a[i]) { int id = stk.top().ss; int v = stk.top().ff; stk.pop(); st.update(1,1,n,stk.top().ss+1,id,v-a[i]); } stk.push({a[i],i}); for (auto it : qs[i]) { ans[it.ss] = (st.query(1,1,n,it.ff.ff,i) <= it.ff.ss); } } for (int i=1;i<=q;i++) cout << ans[i] << '\n'; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifdef Dodi freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t = 1; //cin >> t; while (t --> 0) solve(); }
#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...