#include <bits/stdc++.h>
#define ll unsigned long long
#define pii pair<ll, int>
using namespace std;
const int MAX = (1 << 20);
int tree[MAX * 2];
int ask(int ql, int qr, int node = 1, int l = 1, int r = MAX){
if(ql > r || qr < l) return 0;
if(ql <= l && r <= qr) return tree[node];
int mid = (l + r) / 2;
return max(ask(ql, qr, node * 2, l, mid), ask(ql, qr, node * 2 + 1, mid + 1, r));
}
void update(int pos, int val, int node = 1, int l = 1, int r = MAX){
if(l == r){
tree[node] = val;
return;
}
int mid = (l + r) / 2;
if(pos <= mid){
return update(pos, val, node * 2, l, mid);
}
else{
return update(pos, val, node * 2 + 1, mid + 1, r);
}
}
int n, m;
vector<array<int, 3>> quer[MAX];
bool ans[MAX];
int arr[MAX];
int main(){
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
for (int i = 0; i < m; i++)
{
int l, r, k; cin >> l >> r >> k;
quer[r].push_back({l, k, i});
}
stack<pii> st;
for (int i = 1; i <= n; i++)
{
while(!st.empty() && st.top().first <= arr[i]){
st.pop();
}
if(st.size()){
update(st.top().second, arr[st.top().second] + arr[i]);
}
st.push({arr[i], i});
for(auto& q:quer[i]){
ans[q[2]] = ask(q[0], i) <= q[1];
}
}
for (int i = 0; i < m; i++)
{
cout << ans[i] << '\n';
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:49:45: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
49 | while(!st.empty() && st.top().first <= arr[i]){
| ~~~~~~~~~~~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
31092 KB |
Output is correct |
2 |
Correct |
5 ms |
29020 KB |
Output is correct |
3 |
Incorrect |
7 ms |
31184 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
31092 KB |
Output is correct |
2 |
Correct |
5 ms |
29020 KB |
Output is correct |
3 |
Incorrect |
7 ms |
31184 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1689 ms |
59632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
125 ms |
35676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
31092 KB |
Output is correct |
2 |
Correct |
5 ms |
29020 KB |
Output is correct |
3 |
Incorrect |
7 ms |
31184 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
31092 KB |
Output is correct |
2 |
Correct |
5 ms |
29020 KB |
Output is correct |
3 |
Incorrect |
7 ms |
31184 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |