#include "bits/stdc++.h"
using namespace std;
const int N = 1e6+6;
int arr[N], d[N], ans[N];
vector<int> queries[N];
int l[N], r[N], k[N], s[N<<2];
void upd(int p, int v, int nd, int x, int y){
if (x == y){
s[nd] = v;
return;
}
int mid = (x+y) >> 1;
if (p <= mid)
upd(p, v, nd<<1, x, mid);
else
upd(p, v, nd<<1|1, mid+1, y);
s[nd] = max(s[nd<<1], s[nd<<1|1]);
}
int tap(int l, int r, int nd, int x, int y){
if (l > y or x > r)
return 0;
if (l <= x and y <= r)
return s[nd];
int mid = (x+y) >> 1;
return max(tap(l, r, nd<<1, x, mid), tap(l, r, nd<<1|1, mid+1, y));
}
int main(){
// freopen("file.in", "r", stdin);
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", arr+i);
stack<int> st;
for (int i = 1; i <= n; i++){
while (!st.empty() and arr[st.top()] <= arr[i])
st.pop();
if (st.empty())
d[i] = -1;
else
d[i] = st.top();
st.push(i);
}
int q;
scanf("%d", &q);
for (int i = 1; i <= q; i++){
scanf("%d%d%d", l+i, r+i, k+i);
queries[r[i]].push_back(i);
}
for (int j = 1; j <= n; j++){
int i = d[j];
if (~i)
upd(i, arr[i]+arr[j], 1, 1, n);
for (auto ind: queries[j])
ans[ind] = tap(l[ind], r[ind], 1, 1, n) <= k[ind];
}
for (int i = 1; i <= q; i++)
printf("%d\n", ans[i]);
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
sortbooks.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d", arr+i);
| ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
sortbooks.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d%d%d", l+i, r+i, k+i);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Incorrect |
10 ms |
23900 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Incorrect |
10 ms |
23900 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
652 ms |
176216 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
26200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Incorrect |
10 ms |
23900 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Incorrect |
10 ms |
23900 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |