This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Dost SEFEROĞLU
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define vi vector<int>
#define all(xx) xx.begin(),xx.end()
const int N = 1e6+1,inf = 2e9,B = 23,MOD = 998244353,LIM = 1e9;
struct Node {
vi v;
int ans,mx;
};
int get_smaller(const vi& v, const int x) {
auto it = lower_bound(v.begin(),v.end(),x);
if (it == v.begin()) return -inf;
return *(--it);
}
Node merge(const Node& n1,const Node& n2) {
int n = n1.v.size(),m = n2.v.size();
int ptr = 0,ptr2 = 0;
Node ret;
while (ptr < n && ptr2 < m) {
if (n1.v[ptr] < n2.v[ptr2]) ret.v.push_back(n1.v[ptr++]);
else ret.v.push_back(n2.v[ptr2++]);
}
while (ptr < n) ret.v.push_back(n1.v[ptr++]);
while (ptr2 < m) ret.v.push_back(n2.v[ptr2++]);
ret.mx = max(n1.mx,n2.mx);
ret.ans = max({n1.ans,n2.ans,n1.mx+get_smaller(n2.v,n1.mx)});
return ret;
}
vi vv;
vi a(N);
struct ST {
vector<Node> t;
void build(int node,int l,int r){
if (l == r) {
t[node] = {vi{a[l]},0,a[l]};
return;
}
int m = (l+r) >> 1;
build(2*node,l,m),build(2*node+1,m+1,r);
t[node] = merge(t[2*node],t[2*node+1]);
}
ST(int nn) {
t.resize(4*nn+1);
build(1,1,nn);
}
void get_nodes(int node,int l,int r,int L,int R) {
if (l > R || r < L) return;
if (l >= L && r <= R) {
vv.push_back(node);
return;
}
int m = (l+r) >> 1;
get_nodes(2*node,l,m,L,R),get_nodes(2*node+1,m+1,r,L,R);
}
};
void solve() {
int n,m;
cin >> n >> m;
for (int i=1;i<=n;i++) cin >> a[i];
ST st(n);
while (m--) {
int l,r,k;
cin >> l >> r >> k;
st.get_nodes(1,1,n,l,r);
int ans = 0;
for (auto it : vv) ans = max(ans,st.t[it].ans);
int curmx = st.t[vv[0]].mx;
for (int i=1;i<vv.size();i++) {
ans = max(ans,curmx+get_smaller(st.t[vv[i]].v,curmx));
curmx = max(curmx,st.t[vv[i]].mx);
}
if (ans <= k) cout << 1 << '\n';
else cout << 0 << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
Compilation message (stderr)
sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for (int i=1;i<vv.size();i++) {
| ~^~~~~~~~~~
# | 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... |