Submission #341765

#TimeUsernameProblemLanguageResultExecution timeMemory
341765blacktulipHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
1144 ms57968 KiB
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> using namespace std; typedef long long lo; typedef pair< lo,lo > PII; #define fi first #define se second #define int long long #define mp make_pair #define endl "\n" #define pb push_back #define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR for(int i=0;i<n;i++) #define mid ((start+end)/2) #define ort ((bas+son)/2) const lo inf = 3000000000; const lo KOK = 100000; const lo LOG = 30; const lo li = 1000005; const lo mod = 1000000007; int n,m,b[li],a[li],k,flag,t,maxi[li],mx,dp[li],mini[li],tree[li*4],anss[li]; int cev; pair<int,pair<int,pair<int,int>>> p[li]; string s; vector<int> v[1005]; inline void update(int node,int start,int end,int l,int r,int val){ if(start>end || start>r || end<l)return ; if(start>=l && end<=r){tree[node]=max(tree[node],val);return ;} update(node*2,start,mid,l,r,val),update(node*2+1,mid+1,end,l,r,val); tree[node]=max(tree[node*2],tree[node*2+1]); } inline int query(int node,int start,int end,int l,int r){ if(start>end || start>r || end<l)return 0; if(start>=l && end<=r)return tree[node]; return max(query(node*2,start,mid,l,r),query(node*2+1,mid+1,end,l,r)); } int32_t main(void){ scanf("%lld %lld",&n,&t); for(int i=1;i<=n;i++)scanf("%lld",&a[i]); for(int i=1;i<=t;i++){ scanf("%lld %lld %lld",&p[i].fi,&p[i].se.fi,&p[i].se.se.fi); p[i].se.se.se=i; } sort(p+1,p+t+1); reverse(p+1,p+t+1); stack<pair<int,int>> st; int ind=t; for(int i=n;i>=1;i--){ int son=i; while(st.size() && a[i]>st.top().fi){ update(1,1,n,son,son,a[i]+st.top().fi); //~ cout<<a[i]+st.top().fi<<endl; son=st.top().se; st.pop(); } if(st.size()==0)son=n; st.push({a[i],son}); while(ind>0 && p[ind].fi==i){ if(query(1,1,n,i,p[ind].se.fi)<=p[ind].se.se.fi)anss[p[ind].se.se.se]=1; ind--; } } for(int i=1;i<=t;i++)printf("%lld\n",anss[i]); return 0; }

Compilation message (stderr)

sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   48 |     scanf("%lld %lld",&n,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp:49:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |  for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
      |                       ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |   scanf("%lld %lld %lld",&p[i].fi,&p[i].se.fi,&p[i].se.se.fi);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...