#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
using ll=int;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>;
#define LLINF INF //((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (1000006)
struct node {
int v,add,base;
node*l,*r;
node(int S,int E){
int s=S,e=E,m=(s+e)>>1;
v=-LLINF, add=-LLINF, base=0;
if(s^e)l=new node(s,m),r=new node(m+1,e);
}
void update(int s,int e,int x,int y,int nval) {
value(s,e);
int m=(s+e)>>1;
if(s==x&&e==y) {
add = max(add, nval);
return;
}
if(x>m) r->update(m+1,e,x,y,nval);
else if(y<=m) l->update(s,m,x,y,nval);
else l->update(s,m,x,m,nval),r->update(m+1,e,m+1,y,nval);
v = max(l->value(s,m), r->value(m+1,e));
base = max(l->base, r->base);
}
ll rmq(int s,int e,int x,int y) {
if(x>y) return -LLINF;
value(s,e);
int m=(s+e)>>1;
if(s==x&&e==y) return v;
if(x>m) return r->rmq(m+1,e,x,y);
else if(y<=m) return l->rmq(s,m,x,y);
else return max(l->rmq(s,m,x,m), r->rmq(m+1,e,m+1,y));
}
void set(int s,int e,int x,int nval) {
value(s,e);
if(s==e) {
v = nval + base;
return;
}
int m=(s+e)>>1;
if(x>m) r->set(m+1,e,x,nval);
else l->set(s,m,x,nval);
v = max(l->value(s,m), r->value(m+1,e));
base = max(l->base, r->base);
}
ll value(int s,int e) {
v = max(v, add + base);
if(s^e) {
l->add=max(l->add, add);
r->add=max(r->add, add);
}
add=-LLINF;
return v;
}
void set_base(int s,int e,int x,int nval) {
value(s,e);
if(s==e) {
v-= base, base = nval, v+=base;
return;
}
int m=(s+e)>>1;
if(x>m) r->set_base(m+1, e, x, nval);
else l->set_base(s, m, x, nval);
v = max(l->value(s,m), r->value(m+1,e));
base = max(l->base, r->base);
}
} *seg;
int n,m,A[MAXN];
bool can[MAXN];
vector<int> v;
vector<tuple<int,int,int>> Q[MAXN];
#define gc getchar_unlocked
ll in(){
ll x=0;
char ch=gc();
while(ch<'0'||ch>'9') ch=gc();
while(ch>='0'&&ch<='9') {
x=(x<<3)+(x<<1)+(ch&15);
ch=gc();
}
return x;
}
ll fw[MAXN];
void update(int x,ll nval) {
x = n - x + 1;
for(; x <= n; x+=x&(-x)) fw[x]=max(fw[x],nval);
}
ll mx(int x) {
x = n - x + 1;
ll ans = 0;
for(; x; x-=x&(-x)) ans=max(ans,fw[x]);
return ans;
}
int main() {
n=in(),m=in();
FOR(i,1,n)A[i]=in();
seg=new node(1, n);
FOR(i,1,m) {
ll l,r,k;
l=in(), r=in(), k=in();
Q[r].pb({l, k, i});
}
auto add=[&](ll x){
while(v.size() && A[v.back()] <= A[x]) {
update(v.back(), seg->rmq(1, n, siz(v), siz(v)));
seg->set(1, n, siz(v), -LLINF);
v.pop_back();
}
v.eb(x);
seg->set_base(1, n, siz(v), A[x]);
};
auto upd=[&](ll x){
ll st=-1, en=siz(v);
while(en-st>1){// highest ind that is still > x
ll mid=(st+en)>>1;
if(A[v[mid]] > x) st=mid;
else en=mid;
}
if(st<0) return;
seg->update(1, n, 1, st+1, x);
};
FOR(r,1,n) {
upd(A[r]);
add(r);
for(auto q:Q[r]) {
ll l=get<0>(q);
ll ind = lbd(v, l) + 1;
ll mx2 = max(mx(l), seg->rmq(1, n, ind, siz(v)));
if(mx2 <= get<1>(q)) can[get<2>(q)]=1;
}
}
FOR(i,1,m) cout<<can[i]<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23936 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
17 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
24064 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23936 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
17 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
24064 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
11 |
Correct |
19 ms |
24044 KB |
Output is correct |
12 |
Correct |
23 ms |
24428 KB |
Output is correct |
13 |
Correct |
24 ms |
24428 KB |
Output is correct |
14 |
Correct |
25 ms |
24428 KB |
Output is correct |
15 |
Correct |
27 ms |
24428 KB |
Output is correct |
16 |
Correct |
24 ms |
24428 KB |
Output is correct |
17 |
Correct |
22 ms |
24300 KB |
Output is correct |
18 |
Correct |
24 ms |
24428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2670 ms |
149408 KB |
Output is correct |
2 |
Correct |
2676 ms |
182264 KB |
Output is correct |
3 |
Correct |
2661 ms |
182236 KB |
Output is correct |
4 |
Correct |
2662 ms |
182508 KB |
Output is correct |
5 |
Correct |
2078 ms |
183380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
216 ms |
36460 KB |
Output is correct |
2 |
Correct |
207 ms |
36332 KB |
Output is correct |
3 |
Correct |
164 ms |
36332 KB |
Output is correct |
4 |
Correct |
165 ms |
36332 KB |
Output is correct |
5 |
Correct |
165 ms |
36588 KB |
Output is correct |
6 |
Correct |
156 ms |
35948 KB |
Output is correct |
7 |
Correct |
158 ms |
35948 KB |
Output is correct |
8 |
Correct |
199 ms |
36260 KB |
Output is correct |
9 |
Correct |
42 ms |
25636 KB |
Output is correct |
10 |
Correct |
191 ms |
36260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23936 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
17 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
24064 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
11 |
Correct |
19 ms |
24044 KB |
Output is correct |
12 |
Correct |
23 ms |
24428 KB |
Output is correct |
13 |
Correct |
24 ms |
24428 KB |
Output is correct |
14 |
Correct |
25 ms |
24428 KB |
Output is correct |
15 |
Correct |
27 ms |
24428 KB |
Output is correct |
16 |
Correct |
24 ms |
24428 KB |
Output is correct |
17 |
Correct |
22 ms |
24300 KB |
Output is correct |
18 |
Correct |
24 ms |
24428 KB |
Output is correct |
19 |
Correct |
467 ms |
49132 KB |
Output is correct |
20 |
Correct |
464 ms |
49132 KB |
Output is correct |
21 |
Correct |
429 ms |
48492 KB |
Output is correct |
22 |
Correct |
421 ms |
48620 KB |
Output is correct |
23 |
Correct |
437 ms |
48620 KB |
Output is correct |
24 |
Correct |
317 ms |
48620 KB |
Output is correct |
25 |
Correct |
317 ms |
48440 KB |
Output is correct |
26 |
Correct |
331 ms |
48620 KB |
Output is correct |
27 |
Correct |
333 ms |
48620 KB |
Output is correct |
28 |
Correct |
341 ms |
48876 KB |
Output is correct |
29 |
Correct |
353 ms |
49004 KB |
Output is correct |
30 |
Correct |
351 ms |
49008 KB |
Output is correct |
31 |
Correct |
351 ms |
49004 KB |
Output is correct |
32 |
Correct |
357 ms |
49036 KB |
Output is correct |
33 |
Correct |
352 ms |
49004 KB |
Output is correct |
34 |
Correct |
318 ms |
48236 KB |
Output is correct |
35 |
Correct |
320 ms |
48236 KB |
Output is correct |
36 |
Correct |
311 ms |
48364 KB |
Output is correct |
37 |
Correct |
312 ms |
48236 KB |
Output is correct |
38 |
Correct |
309 ms |
48108 KB |
Output is correct |
39 |
Correct |
378 ms |
48676 KB |
Output is correct |
40 |
Correct |
262 ms |
41376 KB |
Output is correct |
41 |
Correct |
393 ms |
48692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
23936 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
17 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
24064 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
11 |
Correct |
19 ms |
24044 KB |
Output is correct |
12 |
Correct |
23 ms |
24428 KB |
Output is correct |
13 |
Correct |
24 ms |
24428 KB |
Output is correct |
14 |
Correct |
25 ms |
24428 KB |
Output is correct |
15 |
Correct |
27 ms |
24428 KB |
Output is correct |
16 |
Correct |
24 ms |
24428 KB |
Output is correct |
17 |
Correct |
22 ms |
24300 KB |
Output is correct |
18 |
Correct |
24 ms |
24428 KB |
Output is correct |
19 |
Correct |
2670 ms |
149408 KB |
Output is correct |
20 |
Correct |
2676 ms |
182264 KB |
Output is correct |
21 |
Correct |
2661 ms |
182236 KB |
Output is correct |
22 |
Correct |
2662 ms |
182508 KB |
Output is correct |
23 |
Correct |
2078 ms |
183380 KB |
Output is correct |
24 |
Correct |
216 ms |
36460 KB |
Output is correct |
25 |
Correct |
207 ms |
36332 KB |
Output is correct |
26 |
Correct |
164 ms |
36332 KB |
Output is correct |
27 |
Correct |
165 ms |
36332 KB |
Output is correct |
28 |
Correct |
165 ms |
36588 KB |
Output is correct |
29 |
Correct |
156 ms |
35948 KB |
Output is correct |
30 |
Correct |
158 ms |
35948 KB |
Output is correct |
31 |
Correct |
199 ms |
36260 KB |
Output is correct |
32 |
Correct |
42 ms |
25636 KB |
Output is correct |
33 |
Correct |
191 ms |
36260 KB |
Output is correct |
34 |
Correct |
467 ms |
49132 KB |
Output is correct |
35 |
Correct |
464 ms |
49132 KB |
Output is correct |
36 |
Correct |
429 ms |
48492 KB |
Output is correct |
37 |
Correct |
421 ms |
48620 KB |
Output is correct |
38 |
Correct |
437 ms |
48620 KB |
Output is correct |
39 |
Correct |
317 ms |
48620 KB |
Output is correct |
40 |
Correct |
317 ms |
48440 KB |
Output is correct |
41 |
Correct |
331 ms |
48620 KB |
Output is correct |
42 |
Correct |
333 ms |
48620 KB |
Output is correct |
43 |
Correct |
341 ms |
48876 KB |
Output is correct |
44 |
Correct |
353 ms |
49004 KB |
Output is correct |
45 |
Correct |
351 ms |
49008 KB |
Output is correct |
46 |
Correct |
351 ms |
49004 KB |
Output is correct |
47 |
Correct |
357 ms |
49036 KB |
Output is correct |
48 |
Correct |
352 ms |
49004 KB |
Output is correct |
49 |
Correct |
318 ms |
48236 KB |
Output is correct |
50 |
Correct |
320 ms |
48236 KB |
Output is correct |
51 |
Correct |
311 ms |
48364 KB |
Output is correct |
52 |
Correct |
312 ms |
48236 KB |
Output is correct |
53 |
Correct |
309 ms |
48108 KB |
Output is correct |
54 |
Correct |
378 ms |
48676 KB |
Output is correct |
55 |
Correct |
262 ms |
41376 KB |
Output is correct |
56 |
Correct |
393 ms |
48692 KB |
Output is correct |
57 |
Correct |
2672 ms |
183436 KB |
Output is correct |
58 |
Correct |
2689 ms |
183532 KB |
Output is correct |
59 |
Correct |
2577 ms |
182096 KB |
Output is correct |
60 |
Correct |
2569 ms |
182056 KB |
Output is correct |
61 |
Correct |
2549 ms |
182092 KB |
Output is correct |
62 |
Correct |
2573 ms |
182060 KB |
Output is correct |
63 |
Correct |
1688 ms |
178776 KB |
Output is correct |
64 |
Correct |
1694 ms |
178768 KB |
Output is correct |
65 |
Correct |
1953 ms |
181844 KB |
Output is correct |
66 |
Correct |
1952 ms |
181792 KB |
Output is correct |
67 |
Correct |
1962 ms |
182220 KB |
Output is correct |
68 |
Correct |
2037 ms |
183496 KB |
Output is correct |
69 |
Correct |
2049 ms |
183404 KB |
Output is correct |
70 |
Correct |
2037 ms |
183264 KB |
Output is correct |
71 |
Correct |
2035 ms |
183156 KB |
Output is correct |
72 |
Correct |
2039 ms |
183124 KB |
Output is correct |
73 |
Correct |
1664 ms |
174608 KB |
Output is correct |
74 |
Correct |
1670 ms |
175724 KB |
Output is correct |
75 |
Correct |
1664 ms |
174492 KB |
Output is correct |
76 |
Correct |
1660 ms |
174856 KB |
Output is correct |
77 |
Correct |
1654 ms |
174436 KB |
Output is correct |
78 |
Correct |
2127 ms |
175644 KB |
Output is correct |
79 |
Correct |
1260 ms |
120080 KB |
Output is correct |
80 |
Correct |
2302 ms |
172776 KB |
Output is correct |