#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forbn(i, b, n) for(int i = b; i < n; ++i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef complex<double> cd; // !!! long double slow
template <class T> inline void mineq(T &a, T b) { a = min(a, b); }
template <class T> inline void maxeq(T &a, T b) { a = max(a, b); }
int n, q;
const int INF = 1000 * 1000 * 1000 + 10;
const int MX = 2 * 1000 * 1000;
int ol[MX], oright[MX];
bool res[MX];
vi a;
bool cmp(int v1, int v2) {
return ol[v1] < ol[v2];
}
struct Seg {
int mx[MX], t[MX];
vi sl[MX];
vector<ii> rem[MX];
Seg(vi& a) {
forn(i, MX)
res[i] = true;
for(int p = n; p < 2 * n; p++) {
mx[p] = a[p - n];
sl[p].pb(a[p - n]);
t[p] = -INF;
oright[p] = ol[p] = p - n;
}
for(int p = n - 1; p > 0; p--) {
ol[p] = min(ol[2 * p], ol[2 * p + 1]);
oright[p] = max(oright[2 * p], oright[2 * p + 1]);
mx[p] = max(mx[2 * p], mx[2 * p + 1]);
t[p] = max(t[2 * p], t[2 * p + 1]);
merge(all(sl[2 * p]), all(sl[2 * p + 1]), back_inserter(sl[p]));
int ind = lower_bound(all(sl[2 * p + 1]), mx[2 * p]) - sl[2 * p + 1].begin();
if(ind != 0)
maxeq(t[p], mx[2 * p] + sl[2 * p + 1][ind - 1]);
}
forn(i, MX)
sl[i].clear();
}
void query(int l, int r, int k, int left_max, int qid) {
vi vert;
for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1) {
vert.pb(l++);
}
if (r & 1) {
vert.pb(--r);
}
}
sort(all(vert), cmp);
bool ans = true;
for(int v: vert) {
ans = ans && t[v] <= k;
int rp = left_max - 1, lp = k - left_max + 1;
if(lp <= rp) {
rem[v].pb({lp - 1, qid});
rem[v].pb({rp, qid});
}
maxeq(left_max, mx[v]);
}
res[qid] = ans;
}
void process() {
for(int v = 1; v < 2 * n; v++) {
sort(all(rem[v]));
vi slv;
for(int j = ol[v]; j <= oright[v]; j++)
slv.pb(a[j]);
sort(all(slv));
set<int> act;
int i = 0;
for(ii p: rem[v]) {
int qid = p.S;
if(res[qid] == false)
continue;
int en = p.F;
if(i < sz(slv) && slv[i] <= en) {
for(int qid_act: act) {
res[qid_act] = false;
}
act.clear();
}
while(i < sz(slv) && slv[i] <= en)
i += 1;
if(act.find(qid) == act.end()) {
act.insert(qid);
}
else {
act.erase(qid);
}
}
rem[v].clear();
}
}
};
void solve() {
cin >> n >> q;
a.resize(n);
forn(i, n)
cin >> a[i];
Seg seg(a);
int qq = q / 4;
forn(qid, q) {
int l, r, k;
cin >> l >> r >> k;
l--; r--;
seg.query(l, r, k, -INF, qid);
if(qid == qq || qid == 2 * qq || qid == 3 * qq) {
seg.process();
}
}
seg.process();
forn(qid, q) {
cout << res[qid] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// freopen("boards.in", "r", stdin);
// freopen("boards.out", "w", stdout);
int t = 1;
// cin >> t;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
111824 KB |
Output is correct |
2 |
Correct |
72 ms |
111816 KB |
Output is correct |
3 |
Correct |
74 ms |
111864 KB |
Output is correct |
4 |
Correct |
73 ms |
111812 KB |
Output is correct |
5 |
Correct |
68 ms |
111868 KB |
Output is correct |
6 |
Correct |
72 ms |
111912 KB |
Output is correct |
7 |
Correct |
68 ms |
111900 KB |
Output is correct |
8 |
Correct |
70 ms |
111952 KB |
Output is correct |
9 |
Correct |
75 ms |
111816 KB |
Output is correct |
10 |
Correct |
76 ms |
112036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
111824 KB |
Output is correct |
2 |
Correct |
72 ms |
111816 KB |
Output is correct |
3 |
Correct |
74 ms |
111864 KB |
Output is correct |
4 |
Correct |
73 ms |
111812 KB |
Output is correct |
5 |
Correct |
68 ms |
111868 KB |
Output is correct |
6 |
Correct |
72 ms |
111912 KB |
Output is correct |
7 |
Correct |
68 ms |
111900 KB |
Output is correct |
8 |
Correct |
70 ms |
111952 KB |
Output is correct |
9 |
Correct |
75 ms |
111816 KB |
Output is correct |
10 |
Correct |
76 ms |
112036 KB |
Output is correct |
11 |
Correct |
81 ms |
112204 KB |
Output is correct |
12 |
Correct |
96 ms |
112684 KB |
Output is correct |
13 |
Correct |
97 ms |
112812 KB |
Output is correct |
14 |
Correct |
99 ms |
112972 KB |
Output is correct |
15 |
Correct |
110 ms |
113068 KB |
Output is correct |
16 |
Correct |
90 ms |
112588 KB |
Output is correct |
17 |
Correct |
83 ms |
112336 KB |
Output is correct |
18 |
Correct |
80 ms |
112712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
488 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
873 ms |
134644 KB |
Output is correct |
2 |
Correct |
837 ms |
133936 KB |
Output is correct |
3 |
Correct |
563 ms |
132108 KB |
Output is correct |
4 |
Correct |
573 ms |
132364 KB |
Output is correct |
5 |
Correct |
561 ms |
132184 KB |
Output is correct |
6 |
Correct |
468 ms |
129540 KB |
Output is correct |
7 |
Correct |
439 ms |
129600 KB |
Output is correct |
8 |
Correct |
467 ms |
131092 KB |
Output is correct |
9 |
Correct |
116 ms |
112048 KB |
Output is correct |
10 |
Correct |
432 ms |
130564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
111824 KB |
Output is correct |
2 |
Correct |
72 ms |
111816 KB |
Output is correct |
3 |
Correct |
74 ms |
111864 KB |
Output is correct |
4 |
Correct |
73 ms |
111812 KB |
Output is correct |
5 |
Correct |
68 ms |
111868 KB |
Output is correct |
6 |
Correct |
72 ms |
111912 KB |
Output is correct |
7 |
Correct |
68 ms |
111900 KB |
Output is correct |
8 |
Correct |
70 ms |
111952 KB |
Output is correct |
9 |
Correct |
75 ms |
111816 KB |
Output is correct |
10 |
Correct |
76 ms |
112036 KB |
Output is correct |
11 |
Correct |
81 ms |
112204 KB |
Output is correct |
12 |
Correct |
96 ms |
112684 KB |
Output is correct |
13 |
Correct |
97 ms |
112812 KB |
Output is correct |
14 |
Correct |
99 ms |
112972 KB |
Output is correct |
15 |
Correct |
110 ms |
113068 KB |
Output is correct |
16 |
Correct |
90 ms |
112588 KB |
Output is correct |
17 |
Correct |
83 ms |
112336 KB |
Output is correct |
18 |
Correct |
80 ms |
112712 KB |
Output is correct |
19 |
Correct |
2152 ms |
160744 KB |
Output is correct |
20 |
Correct |
2069 ms |
160880 KB |
Output is correct |
21 |
Correct |
2020 ms |
157348 KB |
Output is correct |
22 |
Correct |
2013 ms |
157388 KB |
Output is correct |
23 |
Correct |
2100 ms |
157232 KB |
Output is correct |
24 |
Correct |
1229 ms |
149960 KB |
Output is correct |
25 |
Correct |
1275 ms |
149864 KB |
Output is correct |
26 |
Correct |
1287 ms |
153332 KB |
Output is correct |
27 |
Correct |
1495 ms |
153548 KB |
Output is correct |
28 |
Correct |
1494 ms |
154396 KB |
Output is correct |
29 |
Correct |
1431 ms |
155912 KB |
Output is correct |
30 |
Correct |
1371 ms |
155812 KB |
Output is correct |
31 |
Correct |
1411 ms |
155988 KB |
Output is correct |
32 |
Correct |
1385 ms |
156044 KB |
Output is correct |
33 |
Correct |
1307 ms |
156048 KB |
Output is correct |
34 |
Correct |
1073 ms |
148656 KB |
Output is correct |
35 |
Correct |
1046 ms |
148660 KB |
Output is correct |
36 |
Correct |
1088 ms |
148752 KB |
Output is correct |
37 |
Correct |
1065 ms |
148704 KB |
Output is correct |
38 |
Correct |
1118 ms |
148660 KB |
Output is correct |
39 |
Correct |
1288 ms |
149596 KB |
Output is correct |
40 |
Correct |
477 ms |
130916 KB |
Output is correct |
41 |
Correct |
951 ms |
150080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
111824 KB |
Output is correct |
2 |
Correct |
72 ms |
111816 KB |
Output is correct |
3 |
Correct |
74 ms |
111864 KB |
Output is correct |
4 |
Correct |
73 ms |
111812 KB |
Output is correct |
5 |
Correct |
68 ms |
111868 KB |
Output is correct |
6 |
Correct |
72 ms |
111912 KB |
Output is correct |
7 |
Correct |
68 ms |
111900 KB |
Output is correct |
8 |
Correct |
70 ms |
111952 KB |
Output is correct |
9 |
Correct |
75 ms |
111816 KB |
Output is correct |
10 |
Correct |
76 ms |
112036 KB |
Output is correct |
11 |
Correct |
81 ms |
112204 KB |
Output is correct |
12 |
Correct |
96 ms |
112684 KB |
Output is correct |
13 |
Correct |
97 ms |
112812 KB |
Output is correct |
14 |
Correct |
99 ms |
112972 KB |
Output is correct |
15 |
Correct |
110 ms |
113068 KB |
Output is correct |
16 |
Correct |
90 ms |
112588 KB |
Output is correct |
17 |
Correct |
83 ms |
112336 KB |
Output is correct |
18 |
Correct |
80 ms |
112712 KB |
Output is correct |
19 |
Runtime error |
488 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |