#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define tp3 tuple<int, int, int>
const int N = 1e6, L = 20, inf = INT_MAX;
int n, m, mnA, mxK, a[N], b[N], mxL[N], lg[N+1], st[L][N], seg[N*4];
vector<int> lf[N];
vector<tp3> q[N];
bitset<N> vis, ans;
void build(int p=1, int l=0, int r=n-1) {
if (l == r) {
seg[p] = (b[l] == -1 ? 0 : (a[l] + a[b[l]]));
return;
}
int mid = (l+r) >> 1;
build(p << 1, l, mid);
build((p << 1) + 1, mid+1, r);
seg[p] = max(seg[p << 1], seg[(p << 1) + 1]);
}
void update(int x, int p=1, int l=0, int r=n-1) {
if (l == r) {
seg[p] = 0;
return;
}
int mid = (l+r) >> 1;
if (x <= mid) update(x, p << 1, l, mid);
else update(x, (p << 1) + 1, mid+1, r);
seg[p] = max(seg[p << 1], seg[(p << 1) + 1]);
}
int query(int x, int y, int p=1, int l=0, int r=n-1) {
if (x <= l && r <= y) {
return seg[p];
}
int mid = (l+r) >> 1;
if (y <= mid) {
return query(x, y, p << 1, l, mid);
}
else if(mid+1 <= x) {
return query(x, y, (p << 1) + 1, mid+1, r);
}
else {
return max(query(x, y, p << 1, l, mid), query(x, y, (p << 1) + 1, mid+1, r));
}
}
int querySt(int l, int r) {
int x = lg[r-l+1];
return max(st[x][l], st[x][r - (1 << x) + 1]);
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
memset(b, -1, sizeof(b));
lg[1] = 0;
for (int i = 2; i <= N; i++) {
lg[i] = lg[i >> 1] + 1;
}
cin >> n >> m;
mnA = inf;
for (int i = 0; i < n; i++) {
cin >> a[i];
mnA = min(mnA, a[i]);
st[0][i] = a[i];
}
mxK = -inf;
for (int i = 0; i < m; i++) {
int l, r, k;
cin >> l >> r >> k;
l--; r--;
mxK = max(mxK, k);
q[l].push_back(make_tuple(r, k, i));
}
if (mxK < mnA) {
int curr = 0;
mxL[0] = 0;
for (int i = 1; i < n; i++) {
if (a[i-1] > a[i]) {
curr = i;
}
mxL[i] = curr;
}
for (int l = 0; l < n; l++) {
for (auto& [r, k, idx] : q[l]) {
ans[idx] = (mxL[r] <= l);
}
}
}
else {
for (int j = 1; j < L; j++) {
for (int i = 0; i < n; i++) {
st[j][i] = max(st[j-1][i], st[j-1][i + (1 << (j-1))]);
}
}
for (int i = 0; i < n; i++) {
int l = -1;
int r = i-1;
while (l < r) {
int mid = (l+r+1)/2;
int x = querySt(mid, i-1);
if (x > a[i]) l = mid;
else r = mid-1;
}
if (l == -1 || vis[l]) continue;
vis[l] = 1;
b[i] = l;
lf[l].push_back(i);
}
build();
for (int l = 0; l < n; l++) {
for (auto& [r, k, idx] : q[l]) {
ans[idx] = (query(l, r) <= k);
}
for (int& i : lf[l]) {
update(i);
}
}
}
for (int i = 0; i < m; i++) {
cout << ans[i] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
100952 KB |
Output is correct |
2 |
Correct |
19 ms |
100956 KB |
Output is correct |
3 |
Incorrect |
20 ms |
100944 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
100952 KB |
Output is correct |
2 |
Correct |
19 ms |
100956 KB |
Output is correct |
3 |
Incorrect |
20 ms |
100944 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
603 ms |
94772 KB |
Output is correct |
2 |
Correct |
550 ms |
94776 KB |
Output is correct |
3 |
Correct |
551 ms |
94548 KB |
Output is correct |
4 |
Correct |
540 ms |
94548 KB |
Output is correct |
5 |
Correct |
543 ms |
94584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
88 ms |
117328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
100952 KB |
Output is correct |
2 |
Correct |
19 ms |
100956 KB |
Output is correct |
3 |
Incorrect |
20 ms |
100944 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
100952 KB |
Output is correct |
2 |
Correct |
19 ms |
100956 KB |
Output is correct |
3 |
Incorrect |
20 ms |
100944 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |