#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const int N = 1e6 + 69;
const int INF = 1e9 + 69;
int a[N];
vector<array<int, 3>> query[N];
int ans[N];
struct SegmentTree{
int n;
vector<int> a;
vector<int> lazy;
SegmentTree(int _n){
n = _n;
a.resize(n * 4); lazy.resize(n * 4);
}
void down(int id){
for(int i = id * 2; i <= id * 2 + 1; ++i) {
lazy[i] += lazy[id];
a[i] += lazy[id];
}
lazy[id] = 0;
}
void update(int u, int v, int val, int l, int r, int id){
if (u <= l && r <= v){
a[id] += val;
lazy[id] += val;
return;
}
down(id);
int mid = (l + r) >> 1;
if (u <= mid) update(u, v, val, l, mid, id * 2);
if (v > mid) update(u, v, val, mid + 1, r, id * 2 + 1);
a[id] = max(a[id * 2], a[id * 2 + 1]);
}
void update(int u, int v, int val){if (u <= v) update(u, v, val, 1, n, 1);}
int get(int u, int v, int l, int r, int id){
if (u <= l && r <= v) return a[id];
down(id);
int mid = (l + r) >> 1;
int ans = 0;
if (u <= mid) maximize(ans, get(u, v, l, mid, id * 2));
if (v > mid) maximize(ans, get(u, v, mid + 1, r, id * 2 + 1));
return ans;
}
int get(int u, int v){return get(u, v, 1, n, 1);}
};
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m; cin >> n >> m;
for(int i = 1; i<=n; ++i) cin >> a[i];
for(int i =0; i<m; ++i){
int l, r, k; cin >> l >> r >> k;
query[l].push_back({{r, k, i}});
}
a[n+1] = INF;
deque<int> st; st.push_back(n+1);
SegmentTree segg(n);
for(int i = n; i>=1; --i){
while(a[st.back()] < a[i]) {
int j = st.back();
st.pop_back();
int k = st.back();
segg.update(j, j, a[j]);
segg.update(j + 1, k-1, -a[j]);
}
int j = st.back();
st.push_back(i);
segg.update(i + 1, j - 1, a[i]);
for(auto j: query[i]){
ans[j[2]] = (segg.get(i, j[0]) <= j[1]);
}
}
for(int i = 0; i<m; ++i){
cout << ans[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23896 KB |
Output is correct |
2 |
Correct |
14 ms |
23900 KB |
Output is correct |
3 |
Correct |
17 ms |
23972 KB |
Output is correct |
4 |
Correct |
16 ms |
23900 KB |
Output is correct |
5 |
Correct |
14 ms |
23896 KB |
Output is correct |
6 |
Correct |
16 ms |
23828 KB |
Output is correct |
7 |
Correct |
17 ms |
23900 KB |
Output is correct |
8 |
Correct |
16 ms |
23896 KB |
Output is correct |
9 |
Correct |
15 ms |
23900 KB |
Output is correct |
10 |
Correct |
14 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23896 KB |
Output is correct |
2 |
Correct |
14 ms |
23900 KB |
Output is correct |
3 |
Correct |
17 ms |
23972 KB |
Output is correct |
4 |
Correct |
16 ms |
23900 KB |
Output is correct |
5 |
Correct |
14 ms |
23896 KB |
Output is correct |
6 |
Correct |
16 ms |
23828 KB |
Output is correct |
7 |
Correct |
17 ms |
23900 KB |
Output is correct |
8 |
Correct |
16 ms |
23896 KB |
Output is correct |
9 |
Correct |
15 ms |
23900 KB |
Output is correct |
10 |
Correct |
14 ms |
23900 KB |
Output is correct |
11 |
Correct |
19 ms |
23976 KB |
Output is correct |
12 |
Correct |
19 ms |
24228 KB |
Output is correct |
13 |
Correct |
19 ms |
24152 KB |
Output is correct |
14 |
Correct |
15 ms |
24412 KB |
Output is correct |
15 |
Correct |
19 ms |
24412 KB |
Output is correct |
16 |
Correct |
21 ms |
24348 KB |
Output is correct |
17 |
Correct |
19 ms |
24152 KB |
Output is correct |
18 |
Correct |
19 ms |
24156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1897 ms |
118596 KB |
Output is correct |
2 |
Correct |
1911 ms |
119640 KB |
Output is correct |
3 |
Correct |
1936 ms |
119388 KB |
Output is correct |
4 |
Correct |
1877 ms |
119528 KB |
Output is correct |
5 |
Correct |
1398 ms |
123724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
32080 KB |
Output is correct |
2 |
Correct |
117 ms |
31892 KB |
Output is correct |
3 |
Correct |
94 ms |
32336 KB |
Output is correct |
4 |
Correct |
94 ms |
32584 KB |
Output is correct |
5 |
Correct |
97 ms |
32664 KB |
Output is correct |
6 |
Correct |
93 ms |
31700 KB |
Output is correct |
7 |
Correct |
73 ms |
31828 KB |
Output is correct |
8 |
Correct |
82 ms |
31556 KB |
Output is correct |
9 |
Correct |
41 ms |
27144 KB |
Output is correct |
10 |
Correct |
80 ms |
31752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23896 KB |
Output is correct |
2 |
Correct |
14 ms |
23900 KB |
Output is correct |
3 |
Correct |
17 ms |
23972 KB |
Output is correct |
4 |
Correct |
16 ms |
23900 KB |
Output is correct |
5 |
Correct |
14 ms |
23896 KB |
Output is correct |
6 |
Correct |
16 ms |
23828 KB |
Output is correct |
7 |
Correct |
17 ms |
23900 KB |
Output is correct |
8 |
Correct |
16 ms |
23896 KB |
Output is correct |
9 |
Correct |
15 ms |
23900 KB |
Output is correct |
10 |
Correct |
14 ms |
23900 KB |
Output is correct |
11 |
Correct |
19 ms |
23976 KB |
Output is correct |
12 |
Correct |
19 ms |
24228 KB |
Output is correct |
13 |
Correct |
19 ms |
24152 KB |
Output is correct |
14 |
Correct |
15 ms |
24412 KB |
Output is correct |
15 |
Correct |
19 ms |
24412 KB |
Output is correct |
16 |
Correct |
21 ms |
24348 KB |
Output is correct |
17 |
Correct |
19 ms |
24152 KB |
Output is correct |
18 |
Correct |
19 ms |
24156 KB |
Output is correct |
19 |
Correct |
256 ms |
43192 KB |
Output is correct |
20 |
Correct |
263 ms |
43160 KB |
Output is correct |
21 |
Correct |
231 ms |
42448 KB |
Output is correct |
22 |
Correct |
248 ms |
42528 KB |
Output is correct |
23 |
Correct |
232 ms |
42580 KB |
Output is correct |
24 |
Correct |
143 ms |
43196 KB |
Output is correct |
25 |
Correct |
140 ms |
43080 KB |
Output is correct |
26 |
Correct |
193 ms |
43560 KB |
Output is correct |
27 |
Correct |
235 ms |
43428 KB |
Output is correct |
28 |
Correct |
171 ms |
43600 KB |
Output is correct |
29 |
Correct |
189 ms |
44112 KB |
Output is correct |
30 |
Correct |
184 ms |
43988 KB |
Output is correct |
31 |
Correct |
168 ms |
44020 KB |
Output is correct |
32 |
Correct |
200 ms |
43824 KB |
Output is correct |
33 |
Correct |
206 ms |
44056 KB |
Output is correct |
34 |
Correct |
143 ms |
42152 KB |
Output is correct |
35 |
Correct |
133 ms |
42208 KB |
Output is correct |
36 |
Correct |
143 ms |
42008 KB |
Output is correct |
37 |
Correct |
136 ms |
41924 KB |
Output is correct |
38 |
Correct |
142 ms |
42320 KB |
Output is correct |
39 |
Correct |
175 ms |
41424 KB |
Output is correct |
40 |
Correct |
118 ms |
37940 KB |
Output is correct |
41 |
Correct |
176 ms |
40920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23896 KB |
Output is correct |
2 |
Correct |
14 ms |
23900 KB |
Output is correct |
3 |
Correct |
17 ms |
23972 KB |
Output is correct |
4 |
Correct |
16 ms |
23900 KB |
Output is correct |
5 |
Correct |
14 ms |
23896 KB |
Output is correct |
6 |
Correct |
16 ms |
23828 KB |
Output is correct |
7 |
Correct |
17 ms |
23900 KB |
Output is correct |
8 |
Correct |
16 ms |
23896 KB |
Output is correct |
9 |
Correct |
15 ms |
23900 KB |
Output is correct |
10 |
Correct |
14 ms |
23900 KB |
Output is correct |
11 |
Correct |
19 ms |
23976 KB |
Output is correct |
12 |
Correct |
19 ms |
24228 KB |
Output is correct |
13 |
Correct |
19 ms |
24152 KB |
Output is correct |
14 |
Correct |
15 ms |
24412 KB |
Output is correct |
15 |
Correct |
19 ms |
24412 KB |
Output is correct |
16 |
Correct |
21 ms |
24348 KB |
Output is correct |
17 |
Correct |
19 ms |
24152 KB |
Output is correct |
18 |
Correct |
19 ms |
24156 KB |
Output is correct |
19 |
Correct |
1897 ms |
118596 KB |
Output is correct |
20 |
Correct |
1911 ms |
119640 KB |
Output is correct |
21 |
Correct |
1936 ms |
119388 KB |
Output is correct |
22 |
Correct |
1877 ms |
119528 KB |
Output is correct |
23 |
Correct |
1398 ms |
123724 KB |
Output is correct |
24 |
Correct |
141 ms |
32080 KB |
Output is correct |
25 |
Correct |
117 ms |
31892 KB |
Output is correct |
26 |
Correct |
94 ms |
32336 KB |
Output is correct |
27 |
Correct |
94 ms |
32584 KB |
Output is correct |
28 |
Correct |
97 ms |
32664 KB |
Output is correct |
29 |
Correct |
93 ms |
31700 KB |
Output is correct |
30 |
Correct |
73 ms |
31828 KB |
Output is correct |
31 |
Correct |
82 ms |
31556 KB |
Output is correct |
32 |
Correct |
41 ms |
27144 KB |
Output is correct |
33 |
Correct |
80 ms |
31752 KB |
Output is correct |
34 |
Correct |
256 ms |
43192 KB |
Output is correct |
35 |
Correct |
263 ms |
43160 KB |
Output is correct |
36 |
Correct |
231 ms |
42448 KB |
Output is correct |
37 |
Correct |
248 ms |
42528 KB |
Output is correct |
38 |
Correct |
232 ms |
42580 KB |
Output is correct |
39 |
Correct |
143 ms |
43196 KB |
Output is correct |
40 |
Correct |
140 ms |
43080 KB |
Output is correct |
41 |
Correct |
193 ms |
43560 KB |
Output is correct |
42 |
Correct |
235 ms |
43428 KB |
Output is correct |
43 |
Correct |
171 ms |
43600 KB |
Output is correct |
44 |
Correct |
189 ms |
44112 KB |
Output is correct |
45 |
Correct |
184 ms |
43988 KB |
Output is correct |
46 |
Correct |
168 ms |
44020 KB |
Output is correct |
47 |
Correct |
200 ms |
43824 KB |
Output is correct |
48 |
Correct |
206 ms |
44056 KB |
Output is correct |
49 |
Correct |
143 ms |
42152 KB |
Output is correct |
50 |
Correct |
133 ms |
42208 KB |
Output is correct |
51 |
Correct |
143 ms |
42008 KB |
Output is correct |
52 |
Correct |
136 ms |
41924 KB |
Output is correct |
53 |
Correct |
142 ms |
42320 KB |
Output is correct |
54 |
Correct |
175 ms |
41424 KB |
Output is correct |
55 |
Correct |
118 ms |
37940 KB |
Output is correct |
56 |
Correct |
176 ms |
40920 KB |
Output is correct |
57 |
Correct |
1606 ms |
121152 KB |
Output is correct |
58 |
Correct |
1781 ms |
121152 KB |
Output is correct |
59 |
Correct |
1523 ms |
119136 KB |
Output is correct |
60 |
Correct |
1586 ms |
118876 KB |
Output is correct |
61 |
Correct |
1510 ms |
118604 KB |
Output is correct |
62 |
Correct |
1626 ms |
118868 KB |
Output is correct |
63 |
Correct |
711 ms |
116604 KB |
Output is correct |
64 |
Correct |
702 ms |
116816 KB |
Output is correct |
65 |
Correct |
1140 ms |
123020 KB |
Output is correct |
66 |
Correct |
1142 ms |
123152 KB |
Output is correct |
67 |
Correct |
1047 ms |
123136 KB |
Output is correct |
68 |
Correct |
1294 ms |
125320 KB |
Output is correct |
69 |
Correct |
1279 ms |
125140 KB |
Output is correct |
70 |
Correct |
1234 ms |
124732 KB |
Output is correct |
71 |
Correct |
1310 ms |
124660 KB |
Output is correct |
72 |
Correct |
1251 ms |
124896 KB |
Output is correct |
73 |
Correct |
743 ms |
112568 KB |
Output is correct |
74 |
Correct |
714 ms |
113576 KB |
Output is correct |
75 |
Correct |
702 ms |
112768 KB |
Output is correct |
76 |
Correct |
697 ms |
112540 KB |
Output is correct |
77 |
Correct |
709 ms |
112976 KB |
Output is correct |
78 |
Correct |
1137 ms |
113772 KB |
Output is correct |
79 |
Correct |
682 ms |
88976 KB |
Output is correct |
80 |
Correct |
1002 ms |
110008 KB |
Output is correct |