#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e4+7;
const int nax = 1e6+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
int st[nax*4];
void update(int v, int l, int r, int pos, int val){
if(l > pos || r < pos) return;
if(l == r){
st[v] = val;
return;
}
int md = (l+r)/2;
update(v*2,l,md,pos,val);
update(v*2+1,md+1,r,pos,val);
st[v] = max(st[v*2], st[v*2+1]);
}
int query(int v, int l, int r, int i, int j){
if(l > j || r < i) return 0;
if(i <= l && r <= j) return st[v];
int md = (l+r)/2;
return max(query(v*2,l,md,i,j), query(v*2+1, md+1, r, i, j));
}
int main(){
optimise;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
while(t--){
int n,q;
cin >> n >> q;
vi s(n),l(q), r(q), k(q), ans(q);
vvi qrs(n);
for (int i = 0; i < n; ++i)
{
cin >> s[i];
}
for (int i = 0; i < q; ++i)
{
cin >> l[i] >> r[i] >> k[i];
l[i]--,r[i]--;
qrs[r[i]].pb(i);
}
stack<int> stck;
for (int i = 0; i < n; ++i)
{
while(!stck.empty() && s[stck.top()] <= s[i]){
stck.pop();
}
if(!stck.empty()) {
update(1,0,n-1, stck.top(), s[stck.top()]+s[i]);
}
stck.push(i);
for(auto x : qrs[i]){
ans[x] = (query(1,0,n-1,l[x],i) <= k[x]);
}
}
for (int i = 0; i < q; ++i)
{
cout << ans[i] << endl;
}
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
49 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
167304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
167304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
145 ms |
167376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
136 ms |
167292 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
167304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
167304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |