Submission #272520

# Submission time Handle Problem Language Result Execution time Memory
272520 2020-08-18T12:13:57 Z aZvezda Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2939 ms 120920 KB
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
template<class T, class T2> bool chkmax(T &a, const T2 &b) {return (a < b) ? a = b, 1 : 0;}

const int mod = 1e9 + 7;
const int MAX_N = 1e6 + 10;

struct Node {
	int ans, lazy;
	Node() : ans(0), lazy(0) {}
};

Node tree[4 * MAX_N];

Node operator +(const Node &a, const Node &b) {
	Node ret;
	ret.ans = max(a.ans, b.ans);
	ret.lazy = 0;
	return ret;
}

void push(int curr, int l, int r) {
	chkmax(tree[curr].ans, tree[curr].lazy);
	if(l != r) {
		chkmax(tree[curr * 2].lazy, tree[curr].lazy);
		chkmax(tree[curr * 2 + 1].lazy, tree[curr].lazy);
	}
	tree[curr].lazy = 0;
}

void update(int curr, int l, int r, int ql, int qr, int val) {
	push(curr, l, r);
	if(ql <= l && r <= qr) {
		chkmax(tree[curr].lazy, val);
		push(curr, l, r);
		return;
	} else if(l > qr || r < ql) {
		return;
	}
	int m = (l + r) / 2ll;
	update(curr * 2, l, m, ql, qr, val);
	update(curr * 2 + 1, m + 1, r, ql, qr, val);
	tree[curr] = tree[curr * 2] + tree[curr * 2 + 1];
} 

int ans(int curr, int l, int r, int ql, int qr) {
	push(curr, l, r);
	if(ql <= l && r <= qr) {
		return tree[curr].ans;
	} else if(l > qr || r < ql) {
		return 0;
	}
	int m = (l + r) / 2ll;
	return max(ans(curr * 2, l, m, ql, qr), ans(curr * 2 + 1, m + 1, r, ql, qr));
}

int l[MAX_N], k[MAX_N];
vector<int> query[MAX_N];
bool ret[MAX_N];
int arr[MAX_N];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n, q;
	cin >> n;
	cin >> q;
	for(int i = 0; i < n; i ++) {
		cin >> arr[i];
	}
	for(int i = 0; i < q; i ++) {
		int r;
		cin >> l[i] >> r >> k[i];
		query[r - 1].push_back(i);
		l[i] --;
	}
	stack<int> st;
	for(int i = 0; i < n; i ++) {
		while(!st.empty() && arr[st.top()] <= arr[i]) {
			st.pop();
		}
		if(!st.empty()) {
			update(1, 0, n - 1, 0, st.top(), arr[st.top()] + arr[i]);
		}
		st.push(i);
		for(auto it : query[i]) {
			ret[it] = ans(1, 0, n - 1, l[it], i) <= k[it];
		}
	}
	for(int i = 0; i < q; i ++) {
		cout << ret[i] << endl;
	}
}
 
