Submission #254828

# Submission time Handle Problem Language Result Execution time Memory
254828 2020-07-30T17:22:01 Z vuhoanggiap Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1959 ms 138668 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef pair<int, int> ii;

void Fastio() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int n, m; 
int a[1000005], pre[1000005]; 
bool Ans[1000005];
vector<int> pos[1000005];
vector<pair<ii, int> > Queries[1000005]; 

int ST[1000005 * 4]; 

void Upd(int i, int l, int r, int id, int val) {
	if(id < l or r < id) return; 
	if(l == r) {
		ST[i] = val; 
		return; 
	}
	int mid = (l + r) >> 1; 
	Upd(i << 1, l, mid, id, val);
	Upd(i << 1 | 1, mid + 1, r, id, val); 
	ST[i] = max(ST[i << 1], ST[i << 1 | 1]); 
}

int Query(int i, int l, int r, int L, int R) {
	if(R < l or r < L or L > R) return 0; 
	if(L <= l and r <= R) {
		return ST[i]; 
	}
	int mid = (l + r) >> 1; 
	return max(Query(i << 1, l, mid, L, R), Query(i << 1 | 1, mid + 1, r, L, R)); 
}

signed main()
{
	Fastio(); 
	cin >> n >> m; 
	for(int i = 1; i <= n; i++) {
		cin >> a[i]; 
	}
	for(int i = 1; i <= m; i++) {
		int l, r, k; 
		cin >> l >> r >> k; 
		Queries[l].pb({{r, k}, i}); 
	}
	stack<int> S; 
	for(int i = 1; i <= n; i++) {
		while(!S.empty() and a[S.top()] <= a[i]) S.pop(); 
		if(!S.empty()) {
			pre[i] = S.top(); 
		}
		S.push(i); 
	}
	for(int i = 1; i <= n; i++) {
		pos[pre[i]].pb(i); 
	}
	for(int i = 1; i <= n; i++) {
		Upd(1, 1, n, i, a[i] + a[pre[i]]); 
	}
	for(int l = 0; l <= n; l++) {
		for(auto T : Queries[l]) {
			int r = T.fi.fi, k = T.fi.se, id = T.se; 
			Ans[id] = (Query(1, 1, n, l, r) <= k); 
		}
		for(auto i : pos[l]) {
			Upd(1, 1, n, i, 0); 
		}
	}
	for(int i = 1; i <= m; i++) {
		cout << Ans[i] << '\n'; 
 	}
}

