Submission #475427

# Submission time Handle Problem Language Result Execution time Memory
475427 2021-09-22T10:49:40 Z ismoilov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1181 ms 117308 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll maxx = 1e6+66;

ll tr[maxx];
ll n;
vector <ll> ad[maxx];
vector <ll> a(maxx), b(maxx), c(maxx), k(maxx);

void add(ll id, ll val){
	while(id > 0){
		tr[id] = max(tr[id], val);
		id -= id & -id;
	}
}

ll get(ll id){
	ll s = 0;
	while(id <= n){
		s = max(s, tr[id]);
		id += id & -id;
	}
	return s;
}

void S()
{
	ll m;
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	
	vector <ll> st;
	
	for(int i = 1; i <= m; i ++){
		cin >> b[i] >> c[i] >> k[i];
		ad[c[i]].push_back(i);
	}
	
	vector <bool> ans(m+1);
	
	for(int i = 1; i <= n; i ++){
		
		while(st.size() > 0 && a[i] >= a[st.back()])
			st.pop_back();
		
		ll x = (st.size() == 0 ? 0 : st.back());
		add(x, a[x] + a[i]);

		for(ll it : ad[i])
			ans[it] = (get(b[it]) <= k[it]);
		st.push_back(i);
	}

	for(int i = 1; i <= m; i++)
		cout << ans[i] << "\n";
}

