#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, q, A[1000005];
struct node{
int s, e, m, val, lz;
node *l, *r;
node(int _s, int _e){
s = _s, e = _e, m = (s + e) >> 1;
if(s != e)l = new node(s, m), r = new node(m+1, e);
lz = val = 0;
}
void prop(){
if(lz){
val = lz;
if(s != e)l->lz = lz, r->lz = lz;
lz = 0;
}
}
void upd(int a, int b, int c){
prop();
if(a == s && b == e)lz = c;
else{
if(b <= m)l->upd(a, b, c);
else if(a > m)r->upd(a, b, c);
else l->upd(a, m, c), r->upd(m+1, b, c);
l->prop(), r->prop();
val = max(l->val, r->val);
}
}
int qry(int x){
prop();
if(s == e)return (val >= x ? s : 0);
if(r->val >= x)return r->qry(x);
else return l->qry(x);
}
int qval(int x){
prop();
if(s == e)return val;
if(x <= m)return l->qval(x);
return r->qval(x);
}
}*root;
int ans[1000005];
vector <pii> Q[1000005];
void solve(){
cin >> n >> q;
for(int i=1;i<=n;i++)cin >> A[i];
root = new node(1, n);
stack <int> s;
for(int i=1;i<=q;i++){
int l, r, k;
cin >> l >> r >> k;
Q[r].push_back({l, {k, i}});
}
for(int i=1;i<=n;i++){
while(!s.empty() && A[s.top()] <= A[i])s.pop();
if(!s.empty()){
int x = s.top();
int tmp = root->qry(A[x] + A[i]);
if(tmp + 1 <= x)root->upd(tmp + 1, x, A[x] + A[i]);
}
s.push(i);
for(auto j : Q[i]){
ans[j.se.se] = (root->qval(j.fi) <= j.se.fi);
}
}
for(int i=1;i<=q;i++)cout << ans[i] << '\n';
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message
sortbooks.cpp:88:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
88 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
29276 KB |
Output is correct |
2 |
Correct |
10 ms |
29276 KB |
Output is correct |
3 |
Correct |
10 ms |
29272 KB |
Output is correct |
4 |
Incorrect |
9 ms |
29276 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
29276 KB |
Output is correct |
2 |
Correct |
10 ms |
29276 KB |
Output is correct |
3 |
Correct |
10 ms |
29272 KB |
Output is correct |
4 |
Incorrect |
9 ms |
29276 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2484 ms |
199080 KB |
Output is correct |
2 |
Correct |
2547 ms |
215740 KB |
Output is correct |
3 |
Correct |
2507 ms |
215720 KB |
Output is correct |
4 |
Correct |
2491 ms |
215716 KB |
Output is correct |
5 |
Correct |
2005 ms |
215744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
145 ms |
45276 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
29276 KB |
Output is correct |
2 |
Correct |
10 ms |
29276 KB |
Output is correct |
3 |
Correct |
10 ms |
29272 KB |
Output is correct |
4 |
Incorrect |
9 ms |
29276 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
29276 KB |
Output is correct |
2 |
Correct |
10 ms |
29276 KB |
Output is correct |
3 |
Correct |
10 ms |
29272 KB |
Output is correct |
4 |
Incorrect |
9 ms |
29276 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |