Submission #588486

#TimeUsernameProblemLanguageResultExecution timeMemory
588486AmirElarbiHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
2635 ms104688 KiB
#include <bits/stdc++.h> #define vi vector<int> #define ve vector #define ll long long #define vf vector<float> #define vll vector<pair<ll,ll>> #define ii pair<int,int> #define pll pair<ll,ll> #define vvi vector<vi> #define vii vector<ii> #define gii greater<ii> #define pb push_back #define mp make_pair #define fi first #define se second #define INF 1e9 #define eps 1e-7 #define eps1 1e-2 #define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define MAX_A 2e5+5 using namespace std; const int MOD = 1e4+7; const int nax = 1e6+5; typedef complex<int> Point; #define X real() #define Y imag() int st[nax*4]; void update(int v, int l, int r, int pos, int val){ if(l > pos || r < pos) return; if(l == r){ st[v] = val; return; } int md = (l+r)/2; update(v*2,l,md,pos,val); update(v*2+1,md+1,r,pos,val); st[v] = max(st[v*2], st[v*2+1]); } int query(int v, int l, int r, int i, int j){ if(l > j || r < i) return 0; if(i <= l && r <= j) return st[v]; int md = (l+r)/2; return max(query(v*2,l,md,i,j), query(v*2+1, md+1, r, i, j)); } int main(){ optimise; int t; t = 1; while(t--){ int n,q; cin >> n >> q; vi s(n),l(q), r(q), k(q), ans(q); vvi qrs(n); for (int i = 0; i < n; ++i) { cin >> s[i]; } for (int i = 0; i < q; ++i) { cin >> l[i] >> r[i] >> k[i]; l[i]--,r[i]--; qrs[r[i]].pb(i); } stack<int> stck; for (int i = 0; i < n; ++i) { while(!stck.empty() && s[stck.top()] <= s[i]){ stck.pop(); } if(!stck.empty()) { update(1,0,n-1, stck.top(), s[stck.top()]+s[i]); } stck.push(i); for(auto x : qrs[i]){ ans[x] = (query(1,0,n-1,l[x],i) <= k[x]); } } for (int i = 0; i < q; ++i) { cout << ans[i] << endl; } } }
#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...