This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
const int N = 1e6+12,INF=1e9+7;
int q[N],ct[N],der[4*N];
void update(int v,int l,int r,int x,int y){
if (l == x && r == x){
der[v] = y;
}
else {
int m = l+r>>1;
if (m<x)
update((v<<1)+1,m+1,r,x,y);
else
update(v<<1,l,m,x,y);
der[v]=max(der[v<<1],der[(v<<1)+1]);
}
}
int get_ans(int v,int l,int r,int ql,int qr){
if (qr < l || ql > r)ret 0;
if (ql <= l && r<= qr)ret der[v];
int m = l+r>>1;
ret max(get_ans(v<<1,l,m,ql,qr),get_ans((v<<1)+1,m+1,r,ql,qr));
}
main(){
deque <pair<pii,pii> > v;
int n,t,i,j,cnt=1,res=0;
scan2(n,t)
for (i=1;i<=n;++i){
scan1(q[i])
}
while (t--){
int l,r,k;
scan3(l,r,k)
v.pb({{r,l},{k,cnt++}});
}
sort(all(v));
vector <pii> ans;
for (i=1;i<=n;++i){
while (!ans.empty() && ans.back().fr < q[i]){
ans.pop_back();
}
bool f=0;
if (ans.empty()){
ans.pb({q[i],i});
f=1;
}
int x = ans.back().fr;
int y = ans.back().sc;
if (!f)
ans.pb({q[i],i});
if (x > q[i]){
update(1,1,n,y,x+q[i]);
}
while (!v.empty() && v[0].fr.fr == i){
res = get_ans(1,1,n,v[0].fr.sc,i);
ct[v[0].sc.sc] = (v[0].sc.fr >=res);
v.pop_front();
}
}
for (i=1;i<cnt;++i)
cout <<ct[i]<<"\n";
}
Compilation message (stderr)
sortbooks.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:24:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
24 | int m = l+r>>1;
| ~^~
sortbooks.cpp: In function 'long long int get_ans(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:36:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int m = l+r>>1;
| ~^~
sortbooks.cpp: At global scope:
sortbooks.cpp:40:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
40 | main(){
| ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:42:15: warning: unused variable 'j' [-Wunused-variable]
42 | int n,t,i,j,cnt=1,res=0;
| ^
sortbooks.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:43:5: note: in expansion of macro 'scan2'
43 | scan2(n,t)
| ^~~~~
sortbooks.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
9 | #define scan1(a) scanf("%lld",&a);
| ~~~~~^~~~~~~~~~~
sortbooks.cpp:45:9: note: in expansion of macro 'scan1'
45 | scan1(q[i])
| ^~~~~
sortbooks.cpp:11:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
11 | #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:49:9: note: in expansion of macro 'scan3'
49 | scan3(l,r,k)
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |