제출 #256437

#제출 시각아이디문제언어결과실행 시간메모리
256437uacoder123Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
34 / 100
904 ms262148 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define F first #define S second #define FOR(i,a,b) for (auto i = (a); i <= (b); ++i) #define NFOR(i,a,b) for(auto i = (a); i >= (b); --i) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define mp(i,a) make_pair(i,a) #define pb(a) push_back(a) #define bit(x,b) (x&(1LL<<b)) typedef int lli; typedef pair <lli,lli> ii; typedef pair <lli,ii> iii; typedef vector <lli> vi; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; set<lli> segt[4000001]; lli n,m,ans[4000001],ans1; void up(lli node,lli l,lli r,lli in,lli v) { segt[node].insert(v); if(l==r) { ans[node]=0; return; } lli m=(l+r)/2; if(in<=m) up(2*node+1,l,m,in,v); else up(2*node+2,m+1,r,in,v); auto it=segt[2*node+2].lower_bound(*(--segt[2*node+1].end())); ans[node]=max(ans[2*node+1],ans[2*node+2]); if(it!=segt[2*node+2].begin()) { it--; ans[node]=max(ans[node],(*it)+(*(--segt[2*node+1].end()))); } } ii qu(lli node,lli l,lli r,lli s,lli e,lli cm) { if(l>e||r<s) return(mp(0,cm)); if(l>=s&&r<=e) { auto it=segt[node].lower_bound(cm); ans1=0; if(it!=segt[node].begin()) { it--; ans1=cm+(*it); } return(mp(max(ans[node],ans1),max(cm,(*(--segt[node].end()))))); } lli m=(l+r)/2; ii q1=qu(2*node+1,l,m,s,e,cm); ii q2=qu(2*node+2,m+1,r,s,e,q1.S); return(mp(max(q1.F,q2.F),q2.S)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n>>m; lli arr[n]; for(int i=0;i<n;++i) { lli f; cin>>f; arr[i]=f; up(0,0,n-1,i,f); } for(lli i=0;i<m;++i) { lli f,s,k; cin>>f>>s>>k; f--; s--; ii a=qu(0,0,n-1,f,s,arr[f]); if(a.F<=k) cout<<1<<'\n'; else cout<<0<<'\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...