Submission #910536

# Submission time Handle Problem Language Result Execution time Memory
910536 2024-01-18T05:42:36 Z daoquanglinh2007 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
835 ms 93688 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair

const int NM = 1e6;

int N, M, w[NM+5], pre[NM+5];
vector <int> st;
int bit[NM+5];
vector <pair <pii, int> > q[NM+5];
bool ans[NM+5];

void update(int x, int val){
	while (x <= N){
		bit[x] = max(bit[x], val);
		x += x & (-x);
	}
}

int get(int x){
	int res = 0;
	while (x > 0){
		res = max(res, bit[x]);
		x -= x & (-x);
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> M;
	for (int i = 1; i <= N; i++){
		cin >> w[i];
		while (!st.empty() && w[st.back()] <= w[i]) st.pop_back();
		if (!st.empty()){
			pre[i] = st.back();
		}
		st.push_back(i);
	}
	for (int i = 1; i <= M; i++){
		int l, r, k; cin >> l >> r >> k;
		q[r].push_back(mp(mp(l, k), i));
	}
	for (int i = 1; i <= N; i++){
		if (pre[i] > 0) update(N-pre[i]+1, w[i]+w[pre[i]]);
		for (pair <pii, int> P : q[i]){
			ans[P.se] = get(N-P.fi.fi+1) <= P.fi.se;
		}
	}
	for (int i = 1; i <= M; i++) cout << ans[i] << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 29016 KB Output is correct
2 Correct 9 ms 29020 KB Output is correct
3 Correct 8 ms 29020 KB Output is correct
4 Correct 8 ms 29020 KB Output is correct
5 Correct 9 ms 29020 KB Output is correct
6 Correct 8 ms 29020 KB Output is correct
7 Correct 8 ms 29020 KB Output is correct
8 Correct 7 ms 29020 KB Output is correct
9 Correct 8 ms 29184 KB Output is correct
10 Correct 9 ms 29016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 29016 KB Output is correct
2 Correct 9 ms 29020 KB Output is correct
3 Correct 8 ms 29020 KB Output is correct
4 Correct 8 ms 29020 KB Output is correct
5 Correct 9 ms 29020 KB Output is correct
6 Correct 8 ms 29020 KB Output is correct
7 Correct 8 ms 29020 KB Output is correct
8 Correct 7 ms 29020 KB Output is correct
9 Correct 8 ms 29184 KB Output is correct
10 Correct 9 ms 29016 KB Output is correct
11 Correct 9 ms 29272 KB Output is correct
12 Correct 9 ms 29276 KB Output is correct
13 Correct 12 ms 29300 KB Output is correct
14 Correct 10 ms 29276 KB Output is correct
15 Correct 10 ms 29464 KB Output is correct
16 Correct 10 ms 29276 KB Output is correct
17 Correct 10 ms 29276 KB Output is correct
18 Correct 10 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 823 ms 92048 KB Output is correct
2 Correct 745 ms 93060 KB Output is correct
3 Correct 788 ms 93688 KB Output is correct
4 Correct 835 ms 93092 KB Output is correct
5 Correct 773 ms 89000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 33616 KB Output is correct
2 Correct 49 ms 33364 KB Output is correct
3 Correct 48 ms 33392 KB Output is correct
4 Correct 50 ms 33552 KB Output is correct
5 Correct 46 ms 33404 KB Output is correct
6 Correct 38 ms 32972 KB Output is correct
7 Correct 49 ms 32880 KB Output is correct
8 Correct 46 ms 33084 KB Output is correct
9 Correct 31 ms 32072 KB Output is correct
10 Correct 45 ms 33064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 29016 KB Output is correct
2 Correct 9 ms 29020 KB Output is correct
3 Correct 8 ms 29020 KB Output is correct
4 Correct 8 ms 29020 KB Output is correct
5 Correct 9 ms 29020 KB Output is correct
6 Correct 8 ms 29020 KB Output is correct
7 Correct 8 ms 29020 KB Output is correct
8 Correct 7 ms 29020 KB Output is correct
9 Correct 8 ms 29184 KB Output is correct
10 Correct 9 ms 29016 KB Output is correct
11 Correct 9 ms 29272 KB Output is correct
12 Correct 9 ms 29276 KB Output is correct
13 Correct 12 ms 29300 KB Output is correct
14 Correct 10 ms 29276 KB Output is correct
15 Correct 10 ms 29464 KB Output is correct
16 Correct 10 ms 29276 KB Output is correct
17 Correct 10 ms 29276 KB Output is correct
18 Correct 10 ms 29276 KB Output is correct
19 Correct 108 ms 45136 KB Output is correct
20 Correct 104 ms 45300 KB Output is correct
21 Correct 98 ms 44372 KB Output is correct
22 Correct 95 ms 44416 KB Output is correct
23 Correct 101 ms 44320 KB Output is correct
24 Correct 83 ms 41808 KB Output is correct
25 Correct 118 ms 41736 KB Output is correct
26 Correct 95 ms 42080 KB Output is correct
27 Correct 92 ms 42068 KB Output is correct
28 Correct 98 ms 42096 KB Output is correct
29 Correct 98 ms 42456 KB Output is correct
30 Correct 100 ms 42836 KB Output is correct
31 Correct 105 ms 42512 KB Output is correct
32 Correct 100 ms 42580 KB Output is correct
33 Correct 104 ms 42412 KB Output is correct
34 Correct 97 ms 41556 KB Output is correct
35 Correct 79 ms 41296 KB Output is correct
36 Correct 78 ms 41044 KB Output is correct
37 Correct 80 ms 41044 KB Output is correct
38 Correct 82 ms 41316 KB Output is correct
39 Correct 103 ms 40972 KB Output is correct
40 Correct 82 ms 37572 KB Output is correct
41 Correct 97 ms 42504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 29016 KB Output is correct
2 Correct 9 ms 29020 KB Output is correct
3 Correct 8 ms 29020 KB Output is correct
4 Correct 8 ms 29020 KB Output is correct
5 Correct 9 ms 29020 KB Output is correct
6 Correct 8 ms 29020 KB Output is correct
7 Correct 8 ms 29020 KB Output is correct
8 Correct 7 ms 29020 KB Output is correct
9 Correct 8 ms 29184 KB Output is correct
10 Correct 9 ms 29016 KB Output is correct
11 Correct 9 ms 29272 KB Output is correct
12 Correct 9 ms 29276 KB Output is correct
13 Correct 12 ms 29300 KB Output is correct
14 Correct 10 ms 29276 KB Output is correct
15 Correct 10 ms 29464 KB Output is correct
16 Correct 10 ms 29276 KB Output is correct
17 Correct 10 ms 29276 KB Output is correct
18 Correct 10 ms 29276 KB Output is correct
19 Correct 823 ms 92048 KB Output is correct
20 Correct 745 ms 93060 KB Output is correct
21 Correct 788 ms 93688 KB Output is correct
22 Correct 835 ms 93092 KB Output is correct
23 Correct 773 ms 89000 KB Output is correct
24 Correct 58 ms 33616 KB Output is correct
25 Correct 49 ms 33364 KB Output is correct
26 Correct 48 ms 33392 KB Output is correct
27 Correct 50 ms 33552 KB Output is correct
28 Correct 46 ms 33404 KB Output is correct
29 Correct 38 ms 32972 KB Output is correct
30 Correct 49 ms 32880 KB Output is correct
31 Correct 46 ms 33084 KB Output is correct
32 Correct 31 ms 32072 KB Output is correct
33 Correct 45 ms 33064 KB Output is correct
34 Correct 108 ms 45136 KB Output is correct
35 Correct 104 ms 45300 KB Output is correct
36 Correct 98 ms 44372 KB Output is correct
37 Correct 95 ms 44416 KB Output is correct
38 Correct 101 ms 44320 KB Output is correct
39 Correct 83 ms 41808 KB Output is correct
40 Correct 118 ms 41736 KB Output is correct
41 Correct 95 ms 42080 KB Output is correct
42 Correct 92 ms 42068 KB Output is correct
43 Correct 98 ms 42096 KB Output is correct
44 Correct 98 ms 42456 KB Output is correct
45 Correct 100 ms 42836 KB Output is correct
46 Correct 105 ms 42512 KB Output is correct
47 Correct 100 ms 42580 KB Output is correct
48 Correct 104 ms 42412 KB Output is correct
49 Correct 97 ms 41556 KB Output is correct
50 Correct 79 ms 41296 KB Output is correct
51 Correct 78 ms 41044 KB Output is correct
52 Correct 80 ms 41044 KB Output is correct
53 Correct 82 ms 41316 KB Output is correct
54 Correct 103 ms 40972 KB Output is correct
55 Correct 82 ms 37572 KB Output is correct
56 Correct 97 ms 42504 KB Output is correct
57 Correct 715 ms 93508 KB Output is correct
58 Correct 718 ms 93336 KB Output is correct
59 Correct 750 ms 91976 KB Output is correct
60 Correct 747 ms 91952 KB Output is correct
61 Correct 736 ms 91888 KB Output is correct
62 Correct 751 ms 91692 KB Output is correct
63 Correct 393 ms 84564 KB Output is correct
64 Correct 384 ms 84408 KB Output is correct
65 Correct 645 ms 87520 KB Output is correct
66 Correct 649 ms 87580 KB Output is correct
67 Correct 732 ms 87624 KB Output is correct
68 Correct 715 ms 89124 KB Output is correct
69 Correct 802 ms 89172 KB Output is correct
70 Correct 712 ms 89028 KB Output is correct
71 Correct 768 ms 89072 KB Output is correct
72 Correct 682 ms 88912 KB Output is correct
73 Correct 355 ms 82408 KB Output is correct
74 Correct 380 ms 83344 KB Output is correct
75 Correct 356 ms 82468 KB Output is correct
76 Correct 356 ms 82512 KB Output is correct
77 Correct 358 ms 82408 KB Output is correct
78 Correct 645 ms 84404 KB Output is correct
79 Correct 475 ms 75148 KB Output is correct
80 Correct 611 ms 81140 KB Output is correct