# Verdict Execution time Memory Grader output
1 Correct 109 ms 55160 KB Output is correct
2 Correct 37 ms 55160 KB Output is correct
3 Correct 36 ms 55288 KB Output is correct
4 Correct 35 ms 55160 KB Output is correct
5 Correct 42 ms 55160 KB Output is correct
6 Correct 46 ms 55160 KB Output is correct
7 Correct 37 ms 55160 KB Output is correct
8 Correct 35 ms 55160 KB Output is correct
9 Correct 35 ms 55168 KB Output is correct
10 Correct 37 ms 55160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 55160 KB Output is correct
2 Correct 37 ms 55160 KB Output is correct
3 Correct 36 ms 55288 KB Output is correct
4 Correct 35 ms 55160 KB Output is correct
5 Correct 42 ms 55160 KB Output is correct
6 Correct 46 ms 55160 KB Output is correct
7 Correct 37 ms 55160 KB Output is correct
8 Correct 35 ms 55160 KB Output is correct
9 Correct 35 ms 55168 KB Output is correct
10 Correct 37 ms 55160 KB Output is correct
11 Correct 39 ms 55252 KB Output is correct
12 Correct 70 ms 55416 KB Output is correct
13 Correct 44 ms 55416 KB Output is correct
14 Correct 44 ms 55416 KB Output is correct
15 Correct 53 ms 55416 KB Output is correct
16 Correct 46 ms 55416 KB Output is correct
17 Correct 44 ms 55412 KB Output is correct
18 Correct 39 ms 55416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2939 ms 88392 KB Output is correct
2 Correct 2859 ms 120716 KB Output is correct
3 Correct 2834 ms 120568 KB Output is correct
4 Correct 2866 ms 120780 KB Output is correct
5 Correct 2218 ms 120920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 211 ms 58232 KB Output is correct
2 Correct 190 ms 59640 KB Output is correct
3 Correct 171 ms 60024 KB Output is correct
4 Correct 179 ms 60152 KB Output is correct
5 Correct 177 ms 60280 KB Output is correct
6 Correct 132 ms 59000 KB Output is correct
7 Correct 130 ms 59100 KB Output is correct
8 Correct 165 ms 59892 KB Output is correct
9 Correct 82 ms 58100 KB Output is correct
10 Correct 168 ms 59892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 55160 KB Output is correct
2 Correct 37 ms 55160 KB Output is correct
3 Correct 36 ms 55288 KB Output is correct
4 Correct 35 ms 55160 KB Output is correct
5 Correct 42 ms 55160 KB Output is correct
6 Correct 46 ms 55160 KB Output is correct
7 Correct 37 ms 55160 KB Output is correct
8 Correct 35 ms 55160 KB Output is correct
9 Correct 35 ms 55168 KB Output is correct
10 Correct 37 ms 55160 KB Output is correct
11 Correct 39 ms 55252 KB Output is correct
12 Correct 70 ms 55416 KB Output is correct
13 Correct 44 ms 55416 KB Output is correct
14 Correct 44 ms 55416 KB Output is correct
15 Correct 53 ms 55416 KB Output is correct
16 Correct 46 ms 55416 KB Output is correct
17 Correct 44 ms 55412 KB Output is correct
18 Correct 39 ms 55416 KB Output is correct
19 Correct 504 ms 67036 KB Output is correct
20 Correct 499 ms 65916 KB Output is correct
21 Correct 394 ms 63480 KB Output is correct
22 Correct 406 ms 63096 KB Output is correct
23 Correct 405 ms 64120 KB Output is correct
24 Correct 292 ms 63992 KB Output is correct
25 Correct 274 ms 63096 KB Output is correct
26 Correct 305 ms 64248 KB Output is correct
27 Correct 299 ms 64120 KB Output is correct
28 Correct 414 ms 64120 KB Output is correct
29 Correct 468 ms 64888 KB Output is correct
30 Correct 616 ms 64888 KB Output is correct
31 Correct 381 ms 65380 KB Output is correct
32 Correct 388 ms 65144 KB Output is correct
33 Correct 381 ms 65272 KB Output is correct
34 Correct 295 ms 63480 KB Output is correct
35 Correct 289 ms 63820 KB Output is correct
36 Correct 277 ms 63480 KB Output is correct
37 Correct 291 ms 63820 KB Output is correct
38 Correct 268 ms 63992 KB Output is correct
39 Correct 313 ms 64628 KB Output is correct
40 Correct 220 ms 64492 KB Output is correct
41 Correct 344 ms 64876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 55160 KB Output is correct
2 Correct 37 ms 55160 KB Output is correct
3 Correct 36 ms 55288 KB Output is correct
4 Correct 35 ms 55160 KB Output is correct
5 Correct 42 ms 55160 KB Output is correct
6 Correct 46 ms 55160 KB Output is correct
7 Correct 37 ms 55160 KB Output is correct
8 Correct 35 ms 55160 KB Output is correct
9 Correct 35 ms 55168 KB Output is correct
10 Correct 37 ms 55160 KB Output is correct
11 Correct 39 ms 55252 KB Output is correct
12 Correct 70 ms 55416 KB Output is correct
13 Correct 44 ms 55416 KB Output is correct
14 Correct 44 ms 55416 KB Output is correct
15 Correct 53 ms 55416 KB Output is correct
16 Correct 46 ms 55416 KB Output is correct
17 Correct 44 ms 55412 KB Output is correct
18 Correct 39 ms 55416 KB Output is correct
19 Correct 2939 ms 88392 KB Output is correct
20 Correct 2859 ms 120716 KB Output is correct
21 Correct 2834 ms 120568 KB Output is correct
22 Correct 2866 ms 120780 KB Output is correct
23 Correct 2218 ms 120920 KB Output is correct
24 Correct 211 ms 58232 KB Output is correct
25 Correct 190 ms 59640 KB Output is correct
26 Correct 171 ms 60024 KB Output is correct
27 Correct 179 ms 60152 KB Output is correct
28 Correct 177 ms 60280 KB Output is correct
29 Correct 132 ms 59000 KB Output is correct
30 Correct 130 ms 59100 KB Output is correct
31 Correct 165 ms 59892 KB Output is correct
32 Correct 82 ms 58100 KB Output is correct
33 Correct 168 ms 59892 KB Output is correct
34 Correct 504 ms 67036 KB Output is correct
35 Correct 499 ms 65916 KB Output is correct
36 Correct 394 ms 63480 KB Output is correct
37 Correct 406 ms 63096 KB Output is correct
38 Correct 405 ms 64120 KB Output is correct
39 Correct 292 ms 63992 KB Output is correct
40 Correct 274 ms 63096 KB Output is correct
41 Correct 305 ms 64248 KB Output is correct
42 Correct 299 ms 64120 KB Output is correct
43 Correct 414 ms 64120 KB Output is correct
44 Correct 468 ms 64888 KB Output is correct
45 Correct 616 ms 64888 KB Output is correct
46 Correct 381 ms 65380 KB Output is correct
47 Correct 388 ms 65144 KB Output is correct
48 Correct 381 ms 65272 KB Output is correct
49 Correct 295 ms 63480 KB Output is correct
50 Correct 289 ms 63820 KB Output is correct
51 Correct 277 ms 63480 KB Output is correct
52 Correct 291 ms 63820 KB Output is correct
53 Correct 268 ms 63992 KB Output is correct
54 Correct 313 ms 64628 KB Output is correct
55 Correct 220 ms 64492 KB Output is correct
56 Correct 344 ms 64876 KB Output is correct
57 Correct 2728 ms 119660 KB Output is correct
58 Correct 2726 ms 119652 KB Output is correct
59 Correct 2653 ms 115576 KB Output is correct
60 Correct 2529 ms 115576 KB Output is correct
61 Correct 2573 ms 115548 KB Output is correct
62 Correct 2602 ms 115576 KB Output is correct
63 Correct 1441 ms 107704 KB Output is correct
64 Correct 1463 ms 107716 KB Output is correct
65 Correct 2160 ms 114908 KB Output is correct
66 Correct 1904 ms 115036 KB Output is correct
67 Correct 2450 ms 115376 KB Output is correct
68 Correct 1966 ms 119676 KB Output is correct
69 Correct 2057 ms 119808 KB Output is correct
70 Correct 2084 ms 119100 KB Output is correct
71 Correct 2460 ms 118944 KB Output is correct
72 Correct 1989 ms 119012 KB Output is correct
73 Correct 1270 ms 105720 KB Output is correct
74 Correct 1307 ms 106708 KB Output is correct
75 Correct 1292 ms 105772 KB Output is correct
76 Correct 1384 ms 105972 KB Output is correct
77 Correct 1342 ms 105704 KB Output is correct
78 Correct 1792 ms 111796 KB Output is correct
79 Correct 1115 ms 102756 KB Output is correct
80 Correct 1951 ms 109476 KB Output is correct