#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());
ll min(const ll &a, const ll &b){
return (a < b) ? a : b;
}
ll max(const ll &a, const ll &b){
return (a > b) ? a : b;
}
//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e6 + 1;
int n, qq;
int a[maxN];
struct TQuery{
int l, k, idx;
};
vector <TQuery> q[maxN];
int bit[maxN];
int ans[maxN];
void update(int x, int val){
for (; x; x -= x & -x){
bit[x] = max(bit[x], val);
}
}
int get(int x, int val){
int res = 0;
for (; x <= n; x += x & -x){
res = max(res, bit[x]);
}
return res;
}
void Init(){
cin >> n >> qq;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= qq; ++i){
int l, r, k;
cin >> l >> r >> k;
q[r].pb({l, k, i});
}
vector <int> S;
for (int i = 1; i <= n; ++i){
while (!S.empty() && a[S.back()] <= a[i]){
S.pop_back();
}
if (!S.empty()){
update(S.back(), a[i] + a[S.back()]);
}
S.pb(i);
for (auto &j: q[i]){
//from j -> i
if (get(j.l, i) <= j.k) ans[j.idx] = 1;
else ans[j.idx] = 0;
}
}
for (int i = 1; i <= qq; ++i) cout << ans[i] << "\n";
}
int main(){
if (fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
//freopen(taskname".out", "w", stdout);
}
faster;
ll tt = 1;
//cin >> tt;
while (tt--){
Init();
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23696 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23820 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
12 ms |
23792 KB |
Output is correct |
8 |
Correct |
12 ms |
23760 KB |
Output is correct |
9 |
Correct |
14 ms |
23848 KB |
Output is correct |
10 |
Correct |
13 ms |
23832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23696 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23820 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
12 ms |
23792 KB |
Output is correct |
8 |
Correct |
12 ms |
23760 KB |
Output is correct |
9 |
Correct |
14 ms |
23848 KB |
Output is correct |
10 |
Correct |
13 ms |
23832 KB |
Output is correct |
11 |
Correct |
14 ms |
23872 KB |
Output is correct |
12 |
Correct |
15 ms |
23892 KB |
Output is correct |
13 |
Correct |
17 ms |
23872 KB |
Output is correct |
14 |
Correct |
26 ms |
24012 KB |
Output is correct |
15 |
Correct |
19 ms |
23908 KB |
Output is correct |
16 |
Correct |
18 ms |
23892 KB |
Output is correct |
17 |
Correct |
16 ms |
23940 KB |
Output is correct |
18 |
Correct |
14 ms |
23972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
832 ms |
89008 KB |
Output is correct |
2 |
Correct |
837 ms |
92188 KB |
Output is correct |
3 |
Correct |
807 ms |
92012 KB |
Output is correct |
4 |
Correct |
798 ms |
92284 KB |
Output is correct |
5 |
Correct |
790 ms |
88252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
27256 KB |
Output is correct |
2 |
Correct |
57 ms |
27068 KB |
Output is correct |
3 |
Correct |
57 ms |
26824 KB |
Output is correct |
4 |
Correct |
56 ms |
26836 KB |
Output is correct |
5 |
Correct |
60 ms |
26804 KB |
Output is correct |
6 |
Correct |
67 ms |
26488 KB |
Output is correct |
7 |
Correct |
50 ms |
26508 KB |
Output is correct |
8 |
Correct |
55 ms |
26764 KB |
Output is correct |
9 |
Correct |
41 ms |
25856 KB |
Output is correct |
10 |
Correct |
58 ms |
26672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23696 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23820 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
12 ms |
23792 KB |
Output is correct |
8 |
Correct |
12 ms |
23760 KB |
Output is correct |
9 |
Correct |
14 ms |
23848 KB |
Output is correct |
10 |
Correct |
13 ms |
23832 KB |
Output is correct |
11 |
Correct |
14 ms |
23872 KB |
Output is correct |
12 |
Correct |
15 ms |
23892 KB |
Output is correct |
13 |
Correct |
17 ms |
23872 KB |
Output is correct |
14 |
Correct |
26 ms |
24012 KB |
Output is correct |
15 |
Correct |
19 ms |
23908 KB |
Output is correct |
16 |
Correct |
18 ms |
23892 KB |
Output is correct |
17 |
Correct |
16 ms |
23940 KB |
Output is correct |
18 |
Correct |
14 ms |
23972 KB |
Output is correct |
19 |
Correct |
150 ms |
30812 KB |
Output is correct |
20 |
Correct |
146 ms |
30864 KB |
Output is correct |
21 |
Correct |
116 ms |
30284 KB |
Output is correct |
22 |
Correct |
126 ms |
30268 KB |
Output is correct |
23 |
Correct |
129 ms |
30196 KB |
Output is correct |
24 |
Correct |
142 ms |
29428 KB |
Output is correct |
25 |
Correct |
106 ms |
29372 KB |
Output is correct |
26 |
Correct |
132 ms |
29632 KB |
Output is correct |
27 |
Correct |
131 ms |
29664 KB |
Output is correct |
28 |
Correct |
127 ms |
29644 KB |
Output is correct |
29 |
Correct |
133 ms |
29936 KB |
Output is correct |
30 |
Correct |
142 ms |
30044 KB |
Output is correct |
31 |
Correct |
142 ms |
29928 KB |
Output is correct |
32 |
Correct |
129 ms |
29892 KB |
Output is correct |
33 |
Correct |
133 ms |
29992 KB |
Output is correct |
34 |
Correct |
105 ms |
29132 KB |
Output is correct |
35 |
Correct |
104 ms |
29040 KB |
Output is correct |
36 |
Correct |
101 ms |
29120 KB |
Output is correct |
37 |
Correct |
101 ms |
29160 KB |
Output is correct |
38 |
Correct |
108 ms |
29176 KB |
Output is correct |
39 |
Correct |
118 ms |
29960 KB |
Output is correct |
40 |
Correct |
121 ms |
29060 KB |
Output is correct |
41 |
Correct |
115 ms |
29676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
15 ms |
23696 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23820 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23764 KB |
Output is correct |
7 |
Correct |
12 ms |
23792 KB |
Output is correct |
8 |
Correct |
12 ms |
23760 KB |
Output is correct |
9 |
Correct |
14 ms |
23848 KB |
Output is correct |
10 |
Correct |
13 ms |
23832 KB |
Output is correct |
11 |
Correct |
14 ms |
23872 KB |
Output is correct |
12 |
Correct |
15 ms |
23892 KB |
Output is correct |
13 |
Correct |
17 ms |
23872 KB |
Output is correct |
14 |
Correct |
26 ms |
24012 KB |
Output is correct |
15 |
Correct |
19 ms |
23908 KB |
Output is correct |
16 |
Correct |
18 ms |
23892 KB |
Output is correct |
17 |
Correct |
16 ms |
23940 KB |
Output is correct |
18 |
Correct |
14 ms |
23972 KB |
Output is correct |
19 |
Correct |
832 ms |
89008 KB |
Output is correct |
20 |
Correct |
837 ms |
92188 KB |
Output is correct |
21 |
Correct |
807 ms |
92012 KB |
Output is correct |
22 |
Correct |
798 ms |
92284 KB |
Output is correct |
23 |
Correct |
790 ms |
88252 KB |
Output is correct |
24 |
Correct |
63 ms |
27256 KB |
Output is correct |
25 |
Correct |
57 ms |
27068 KB |
Output is correct |
26 |
Correct |
57 ms |
26824 KB |
Output is correct |
27 |
Correct |
56 ms |
26836 KB |
Output is correct |
28 |
Correct |
60 ms |
26804 KB |
Output is correct |
29 |
Correct |
67 ms |
26488 KB |
Output is correct |
30 |
Correct |
50 ms |
26508 KB |
Output is correct |
31 |
Correct |
55 ms |
26764 KB |
Output is correct |
32 |
Correct |
41 ms |
25856 KB |
Output is correct |
33 |
Correct |
58 ms |
26672 KB |
Output is correct |
34 |
Correct |
150 ms |
30812 KB |
Output is correct |
35 |
Correct |
146 ms |
30864 KB |
Output is correct |
36 |
Correct |
116 ms |
30284 KB |
Output is correct |
37 |
Correct |
126 ms |
30268 KB |
Output is correct |
38 |
Correct |
129 ms |
30196 KB |
Output is correct |
39 |
Correct |
142 ms |
29428 KB |
Output is correct |
40 |
Correct |
106 ms |
29372 KB |
Output is correct |
41 |
Correct |
132 ms |
29632 KB |
Output is correct |
42 |
Correct |
131 ms |
29664 KB |
Output is correct |
43 |
Correct |
127 ms |
29644 KB |
Output is correct |
44 |
Correct |
133 ms |
29936 KB |
Output is correct |
45 |
Correct |
142 ms |
30044 KB |
Output is correct |
46 |
Correct |
142 ms |
29928 KB |
Output is correct |
47 |
Correct |
129 ms |
29892 KB |
Output is correct |
48 |
Correct |
133 ms |
29992 KB |
Output is correct |
49 |
Correct |
105 ms |
29132 KB |
Output is correct |
50 |
Correct |
104 ms |
29040 KB |
Output is correct |
51 |
Correct |
101 ms |
29120 KB |
Output is correct |
52 |
Correct |
101 ms |
29160 KB |
Output is correct |
53 |
Correct |
108 ms |
29176 KB |
Output is correct |
54 |
Correct |
118 ms |
29960 KB |
Output is correct |
55 |
Correct |
121 ms |
29060 KB |
Output is correct |
56 |
Correct |
115 ms |
29676 KB |
Output is correct |
57 |
Correct |
851 ms |
92372 KB |
Output is correct |
58 |
Correct |
837 ms |
92524 KB |
Output is correct |
59 |
Correct |
843 ms |
90728 KB |
Output is correct |
60 |
Correct |
770 ms |
90816 KB |
Output is correct |
61 |
Correct |
762 ms |
90772 KB |
Output is correct |
62 |
Correct |
786 ms |
90684 KB |
Output is correct |
63 |
Correct |
558 ms |
83768 KB |
Output is correct |
64 |
Correct |
514 ms |
83592 KB |
Output is correct |
65 |
Correct |
743 ms |
86724 KB |
Output is correct |
66 |
Correct |
732 ms |
86728 KB |
Output is correct |
67 |
Correct |
794 ms |
86784 KB |
Output is correct |
68 |
Correct |
798 ms |
88396 KB |
Output is correct |
69 |
Correct |
779 ms |
88596 KB |
Output is correct |
70 |
Correct |
817 ms |
88156 KB |
Output is correct |
71 |
Correct |
771 ms |
88184 KB |
Output is correct |
72 |
Correct |
823 ms |
88060 KB |
Output is correct |
73 |
Correct |
501 ms |
79564 KB |
Output is correct |
74 |
Correct |
514 ms |
80444 KB |
Output is correct |
75 |
Correct |
520 ms |
79640 KB |
Output is correct |
76 |
Correct |
493 ms |
79620 KB |
Output is correct |
77 |
Correct |
497 ms |
79360 KB |
Output is correct |
78 |
Correct |
746 ms |
81820 KB |
Output is correct |
79 |
Correct |
541 ms |
71612 KB |
Output is correct |
80 |
Correct |
708 ms |
77884 KB |
Output is correct |