#include <bits/stdc++.h>
#pragma GCC optimization("g", on)
#pragma GCC optimize ("inline")
#pragma GCC optimization("03")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N = 1e6 + 5;
const int inf = 1e9 + 7;
//const int k = 1e3;
int n, m, a[N], mx[N], mn[N], ans[N], x, l, r, q, bl[N], br[N], k;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
k = sqrt(n);
for(int i = 1; i <= n; ++i){
mn[i / k] = inf;
}
for(int i = 1; i <= n; ++i){
cin >> a[i];
if(mx[i / k] == 0) {bl[i / k] = i; br[(i - 1) / k] = i - 1;}
mx[i / k] = max(mx[i / k], a[i]);
mn[i / k] = min(mn[i / k], a[i]);
if(mx[i / k] > a[i]){
ans[i / k] = max(ans[i / k], mx[i / k] - a[i]);
}
}
while(m--){
cin >> l >> r >> q;
bool ok = 1;
x = 0;
for(int i = l; i <= br[l / k]; ++i){
x = max(x, a[i]);
if(x - a[i] > q) ok = 0;
}
if(!ok) {cout << ok << '\n'; continue;}
for(int i = (l / k) + 1; i <= (r / k - 1); ++i){
if(ans[i] > q) ok = 0;
if(x - mn[i] > q) ok = 0;
x = max(x, mx[i]);
}
if(!ok) {cout << ok << '\n'; continue;}
for(int i = bl[r / k]; i <= r; ++i){
if(x - a[i] > q) ok = 0;
x = max(x, a[i]);
}
cout << ok << '\n';
}
return 0;
}
Compilation message
sortbooks.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization("g", on)
|
sortbooks.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
5 | #pragma GCC optimization("03")
|
sortbooks.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
6 | #pragma GCC optimization("unroll-loops")
|
sortbooks.cpp:7: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
7 | #pragma comment(linker, "/stack:200000000")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1160 ms |
6288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
80 ms |
836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |