Submission #500879

# Submission time Handle Problem Language Result Execution time Memory
500879 2022-01-01T14:25:37 Z Mazaalai Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1454 ms 79788 KB
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define LINE "----------------------\n"
#define ALL(x) x.begin(),x.end()
using namespace std;
using ll = long long;
using PII = pair <int, int>;
using VI = vector <int>;
using VVI = vector <VI>;
using VPI = vector <PII>;

const int N = 1e6 + 5;
const int M = 4 * N;
const int INF = 1e9+1;
int nums[N], ans[N], node[M];
int n, m;
struct Query {
	int l, r, k, id;
	Query () {}
	Query (int _l, int _r, int _k, int _id) {
		l = _l;
		r = _r;
		k = _k;
		id = _id;
	}
	void init (int _l, int _r, int _k, int _id) {
		l = _l;
		r = _r;
		k = _k;
		id = _id;
	}
	bool operator < (const Query& a) const {
		return r < a.r;
	}
};
vector <Query> queries[N];
void update(int l, int r, int id, int val, int head) {
	if (l == r) {
		node[head] = val;
		return;
	}
	int mid = (l+r)>>1;
	if (id <= mid) update(l, mid, id, val, head*2+1);
	else update(mid+1, r, id, val, head*2+2);
	node[head] = max(node[head*2+1], node[head*2+2]);
}
int query(int l, int r, int L, int R, int head) {
	if (l > R || L > r) return -1;
	if (L <= l && r <= R) return node[head];
	int mid = (l+r)>>1;
	return max(
		query(l, mid, L, R, head*2+1),
		query(mid+1, r, L, R, head*2+2)
	);
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	cin >> n >> m;
	nums[0] = 1e9+1;
	for (int i = 1; i <= n; i++) cin >> nums[i];
	// vector <Query> queries;
	Query tmp;
	for (int i = 1; i <= m; i++) {
		int l, r, k; cin >> l >> r >> k;
		tmp.init(l, r, k, i);
		queries[r].pb(tmp);
	}
	stack <int> stk;
	stk.push(0);
	memset(node, -1, sizeof(node));
	for (int i = 1, j = 0; i <= n && j < m; i++) {
		while (nums[i] >= nums[stk.top()]) stk.pop();
		if (stk.size() > 1) update(1, n, stk.top(), nums[stk.top()]+nums[i], 0);
		stk.push(i);
		for (auto &curQ : queries[i]) {
			ans[curQ.id] = (query(1, n, curQ.l, curQ.r, 0) > curQ.k ? 0 : 1);
			j++;
		}
	}
	for (int i = 1; i <= m; i++) cout << ans[i] << '\n';

}























