제출 #486724

#제출 시각아이디문제언어결과실행 시간메모리
486724Urvuk3Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
13 / 100
1360 ms100868 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MAXN=1e6+3,MAXA=5e6+5,INF=1e9,LINF=1e18; #define fi first #define se second #define pll pair<ll,ll> #define pii pair<int,int> #define mid (l+r)/2 #define sz(a) int((a).size()) #define all(a) a.begin(),a.end() #define mod 1000000007LL #define pb push_back #define endl "\n" #define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush; #define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} #define pb push_back #define pf push_front #define ppf pop_front #define ppb pop_back #define PRINTvec(x) { cerr<<#x<<"-"; for(int i=0;i<sz(x);i++) cerr<<x[i]<<" "; cerr<<endl; } ll n,m,k,x,y,z,res=0,l,r,idx; string s,t; vector<int> a; ifstream input; ofstream output; int seg[4*MAXN]; #ifdef ONLINE_JUDGE #define input cin #define output cout #endif struct kveri{ int l,r,idx,k; void input(){ cin>>l>>r>>idx; } kveri(int l1,int r1,int idx1,int k1){ l=l1; r=r1; idx=idx1; k=k1; } }; vector<kveri> q[MAXN]; void update(int node,int l,int r,int idx,int val){ if(l==r){ seg[node]=val; return; } if(idx<=mid) update(2*node,l,mid,idx,val); else update(2*node+1,mid+1,r,idx,val); seg[node]=max(seg[2*node],seg[2*node+1]); } int query(int node,int l,int r,int L,int R){ if(L<=l && r<=R) return seg[node]; int ret=0; if(L<=mid) ret=max(ret,query(2*node,l,mid,L,R)); if(R>mid) ret=max(ret,query(2*node+1,mid+1,r,L,R)); return ret; } void solve(){ cin>>n>>m; a.resize(n+1); vector<int> ans(n+1); for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=m;i++){ cin>>l>>r>>k; idx=i; q[r].pb(kveri(l,r,idx,k)); } stack<int> s; for(int i=1;i<=n;i++){ while(!s.empty() && a[s.top()]<=a[i]){ s.pop(); } if(!s.empty()){ update(1,1,n,s.top(),a[s.top()]+a[i]); } for(kveri kv:q[i]){ if(query(1,1,n,kv.l,i)<=kv.k){ ans[kv.idx]=1; } } s.push(i); } for(int i=1;i<=m;i++){ cout<<ans[i]<<endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE input.open("D:\\UROS\\Programiranje\\input.in",ios::in); output.open("D:\\UROS\\Programiranje\\output.out",ios::out|ios::trunc); #endif //freopen(".in","r",stdin); //freopen(".out","w",stdout); int t; //cin>>t; t=1; while(t--){ solve(); } 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...