int main()
{
	IOS;
	/*int t;
	cin >> t;
	while(t --)*/
		S();
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 55040 KB Output is correct
2 Correct 27 ms 55060 KB Output is correct
3 Correct 27 ms 55116 KB Output is correct
4 Correct 28 ms 55116 KB Output is correct
5 Correct 27 ms 55124 KB Output is correct
6 Correct 27 ms 55164 KB Output is correct
7 Correct 26 ms 55088 KB Output is correct
8 Correct 27 ms 55116 KB Output is correct
9 Correct 27 ms 55112 KB Output is correct
10 Correct 27 ms 55052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 55040 KB Output is correct
2 Correct 27 ms 55060 KB Output is correct
3 Correct 27 ms 55116 KB Output is correct
4 Correct 28 ms 55116 KB Output is correct
5 Correct 27 ms 55124 KB Output is correct
6 Correct 27 ms 55164 KB Output is correct
7 Correct 26 ms 55088 KB Output is correct
8 Correct 27 ms 55116 KB Output is correct
9 Correct 27 ms 55112 KB Output is correct
10 Correct 27 ms 55052 KB Output is correct
11 Correct 29 ms 55216 KB Output is correct
12 Correct 29 ms 55296 KB Output is correct
13 Correct 29 ms 55332 KB Output is correct
14 Correct 30 ms 55372 KB Output is correct
15 Correct 32 ms 55380 KB Output is correct
16 Correct 30 ms 55348 KB Output is correct
17 Correct 31 ms 55332 KB Output is correct
18 Correct 30 ms 55348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1175 ms 84948 KB Output is correct
2 Correct 1181 ms 84900 KB Output is correct
3 Correct 1179 ms 84932 KB Output is correct
4 Correct 1173 ms 84948 KB Output is correct
5 Correct 1042 ms 77020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 57924 KB Output is correct
2 Correct 92 ms 57616 KB Output is correct
3 Correct 89 ms 57032 KB Output is correct
4 Correct 88 ms 57112 KB Output is correct
5 Correct 96 ms 57172 KB Output is correct
6 Correct 80 ms 56436 KB Output is correct
7 Correct 78 ms 56432 KB Output is correct
8 Correct 85 ms 57072 KB Output is correct
9 Correct 67 ms 57544 KB Output is correct
10 Correct 92 ms 58688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 55040 KB Output is correct
2 Correct 27 ms 55060 KB Output is correct
3 Correct 27 ms 55116 KB Output is correct
4 Correct 28 ms 55116 KB Output is correct
5 Correct 27 ms 55124 KB Output is correct
6 Correct 27 ms 55164 KB Output is correct
7 Correct 26 ms 55088 KB Output is correct
8 Correct 27 ms 55116 KB Output is correct
9 Correct 27 ms 55112 KB Output is correct
10 Correct 27 ms 55052 KB Output is correct
11 Correct 29 ms 55216 KB Output is correct
12 Correct 29 ms 55296 KB Output is correct
13 Correct 29 ms 55332 KB Output is correct
14 Correct 30 ms 55372 KB Output is correct
15 Correct 32 ms 55380 KB Output is correct
16 Correct 30 ms 55348 KB Output is correct
17 Correct 31 ms 55332 KB Output is correct
18 Correct 30 ms 55348 KB Output is correct
19 Correct 198 ms 67408 KB Output is correct
20 Correct 214 ms 67396 KB Output is correct
21 Correct 178 ms 66260 KB Output is correct
22 Correct 175 ms 66076 KB Output is correct
23 Correct 175 ms 66160 KB Output is correct
24 Correct 163 ms 64324 KB Output is correct
25 Correct 160 ms 64324 KB Output is correct
26 Correct 177 ms 64996 KB Output is correct
27 Correct 172 ms 64996 KB Output is correct
28 Correct 184 ms 65232 KB Output is correct
29 Correct 202 ms 65876 KB Output is correct
30 Correct 185 ms 65860 KB Output is correct
31 Correct 186 ms 65732 KB Output is correct
32 Correct 187 ms 65864 KB Output is correct
33 Correct 182 ms 65736 KB Output is correct
34 Correct 180 ms 64096 KB Output is correct
35 Correct 160 ms 63968 KB Output is correct
36 Correct 158 ms 63816 KB Output is correct
37 Correct 155 ms 63884 KB Output is correct
38 Correct 164 ms 64072 KB Output is correct
39 Correct 181 ms 64572 KB Output is correct
40 Correct 150 ms 63032 KB Output is correct
41 Correct 174 ms 63768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 55040 KB Output is correct
2 Correct 27 ms 55060 KB Output is correct
3 Correct 27 ms 55116 KB Output is correct
4 Correct 28 ms 55116 KB Output is correct
5 Correct 27 ms 55124 KB Output is correct
6 Correct 27 ms 55164 KB Output is correct
7 Correct 26 ms 55088 KB Output is correct
8 Correct 27 ms 55116 KB Output is correct
9 Correct 27 ms 55112 KB Output is correct
10 Correct 27 ms 55052 KB Output is correct
11 Correct 29 ms 55216 KB Output is correct
12 Correct 29 ms 55296 KB Output is correct
13 Correct 29 ms 55332 KB Output is correct
14 Correct 30 ms 55372 KB Output is correct
15 Correct 32 ms 55380 KB Output is correct
16 Correct 30 ms 55348 KB Output is correct
17 Correct 31 ms 55332 KB Output is correct
18 Correct 30 ms 55348 KB Output is correct
19 Correct 1175 ms 84948 KB Output is correct
20 Correct 1181 ms 84900 KB Output is correct
21 Correct 1179 ms 84932 KB Output is correct
22 Correct 1173 ms 84948 KB Output is correct
23 Correct 1042 ms 77020 KB Output is correct
24 Correct 96 ms 57924 KB Output is correct
25 Correct 92 ms 57616 KB Output is correct
26 Correct 89 ms 57032 KB Output is correct
27 Correct 88 ms 57112 KB Output is correct
28 Correct 96 ms 57172 KB Output is correct
29 Correct 80 ms 56436 KB Output is correct
30 Correct 78 ms 56432 KB Output is correct
31 Correct 85 ms 57072 KB Output is correct
32 Correct 67 ms 57544 KB Output is correct
33 Correct 92 ms 58688 KB Output is correct
34 Correct 198 ms 67408 KB Output is correct
35 Correct 214 ms 67396 KB Output is correct
36 Correct 178 ms 66260 KB Output is correct
37 Correct 175 ms 66076 KB Output is correct
38 Correct 175 ms 66160 KB Output is correct
39 Correct 163 ms 64324 KB Output is correct
40 Correct 160 ms 64324 KB Output is correct
41 Correct 177 ms 64996 KB Output is correct
42 Correct 172 ms 64996 KB Output is correct
43 Correct 184 ms 65232 KB Output is correct
44 Correct 202 ms 65876 KB Output is correct
45 Correct 185 ms 65860 KB Output is correct
46 Correct 186 ms 65732 KB Output is correct
47 Correct 187 ms 65864 KB Output is correct
48 Correct 182 ms 65736 KB Output is correct
49 Correct 180 ms 64096 KB Output is correct
50 Correct 160 ms 63968 KB Output is correct
51 Correct 158 ms 63816 KB Output is correct
52 Correct 155 ms 63884 KB Output is correct
53 Correct 164 ms 64072 KB Output is correct
54 Correct 181 ms 64572 KB Output is correct
55 Correct 150 ms 63032 KB Output is correct
56 Correct 174 ms 63768 KB Output is correct
57 Correct 1181 ms 117308 KB Output is correct
58 Correct 1163 ms 99920 KB Output is correct
59 Correct 1096 ms 97164 KB Output is correct
60 Correct 1091 ms 97268 KB Output is correct
61 Correct 1083 ms 97360 KB Output is correct
62 Correct 1107 ms 97352 KB Output is correct
63 Correct 808 ms 100208 KB Output is correct
64 Correct 780 ms 99652 KB Output is correct
65 Correct 1012 ms 106528 KB Output is correct
66 Correct 981 ms 89236 KB Output is correct
67 Correct 998 ms 89412 KB Output is correct
68 Correct 1047 ms 92476 KB Output is correct
69 Correct 1043 ms 109712 KB Output is correct
70 Correct 1092 ms 109036 KB Output is correct
71 Correct 1034 ms 109136 KB Output is correct
72 Correct 1049 ms 109164 KB Output is correct
73 Correct 722 ms 98324 KB Output is correct
74 Correct 763 ms 99116 KB Output is correct
75 Correct 728 ms 98252 KB Output is correct
76 Correct 733 ms 98260 KB Output is correct
77 Correct 748 ms 98020 KB Output is correct
78 Correct 971 ms 104272 KB Output is correct
79 Correct 742 ms 94640 KB Output is correct
80 Correct 958 ms 99268 KB Output is correct