#include <bits/stdc++.h>
using namespace std;
template<class T, class U>
void ckmin(T &a, U b)
{
if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
if (a < b) a = b;
}
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 1000013
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef pair<pii, pii> ppp;
int N, Q;
int arr[MAXN];
int pos[MAXN];
vpi guys;
vector<ppp> quer;
vi upds[MAXN];
bitset<MAXN> ans;
int fen[MAXN];
void update(int idx, int v)
{
for (int e = idx + 1; e <= N; e += e & (-e)) ckmax(fen[e], v);
}
int query(int idx)
{
int res = 0;
for (int e = idx + 1; e; e -= e & (-e)) ckmax(res, fen[e]);
return res;
}
//max (a[i] + a[j]) such that a[i] > a[j]
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> Q;
FOR(i, 0, N)
{
cin >> arr[i];
}
FOR(i, 0, Q)
{
int l, r, v; cin >> l >> r >> v; l--; r--;
quer.PB({{l, r}, {v, i}});
}
guys.PB({1000000013, -1});
FOR(i, 0, N)
{
while(guys.back().fi <= arr[i])
{
guys.pop_back();
}
pos[i] = guys.back().se;
guys.PB({arr[i], i});
upds[pos[i]].PB(i);
}
sort(ALL(quer));
int iter = Q - 1;
FORD(i, N, 0)
{
for (int x : upds[i])
{
update(x, arr[i] + arr[x]);
}
while(iter >= 0 && quer[iter].fi.fi == i)
{
int l = quer[iter].fi.fi, r = quer[iter].fi.se, v = quer[iter].se.fi, qid = quer[iter].se.se;
ans[qid] = (query(r) > v);
// cerr << qid << ',' << query(r) << endl;
iter--;
}
}
//find the first guy > x on left.
//left, right, value, qid;
FOR(i, 0, Q)
{
cout << (ans[i] ? 0 : 1) << '\n';
}
}
Compilation message
sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:94:8: warning: unused variable 'l' [-Wunused-variable]
int l = quer[iter].fi.fi, r = quer[iter].fi.se, v = quer[iter].se.fi, qid = quer[iter].se.se;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
23 ms |
23800 KB |
Output is correct |
3 |
Correct |
28 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
27 ms |
23928 KB |
Output is correct |
7 |
Correct |
28 ms |
23928 KB |
Output is correct |
8 |
Correct |
31 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
27 ms |
23928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
23 ms |
23800 KB |
Output is correct |
3 |
Correct |
28 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
27 ms |
23928 KB |
Output is correct |
7 |
Correct |
28 ms |
23928 KB |
Output is correct |
8 |
Correct |
31 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
27 ms |
23928 KB |
Output is correct |
11 |
Correct |
28 ms |
24184 KB |
Output is correct |
12 |
Correct |
30 ms |
24184 KB |
Output is correct |
13 |
Correct |
32 ms |
24316 KB |
Output is correct |
14 |
Correct |
28 ms |
24312 KB |
Output is correct |
15 |
Correct |
27 ms |
24312 KB |
Output is correct |
16 |
Correct |
27 ms |
24280 KB |
Output is correct |
17 |
Correct |
25 ms |
24184 KB |
Output is correct |
18 |
Correct |
26 ms |
24184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
959 ms |
69696 KB |
Output is correct |
2 |
Correct |
953 ms |
73900 KB |
Output is correct |
3 |
Correct |
945 ms |
73952 KB |
Output is correct |
4 |
Correct |
935 ms |
73884 KB |
Output is correct |
5 |
Correct |
820 ms |
61888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
28468 KB |
Output is correct |
2 |
Correct |
102 ms |
30436 KB |
Output is correct |
3 |
Correct |
89 ms |
29288 KB |
Output is correct |
4 |
Correct |
88 ms |
29288 KB |
Output is correct |
5 |
Correct |
95 ms |
29272 KB |
Output is correct |
6 |
Correct |
88 ms |
29160 KB |
Output is correct |
7 |
Correct |
92 ms |
29328 KB |
Output is correct |
8 |
Correct |
86 ms |
28904 KB |
Output is correct |
9 |
Correct |
75 ms |
27112 KB |
Output is correct |
10 |
Correct |
90 ms |
28868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
23 ms |
23800 KB |
Output is correct |
3 |
Correct |
28 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
27 ms |
23928 KB |
Output is correct |
7 |
Correct |
28 ms |
23928 KB |
Output is correct |
8 |
Correct |
31 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
27 ms |
23928 KB |
Output is correct |
11 |
Correct |
28 ms |
24184 KB |
Output is correct |
12 |
Correct |
30 ms |
24184 KB |
Output is correct |
13 |
Correct |
32 ms |
24316 KB |
Output is correct |
14 |
Correct |
28 ms |
24312 KB |
Output is correct |
15 |
Correct |
27 ms |
24312 KB |
Output is correct |
16 |
Correct |
27 ms |
24280 KB |
Output is correct |
17 |
Correct |
25 ms |
24184 KB |
Output is correct |
18 |
Correct |
26 ms |
24184 KB |
Output is correct |
19 |
Correct |
209 ms |
39636 KB |
Output is correct |
20 |
Correct |
209 ms |
39708 KB |
Output is correct |
21 |
Correct |
203 ms |
39484 KB |
Output is correct |
22 |
Correct |
202 ms |
39424 KB |
Output is correct |
23 |
Correct |
207 ms |
39392 KB |
Output is correct |
24 |
Correct |
182 ms |
37160 KB |
Output is correct |
25 |
Correct |
177 ms |
37092 KB |
Output is correct |
26 |
Correct |
181 ms |
37300 KB |
Output is correct |
27 |
Correct |
181 ms |
37376 KB |
Output is correct |
28 |
Correct |
182 ms |
37272 KB |
Output is correct |
29 |
Correct |
191 ms |
37424 KB |
Output is correct |
30 |
Correct |
183 ms |
37320 KB |
Output is correct |
31 |
Correct |
182 ms |
37496 KB |
Output is correct |
32 |
Correct |
182 ms |
37344 KB |
Output is correct |
33 |
Correct |
188 ms |
37416 KB |
Output is correct |
34 |
Correct |
186 ms |
37020 KB |
Output is correct |
35 |
Correct |
187 ms |
37084 KB |
Output is correct |
36 |
Correct |
194 ms |
36968 KB |
Output is correct |
37 |
Correct |
185 ms |
36832 KB |
Output is correct |
38 |
Correct |
188 ms |
37220 KB |
Output is correct |
39 |
Correct |
187 ms |
36576 KB |
Output is correct |
40 |
Correct |
160 ms |
34056 KB |
Output is correct |
41 |
Correct |
175 ms |
35536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
23928 KB |
Output is correct |
2 |
Correct |
23 ms |
23800 KB |
Output is correct |
3 |
Correct |
28 ms |
23800 KB |
Output is correct |
4 |
Correct |
23 ms |
23800 KB |
Output is correct |
5 |
Correct |
23 ms |
23928 KB |
Output is correct |
6 |
Correct |
27 ms |
23928 KB |
Output is correct |
7 |
Correct |
28 ms |
23928 KB |
Output is correct |
8 |
Correct |
31 ms |
23928 KB |
Output is correct |
9 |
Correct |
24 ms |
23800 KB |
Output is correct |
10 |
Correct |
27 ms |
23928 KB |
Output is correct |
11 |
Correct |
28 ms |
24184 KB |
Output is correct |
12 |
Correct |
30 ms |
24184 KB |
Output is correct |
13 |
Correct |
32 ms |
24316 KB |
Output is correct |
14 |
Correct |
28 ms |
24312 KB |
Output is correct |
15 |
Correct |
27 ms |
24312 KB |
Output is correct |
16 |
Correct |
27 ms |
24280 KB |
Output is correct |
17 |
Correct |
25 ms |
24184 KB |
Output is correct |
18 |
Correct |
26 ms |
24184 KB |
Output is correct |
19 |
Correct |
959 ms |
69696 KB |
Output is correct |
20 |
Correct |
953 ms |
73900 KB |
Output is correct |
21 |
Correct |
945 ms |
73952 KB |
Output is correct |
22 |
Correct |
935 ms |
73884 KB |
Output is correct |
23 |
Correct |
820 ms |
61888 KB |
Output is correct |
24 |
Correct |
100 ms |
28468 KB |
Output is correct |
25 |
Correct |
102 ms |
30436 KB |
Output is correct |
26 |
Correct |
89 ms |
29288 KB |
Output is correct |
27 |
Correct |
88 ms |
29288 KB |
Output is correct |
28 |
Correct |
95 ms |
29272 KB |
Output is correct |
29 |
Correct |
88 ms |
29160 KB |
Output is correct |
30 |
Correct |
92 ms |
29328 KB |
Output is correct |
31 |
Correct |
86 ms |
28904 KB |
Output is correct |
32 |
Correct |
75 ms |
27112 KB |
Output is correct |
33 |
Correct |
90 ms |
28868 KB |
Output is correct |
34 |
Correct |
209 ms |
39636 KB |
Output is correct |
35 |
Correct |
209 ms |
39708 KB |
Output is correct |
36 |
Correct |
203 ms |
39484 KB |
Output is correct |
37 |
Correct |
202 ms |
39424 KB |
Output is correct |
38 |
Correct |
207 ms |
39392 KB |
Output is correct |
39 |
Correct |
182 ms |
37160 KB |
Output is correct |
40 |
Correct |
177 ms |
37092 KB |
Output is correct |
41 |
Correct |
181 ms |
37300 KB |
Output is correct |
42 |
Correct |
181 ms |
37376 KB |
Output is correct |
43 |
Correct |
182 ms |
37272 KB |
Output is correct |
44 |
Correct |
191 ms |
37424 KB |
Output is correct |
45 |
Correct |
183 ms |
37320 KB |
Output is correct |
46 |
Correct |
182 ms |
37496 KB |
Output is correct |
47 |
Correct |
182 ms |
37344 KB |
Output is correct |
48 |
Correct |
188 ms |
37416 KB |
Output is correct |
49 |
Correct |
186 ms |
37020 KB |
Output is correct |
50 |
Correct |
187 ms |
37084 KB |
Output is correct |
51 |
Correct |
194 ms |
36968 KB |
Output is correct |
52 |
Correct |
185 ms |
36832 KB |
Output is correct |
53 |
Correct |
188 ms |
37220 KB |
Output is correct |
54 |
Correct |
187 ms |
36576 KB |
Output is correct |
55 |
Correct |
160 ms |
34056 KB |
Output is correct |
56 |
Correct |
175 ms |
35536 KB |
Output is correct |
57 |
Correct |
958 ms |
103264 KB |
Output is correct |
58 |
Correct |
956 ms |
103196 KB |
Output is correct |
59 |
Correct |
954 ms |
103136 KB |
Output is correct |
60 |
Correct |
963 ms |
103144 KB |
Output is correct |
61 |
Correct |
969 ms |
103140 KB |
Output is correct |
62 |
Correct |
987 ms |
103156 KB |
Output is correct |
63 |
Correct |
828 ms |
89120 KB |
Output is correct |
64 |
Correct |
809 ms |
89124 KB |
Output is correct |
65 |
Correct |
864 ms |
91084 KB |
Output is correct |
66 |
Correct |
861 ms |
91072 KB |
Output is correct |
67 |
Correct |
828 ms |
91000 KB |
Output is correct |
68 |
Correct |
827 ms |
90988 KB |
Output is correct |
69 |
Correct |
842 ms |
91200 KB |
Output is correct |
70 |
Correct |
835 ms |
91276 KB |
Output is correct |
71 |
Correct |
847 ms |
91052 KB |
Output is correct |
72 |
Correct |
884 ms |
91020 KB |
Output is correct |
73 |
Correct |
835 ms |
87604 KB |
Output is correct |
74 |
Correct |
884 ms |
88676 KB |
Output is correct |
75 |
Correct |
821 ms |
87536 KB |
Output is correct |
76 |
Correct |
818 ms |
87692 KB |
Output is correct |
77 |
Correct |
797 ms |
87560 KB |
Output is correct |
78 |
Correct |
822 ms |
88268 KB |
Output is correct |
79 |
Correct |
723 ms |
73024 KB |
Output is correct |
80 |
Correct |
762 ms |
81852 KB |
Output is correct |