# Verdict Execution time Memory Grader output
1 Correct 26 ms 39372 KB Output is correct
2 Correct 22 ms 39372 KB Output is correct
3 Correct 20 ms 39412 KB Output is correct
4 Correct 24 ms 39400 KB Output is correct
5 Correct 19 ms 39372 KB Output is correct
6 Correct 19 ms 39500 KB Output is correct
7 Correct 19 ms 39500 KB Output is correct
8 Correct 19 ms 39480 KB Output is correct
9 Correct 20 ms 39372 KB Output is correct
10 Correct 21 ms 39500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 39372 KB Output is correct
2 Correct 22 ms 39372 KB Output is correct
3 Correct 20 ms 39412 KB Output is correct
4 Correct 24 ms 39400 KB Output is correct
5 Correct 19 ms 39372 KB Output is correct
6 Correct 19 ms 39500 KB Output is correct
7 Correct 19 ms 39500 KB Output is correct
8 Correct 19 ms 39480 KB Output is correct
9 Correct 20 ms 39372 KB Output is correct
10 Correct 21 ms 39500 KB Output is correct
11 Correct 24 ms 39556 KB Output is correct
12 Correct 25 ms 39556 KB Output is correct
13 Correct 22 ms 39620 KB Output is correct
14 Correct 26 ms 39660 KB Output is correct
15 Correct 24 ms 39656 KB Output is correct
16 Correct 22 ms 39740 KB Output is correct
17 Correct 22 ms 39704 KB Output is correct
18 Correct 25 ms 39688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1353 ms 79660 KB Output is correct
2 Correct 1365 ms 79788 KB Output is correct
3 Correct 1327 ms 79740 KB Output is correct
4 Correct 1376 ms 79756 KB Output is correct
5 Correct 1148 ms 79692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 44880 KB Output is correct
2 Correct 120 ms 44704 KB Output is correct
3 Correct 89 ms 44868 KB Output is correct
4 Correct 91 ms 44868 KB Output is correct
5 Correct 91 ms 44916 KB Output is correct
6 Correct 79 ms 44612 KB Output is correct
7 Correct 86 ms 44520 KB Output is correct
8 Correct 91 ms 44360 KB Output is correct
9 Correct 54 ms 43316 KB Output is correct
10 Correct 101 ms 44380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 39372 KB Output is correct
2 Correct 22 ms 39372 KB Output is correct
3 Correct 20 ms 39412 KB Output is correct
4 Correct 24 ms 39400 KB Output is correct
5 Correct 19 ms 39372 KB Output is correct
6 Correct 19 ms 39500 KB Output is correct
7 Correct 19 ms 39500 KB Output is correct
8 Correct 19 ms 39480 KB Output is correct
9 Correct 20 ms 39372 KB Output is correct
10 Correct 21 ms 39500 KB Output is correct
11 Correct 24 ms 39556 KB Output is correct
12 Correct 25 ms 39556 KB Output is correct
13 Correct 22 ms 39620 KB Output is correct
14 Correct 26 ms 39660 KB Output is correct
15 Correct 24 ms 39656 KB Output is correct
16 Correct 22 ms 39740 KB Output is correct
17 Correct 22 ms 39704 KB Output is correct
18 Correct 25 ms 39688 KB Output is correct
19 Correct 221 ms 53168 KB Output is correct
20 Correct 227 ms 53124 KB Output is correct
21 Correct 220 ms 52712 KB Output is correct
22 Correct 199 ms 52640 KB Output is correct
23 Correct 252 ms 52664 KB Output is correct
24 Correct 176 ms 52564 KB Output is correct
25 Correct 165 ms 52600 KB Output is correct
26 Correct 182 ms 52836 KB Output is correct
27 Correct 229 ms 52840 KB Output is correct
28 Correct 189 ms 52780 KB Output is correct
29 Correct 220 ms 53108 KB Output is correct
30 Correct 208 ms 53236 KB Output is correct
31 Correct 203 ms 53016 KB Output is correct
32 Correct 211 ms 53104 KB Output is correct
33 Correct 198 ms 53060 KB Output is correct
34 Correct 189 ms 52088 KB Output is correct
35 Correct 163 ms 52088 KB Output is correct
36 Correct 176 ms 51844 KB Output is correct
37 Correct 161 ms 51936 KB Output is correct
38 Correct 165 ms 52012 KB Output is correct
39 Correct 190 ms 51288 KB Output is correct
40 Correct 148 ms 50096 KB Output is correct
41 Correct 179 ms 50780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 39372 KB Output is correct
2 Correct 22 ms 39372 KB Output is correct
3 Correct 20 ms 39412 KB Output is correct
4 Correct 24 ms 39400 KB Output is correct
5 Correct 19 ms 39372 KB Output is correct
6 Correct 19 ms 39500 KB Output is correct
7 Correct 19 ms 39500 KB Output is correct
8 Correct 19 ms 39480 KB Output is correct
9 Correct 20 ms 39372 KB Output is correct
10 Correct 21 ms 39500 KB Output is correct
11 Correct 24 ms 39556 KB Output is correct
12 Correct 25 ms 39556 KB Output is correct
13 Correct 22 ms 39620 KB Output is correct
14 Correct 26 ms 39660 KB Output is correct
15 Correct 24 ms 39656 KB Output is correct
16 Correct 22 ms 39740 KB Output is correct
17 Correct 22 ms 39704 KB Output is correct
18 Correct 25 ms 39688 KB Output is correct
19 Correct 1353 ms 79660 KB Output is correct
20 Correct 1365 ms 79788 KB Output is correct
21 Correct 1327 ms 79740 KB Output is correct
22 Correct 1376 ms 79756 KB Output is correct
23 Correct 1148 ms 79692 KB Output is correct
24 Correct 104 ms 44880 KB Output is correct
25 Correct 120 ms 44704 KB Output is correct
26 Correct 89 ms 44868 KB Output is correct
27 Correct 91 ms 44868 KB Output is correct
28 Correct 91 ms 44916 KB Output is correct
29 Correct 79 ms 44612 KB Output is correct
30 Correct 86 ms 44520 KB Output is correct
31 Correct 91 ms 44360 KB Output is correct
32 Correct 54 ms 43316 KB Output is correct
33 Correct 101 ms 44380 KB Output is correct
34 Correct 221 ms 53168 KB Output is correct
35 Correct 227 ms 53124 KB Output is correct
36 Correct 220 ms 52712 KB Output is correct
37 Correct 199 ms 52640 KB Output is correct
38 Correct 252 ms 52664 KB Output is correct
39 Correct 176 ms 52564 KB Output is correct
40 Correct 165 ms 52600 KB Output is correct
41 Correct 182 ms 52836 KB Output is correct
42 Correct 229 ms 52840 KB Output is correct
43 Correct 189 ms 52780 KB Output is correct
44 Correct 220 ms 53108 KB Output is correct
45 Correct 208 ms 53236 KB Output is correct
46 Correct 203 ms 53016 KB Output is correct
47 Correct 211 ms 53104 KB Output is correct
48 Correct 198 ms 53060 KB Output is correct
49 Correct 189 ms 52088 KB Output is correct
50 Correct 163 ms 52088 KB Output is correct
51 Correct 176 ms 51844 KB Output is correct
52 Correct 161 ms 51936 KB Output is correct
53 Correct 165 ms 52012 KB Output is correct
54 Correct 190 ms 51288 KB Output is correct
55 Correct 148 ms 50096 KB Output is correct
56 Correct 179 ms 50780 KB Output is correct
57 Correct 1399 ms 75204 KB Output is correct
58 Correct 1454 ms 75424 KB Output is correct
59 Correct 1278 ms 74444 KB Output is correct
60 Correct 1203 ms 74480 KB Output is correct
61 Correct 1252 ms 74368 KB Output is correct
62 Correct 1291 ms 74436 KB Output is correct
63 Correct 823 ms 73844 KB Output is correct
64 Correct 810 ms 73864 KB Output is correct
65 Correct 1094 ms 74508 KB Output is correct
66 Correct 1075 ms 74384 KB Output is correct
67 Correct 1097 ms 79208 KB Output is correct
68 Correct 1159 ms 75212 KB Output is correct
69 Correct 1177 ms 75244 KB Output is correct
70 Correct 1217 ms 75040 KB Output is correct
71 Correct 1143 ms 75004 KB Output is correct
72 Correct 1156 ms 75240 KB Output is correct
73 Correct 795 ms 70296 KB Output is correct
74 Correct 745 ms 73368 KB Output is correct
75 Correct 710 ms 73604 KB Output is correct
76 Correct 731 ms 73592 KB Output is correct
77 Correct 772 ms 73104 KB Output is correct
78 Correct 962 ms 72916 KB Output is correct
79 Correct 693 ms 68636 KB Output is correct
80 Correct 967 ms 72500 KB Output is correct