Submission #583589

#TimeUsernameProblemLanguageResultExecution timeMemory
583589MasterTasterHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
1910 ms190744 KiB
#include<iostream> #include<map> #include<vector> #include<stack> #include<algorithm> #define ll long long #define pii pair<int, int> #define xx first #define yy second #define pb push_back #define MAXN 1000010 using namespace std; int seg[4*MAXN], n, m, a[MAXN], lg[MAXN]; vector< pair < pii, pii > > all; vector< pair < pii, int > > order; map<pair< pii, int >, int> ress; void build(int node, int l, int r) { if (l==r) { seg[node]=-1; return; } int mid=l+(r-l)/2; build(2*node, l, mid); build(2*node+1, mid+1, r); seg[node]=max(seg[2*node], seg[2*node+1]); } void upd(int node, int l, int r, int ind, int val) { if (ind>r || ind<l) return; if (l==r) { seg[node]=val; return; } int mid=l+(r-l)/2; upd(2*node, l, mid, ind, val); upd(2*node+1, mid+1, r, ind, val); seg[node]=max(seg[2*node], seg[2*node+1]); } int maxQuery(int node, int l, int r, int left, int right) { if (left>r || right<l) return -1; if (left<=l && right>=r) return seg[node]; int mid=l+(r-l)/2; return max(maxQuery(2*node, l, mid, left, right), maxQuery(2*node+1, mid+1, r, left, right)); } int main(){ cin>>n>>m; for (int i=1; i<=n; i++) cin>>a[i]; stack<pii> st; st.push({1000000001, 0}); for (int i=1; i<=n; i++) { while (st.top().xx<a[i]) st.pop(); lg[i]=st.top().yy; //cout<<i<<" "<<lg[i]<<endl; st.push({a[i], i}); all.pb({{a[i]+a[lg[i]], 0}, {i, lg[i]}}); } for (int i=0; i<m; i++) { int l, r, k; cin>>l>>r>>k; order.pb({{l, r}, k}); all.pb({{k, 1}, {l, r}}); } sort(all.begin(), all.end(), greater< pair < pii, pii > >()); int N=all.size(); build(1,1, N); for (int i=0; i<all.size(); i++) { int k=all[i].xx.xx, t=all[i].xx.yy, l=all[i].yy.xx, r=all[i].yy.yy; //cout<<k<<" "<<t<<" "<<l<<" "<<r<<endl; if (t==0) { upd(1, 1, N, l, r); } else { int x=maxQuery(1, 1, N, l, r), temp=1; //cout<<x<<endl; if (x>=l) temp=0; ress[{{l, r}, k}]=temp; } } for (int i=0; i<m; i++) { int l=order[i].xx.xx, r=order[i].xx.yy, k=order[i].yy; cout<<ress[{{l, r}, k}]<<endl; } }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:77:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for (int i=0; i<all.size(); i++)
      |                   ~^~~~~~~~~~~
#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...