Submission #1127333

#TimeUsernameProblemLanguageResultExecution timeMemory
1127333koukirocksHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
599 ms33996 KiB
#include <bits/stdc++.h> #define speed ios_base::sync_with_stdio(0); cin.tie(0) #define all(x) (x).begin(),(x).end() #define F first #define S second //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx,avx2") //#pragma GCC target("popcnt") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll MAX=2e5+10,P=1e9+7; const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f; const ldb eps=1e-6; const ldb PI=acos(-1.0); const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; template<typename T> using vvector = vector<vector<T>>; struct qry { int l,r,k,id; }; struct BIT { int n; vector<int> a; BIT(int N):n(N) { a.resize(n+1); } void update(int x,int val) { while (x<=n) { a[x]=max(a[x],val); x+=(-x&x); } } int query(int x) { int ans=0; while (x) { ans=max(a[x],ans); x-=(-x&x); } return ans; } }; int main() { speed; int n,q; cin>>n>>q; vector<int> w(n+1); vector<qry> Q(q); for (int i=1;i<=n;i++) { cin>>w[i]; } for (int i=0;i<q;i++) { cin>>Q[i].l>>Q[i].r>>Q[i].k; Q[i].id=i; } sort(all(Q),[&](qry a,qry b){ return a.l>b.l; }); vector<int> stk; BIT ans(n); vector<int> fin(q); int qid=0; for (int i=n;i>=1;i--) { while (!stk.empty() and w[stk.back()]<w[i]) { int v=stk.back(); stk.pop_back(); ans.update(v,w[v]+w[i]); // cout<<v<<" "<<w[i]+w[v]<<" upd\n"; } stk.push_back(i); while (qid<q and Q[qid].l==i) { fin[Q[qid].id]=ans.query(Q[qid].r)<=Q[qid].k; // cout<<Q[qid].l<<" "<<Q[qid].r<<" "<<ans.query(Q[qid].r)<<" Q\n"; qid++; } } for (int i=0;i<q;i++) cout<<fin[i]<<"\n"; return 0; }
#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...