# Verdict Execution time Memory Grader output
1 Correct 27 ms 47360 KB Output is correct
2 Correct 30 ms 47360 KB Output is correct
3 Correct 27 ms 47360 KB Output is correct
4 Correct 26 ms 47360 KB Output is correct
5 Correct 27 ms 47360 KB Output is correct
6 Correct 27 ms 47360 KB Output is correct
7 Correct 27 ms 47352 KB Output is correct
8 Correct 32 ms 47360 KB Output is correct
9 Correct 27 ms 47360 KB Output is correct
10 Correct 28 ms 47352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47360 KB Output is correct
2 Correct 30 ms 47360 KB Output is correct
3 Correct 27 ms 47360 KB Output is correct
4 Correct 26 ms 47360 KB Output is correct
5 Correct 27 ms 47360 KB Output is correct
6 Correct 27 ms 47360 KB Output is correct
7 Correct 27 ms 47352 KB Output is correct
8 Correct 32 ms 47360 KB Output is correct
9 Correct 27 ms 47360 KB Output is correct
10 Correct 28 ms 47352 KB Output is correct
11 Correct 29 ms 47488 KB Output is correct
12 Correct 30 ms 47736 KB Output is correct
13 Correct 33 ms 47744 KB Output is correct
14 Correct 32 ms 47736 KB Output is correct
15 Correct 33 ms 47736 KB Output is correct
16 Correct 32 ms 47740 KB Output is correct
17 Correct 32 ms 47608 KB Output is correct
18 Correct 31 ms 47608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1845 ms 104440 KB Output is correct
2 Correct 1874 ms 137452 KB Output is correct
3 Correct 1902 ms 137092 KB Output is correct
4 Correct 1959 ms 137132 KB Output is correct
5 Correct 1843 ms 121212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 53752 KB Output is correct
2 Correct 152 ms 54904 KB Output is correct
3 Correct 166 ms 53620 KB Output is correct
4 Correct 165 ms 53748 KB Output is correct
5 Correct 151 ms 53876 KB Output is correct
6 Correct 136 ms 53104 KB Output is correct
7 Correct 138 ms 53104 KB Output is correct
8 Correct 137 ms 53376 KB Output is correct
9 Correct 71 ms 50480 KB Output is correct
10 Correct 136 ms 53424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47360 KB Output is correct
2 Correct 30 ms 47360 KB Output is correct
3 Correct 27 ms 47360 KB Output is correct
4 Correct 26 ms 47360 KB Output is correct
5 Correct 27 ms 47360 KB Output is correct
6 Correct 27 ms 47360 KB Output is correct
7 Correct 27 ms 47352 KB Output is correct
8 Correct 32 ms 47360 KB Output is correct
9 Correct 27 ms 47360 KB Output is correct
10 Correct 28 ms 47352 KB Output is correct
11 Correct 29 ms 47488 KB Output is correct
12 Correct 30 ms 47736 KB Output is correct
13 Correct 33 ms 47744 KB Output is correct
14 Correct 32 ms 47736 KB Output is correct
15 Correct 33 ms 47736 KB Output is correct
16 Correct 32 ms 47740 KB Output is correct
17 Correct 32 ms 47608 KB Output is correct
18 Correct 31 ms 47608 KB Output is correct
19 Correct 374 ms 65936 KB Output is correct
20 Correct 354 ms 65912 KB Output is correct
21 Correct 313 ms 64760 KB Output is correct
22 Correct 315 ms 64888 KB Output is correct
23 Correct 306 ms 64888 KB Output is correct
24 Correct 283 ms 61932 KB Output is correct
25 Correct 299 ms 62064 KB Output is correct
26 Correct 306 ms 62316 KB Output is correct
27 Correct 307 ms 62448 KB Output is correct
28 Correct 311 ms 62448 KB Output is correct
29 Correct 356 ms 62828 KB Output is correct
30 Correct 356 ms 62828 KB Output is correct
31 Correct 330 ms 62696 KB Output is correct
32 Correct 312 ms 62700 KB Output is correct
33 Correct 326 ms 62828 KB Output is correct
34 Correct 273 ms 61172 KB Output is correct
35 Correct 278 ms 61168 KB Output is correct
36 Correct 279 ms 61048 KB Output is correct
37 Correct 269 ms 60908 KB Output is correct
38 Correct 274 ms 61296 KB Output is correct
39 Correct 287 ms 61476 KB Output is correct
40 Correct 225 ms 58412 KB Output is correct
41 Correct 268 ms 60716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 47360 KB Output is correct
2 Correct 30 ms 47360 KB Output is correct
3 Correct 27 ms 47360 KB Output is correct
4 Correct 26 ms 47360 KB Output is correct
5 Correct 27 ms 47360 KB Output is correct
6 Correct 27 ms 47360 KB Output is correct
7 Correct 27 ms 47352 KB Output is correct
8 Correct 32 ms 47360 KB Output is correct
9 Correct 27 ms 47360 KB Output is correct
10 Correct 28 ms 47352 KB Output is correct
11 Correct 29 ms 47488 KB Output is correct
12 Correct 30 ms 47736 KB Output is correct
13 Correct 33 ms 47744 KB Output is correct
14 Correct 32 ms 47736 KB Output is correct
15 Correct 33 ms 47736 KB Output is correct
16 Correct 32 ms 47740 KB Output is correct
17 Correct 32 ms 47608 KB Output is correct
18 Correct 31 ms 47608 KB Output is correct
19 Correct 1845 ms 104440 KB Output is correct
20 Correct 1874 ms 137452 KB Output is correct
21 Correct 1902 ms 137092 KB Output is correct
22 Correct 1959 ms 137132 KB Output is correct
23 Correct 1843 ms 121212 KB Output is correct
24 Correct 172 ms 53752 KB Output is correct
25 Correct 152 ms 54904 KB Output is correct
26 Correct 166 ms 53620 KB Output is correct
27 Correct 165 ms 53748 KB Output is correct
28 Correct 151 ms 53876 KB Output is correct
29 Correct 136 ms 53104 KB Output is correct
30 Correct 138 ms 53104 KB Output is correct
31 Correct 137 ms 53376 KB Output is correct
32 Correct 71 ms 50480 KB Output is correct
33 Correct 136 ms 53424 KB Output is correct
34 Correct 374 ms 65936 KB Output is correct
35 Correct 354 ms 65912 KB Output is correct
36 Correct 313 ms 64760 KB Output is correct
37 Correct 315 ms 64888 KB Output is correct
38 Correct 306 ms 64888 KB Output is correct
39 Correct 283 ms 61932 KB Output is correct
40 Correct 299 ms 62064 KB Output is correct
41 Correct 306 ms 62316 KB Output is correct
42 Correct 307 ms 62448 KB Output is correct
43 Correct 311 ms 62448 KB Output is correct
44 Correct 356 ms 62828 KB Output is correct
45 Correct 356 ms 62828 KB Output is correct
46 Correct 330 ms 62696 KB Output is correct
47 Correct 312 ms 62700 KB Output is correct
48 Correct 326 ms 62828 KB Output is correct
49 Correct 273 ms 61172 KB Output is correct
50 Correct 278 ms 61168 KB Output is correct
51 Correct 279 ms 61048 KB Output is correct
52 Correct 269 ms 60908 KB Output is correct
53 Correct 274 ms 61296 KB Output is correct
54 Correct 287 ms 61476 KB Output is correct
55 Correct 225 ms 58412 KB Output is correct
56 Correct 268 ms 60716 KB Output is correct
57 Correct 1903 ms 138668 KB Output is correct
58 Correct 1888 ms 138640 KB Output is correct
59 Correct 1837 ms 135916 KB Output is correct
60 Correct 1835 ms 135944 KB Output is correct
61 Correct 1786 ms 136092 KB Output is correct
62 Correct 1905 ms 136040 KB Output is correct
63 Correct 1415 ms 114912 KB Output is correct
64 Correct 1406 ms 114876 KB Output is correct
65 Correct 1676 ms 120720 KB Output is correct
66 Correct 1742 ms 120492 KB Output is correct
67 Correct 1753 ms 120488 KB Output is correct
68 Correct 1818 ms 122476 KB Output is correct
69 Correct 1790 ms 122380 KB Output is correct
70 Correct 1875 ms 122020 KB Output is correct
71 Correct 1856 ms 121880 KB Output is correct
72 Correct 1844 ms 121984 KB Output is correct
73 Correct 1368 ms 112496 KB Output is correct
74 Correct 1387 ms 113012 KB Output is correct
75 Correct 1377 ms 112104 KB Output is correct
76 Correct 1331 ms 112064 KB Output is correct
77 Correct 1325 ms 112500 KB Output is correct
78 Correct 1545 ms 117708 KB Output is correct
79 Correct 1151 ms 99912 KB Output is correct
80 Correct 1550 ms 113244 KB Output is correct