This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e3 + 9;
const ll inf = 1e9 + 7;
struct Node{
vector<ll> v; ll inv;
};
Node st[4*N],spare;
ll n,Q,a[N];
Node Combine(Node lf,Node rg){
Node now;
now.inv = max(lf.inv,rg.inv);
if (rg.v.size() && lf.v.size()){
auto it = prev(upper_bound(rg.v.begin(),rg.v.end(),lf.v.back()));
if (it != rg.v.end()) now.inv = max(now.inv,*it + lf.v.back());
}
ll st1 = 0,st2 = 0;
while(st1 < lf.v.size() || st2 < rg.v.size()){
ll x = inf,y = inf;
if (st1 < lf.v.size()) x = lf.v[st1];
if (st2 < rg.v.size()) y = rg.v[st2];
if (x < y) now.v.push_back(x),st1++;
else now.v.push_back(y),st2++;
//cout<<x<<" "<<y; exit(0);
}
return now;
}
void build(ll id,ll l,ll r){
//cout<<id<<" "<<l<<" "<<r<<"\n";
if (l == r){
st[id].v.push_back(a[l]); st[id].inv = 0;
return;
}
ll mid = (l + r)/2;
build(id*2,l,mid); build(id*2 + 1,mid + 1,r);
st[id] = Combine(st[id*2],st[id*2 + 1]);
}
Node Get(ll id,ll l,ll r,ll u,ll v){
if (v < l||r < u) return spare;
if (u <= l&&r <= v) return st[id];
ll mid = (l + r)/2;
return Combine(Get(id*2,l,mid,u,v),Get(id*2 + 1,mid + 1,r,u,v));
}
ll l,r,k;
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".INP","r")){
freopen(task".INP","r",stdin);
//freopen(task".OUT","w",stdout);
}
cin>>n>>Q;
for (ll i = 1;i <= n;i++) cin>>a[i];
build(1,1,n); //cout<<st[4].inv; return 0;
while(Q--){
cin>>l>>r>>k;
Node now = Get(1,1,n,l,r); //cout<<now.inv; return 0;
cout<<(now.inv <= k)<<"\n";
}
}
Compilation message (stderr)
sortbooks.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization O2
|
sortbooks.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
sortbooks.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
3 | #pragma target ("avx2")
|
sortbooks.cpp: In function 'Node Combine(Node, Node)':
sortbooks.cpp:31:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | while(st1 < lf.v.size() || st2 < rg.v.size()){
| ~~~~^~~~~~~~~~~~~
sortbooks.cpp:31:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | while(st1 < lf.v.size() || st2 < rg.v.size()){
| ~~~~^~~~~~~~~~~~~
sortbooks.cpp:33:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | if (st1 < lf.v.size()) x = lf.v[st1];
| ~~~~^~~~~~~~~~~~~
sortbooks.cpp:34:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | if (st2 < rg.v.size()) y = rg.v[st2];
| ~~~~^~~~~~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | freopen(task".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |