Submission #223636

# Submission time Handle Problem Language Result Execution time Memory
223636 2020-04-15T21:07:48 Z wilwxk Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1915 ms 51760 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e6+5;
int book[MAXN];
int seg[MAXN*4];
int ans[MAXN];
vector<pair<int, int> > seg_ind;
vector<tuple<int, int, int, int> > qv;
int n, q;

void update(int u, int l, int r, int qi, int val) {
	if(qi < l || qi > r) return;
	if(l == r) {
		seg[u] = val;
		return;
	}
	int m = (l+r)/2;
	int vl = u*2;
	int vr = vl|1;
	update(vl, l, m, qi, val);
	update(vr, m+1, r, qi, val);
	seg[u] = max(seg[vl], seg[vr]);
}

int query(int u, int l, int r, int ql, int qr) {
	if(ql > r || qr < l) return 0;
	if(ql <= l && qr >= r) return seg[u];
	int m = (l+r)/2;
	int vl = u*2;
	int vr = vl|1;
	return max( query(vl, l, m, ql, qr), query(vr, m+1, r, ql, qr) );
}


int main() {
	scanf("%d %d", &n, &q);
	for(int i = 1; i <= n; i++) scanf("%d", &book[i]);
	for(int i = 1; i <= q; i++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		qv.push_back({a, b, c, i});
	}
	sort(qv.rbegin(), qv.rend());

	stack<int> st;
	st.push(0);
	book[0] = 2e9+9;
	for(int i = 1; i <= n; i++) {
		while(book[st.top()] <= book[i]) st.pop();
		seg_ind.push_back({st.top(), i});
		// printf("+(%d, %d)\n", i, st.top());
		st.push(i);
	}
	sort(seg_ind.rbegin(), seg_ind.rend());

	int p = 0;
	for(int i = 0; i <= q; i++) {
		int ql, qr, x, id;
		tie(ql, qr, x, id) = qv[i];
		while(p < n && seg_ind[p].first >= ql) {
			int val = book[seg_ind[p].first] + book[seg_ind[p].second];
			// printf("act %d %d %d\n", seg_ind[p].first, seg_ind[p].second, val);
			update(1, 1, n, seg_ind[p].second, val);
			p++;
		}

		int mx = query(1, 1, n, ql, qr);
		// printf(">> %d %d %d\n", ql, qr, mx);
		ans[id] = (mx <= x);
	}

	for(int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:38:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", &book[i]);
                              ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 9 ms 768 KB Output is correct
13 Correct 9 ms 768 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 11 ms 896 KB Output is correct
16 Correct 10 ms 768 KB Output is correct
17 Correct 9 ms 768 KB Output is correct
18 Correct 10 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1800 ms 51264 KB Output is correct
2 Correct 1915 ms 51388 KB Output is correct
3 Correct 1778 ms 51320 KB Output is correct
4 Correct 1767 ms 51388 KB Output is correct
5 Correct 1548 ms 51484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 7652 KB Output is correct
2 Correct 135 ms 7780 KB Output is correct
3 Correct 123 ms 7652 KB Output is correct
4 Correct 126 ms 7652 KB Output is correct
5 Correct 125 ms 7804 KB Output is correct
6 Correct 122 ms 7524 KB Output is correct
7 Correct 119 ms 7652 KB Output is correct
8 Correct 116 ms 7396 KB Output is correct
9 Correct 67 ms 3940 KB Output is correct
10 Correct 118 ms 7396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 9 ms 768 KB Output is correct
13 Correct 9 ms 768 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 11 ms 896 KB Output is correct
16 Correct 10 ms 768 KB Output is correct
17 Correct 9 ms 768 KB Output is correct
18 Correct 10 ms 768 KB Output is correct
19 Correct 304 ms 17788 KB Output is correct
20 Correct 317 ms 17756 KB Output is correct
21 Correct 284 ms 17604 KB Output is correct
22 Correct 299 ms 17628 KB Output is correct
23 Correct 292 ms 17496 KB Output is correct
24 Correct 272 ms 17500 KB Output is correct
25 Correct 279 ms 17568 KB Output is correct
26 Correct 280 ms 17616 KB Output is correct
27 Correct 282 ms 17628 KB Output is correct
28 Correct 277 ms 17628 KB Output is correct
29 Correct 282 ms 17884 KB Output is correct
30 Correct 277 ms 17756 KB Output is correct
31 Correct 277 ms 17756 KB Output is correct
32 Correct 285 ms 17756 KB Output is correct
33 Correct 276 ms 17760 KB Output is correct
34 Correct 264 ms 17372 KB Output is correct
35 Correct 269 ms 17372 KB Output is correct
36 Correct 267 ms 17220 KB Output is correct
37 Correct 275 ms 17244 KB Output is correct
38 Correct 265 ms 17380 KB Output is correct
39 Correct 263 ms 16348 KB Output is correct
40 Correct 195 ms 12764 KB Output is correct
41 Correct 246 ms 15836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 9 ms 768 KB Output is correct
13 Correct 9 ms 768 KB Output is correct
14 Correct 11 ms 768 KB Output is correct
15 Correct 11 ms 896 KB Output is correct
16 Correct 10 ms 768 KB Output is correct
17 Correct 9 ms 768 KB Output is correct
18 Correct 10 ms 768 KB Output is correct
19 Correct 1800 ms 51264 KB Output is correct
20 Correct 1915 ms 51388 KB Output is correct
21 Correct 1778 ms 51320 KB Output is correct
22 Correct 1767 ms 51388 KB Output is correct
23 Correct 1548 ms 51484 KB Output is correct
24 Correct 130 ms 7652 KB Output is correct
25 Correct 135 ms 7780 KB Output is correct
26 Correct 123 ms 7652 KB Output is correct
27 Correct 126 ms 7652 KB Output is correct
28 Correct 125 ms 7804 KB Output is correct
29 Correct 122 ms 7524 KB Output is correct
30 Correct 119 ms 7652 KB Output is correct
31 Correct 116 ms 7396 KB Output is correct
32 Correct 67 ms 3940 KB Output is correct
33 Correct 118 ms 7396 KB Output is correct
34 Correct 304 ms 17788 KB Output is correct
35 Correct 317 ms 17756 KB Output is correct
36 Correct 284 ms 17604 KB Output is correct
37 Correct 299 ms 17628 KB Output is correct
38 Correct 292 ms 17496 KB Output is correct
39 Correct 272 ms 17500 KB Output is correct
40 Correct 279 ms 17568 KB Output is correct
41 Correct 280 ms 17616 KB Output is correct
42 Correct 282 ms 17628 KB Output is correct
43 Correct 277 ms 17628 KB Output is correct
44 Correct 282 ms 17884 KB Output is correct
45 Correct 277 ms 17756 KB Output is correct
46 Correct 277 ms 17756 KB Output is correct
47 Correct 285 ms 17756 KB Output is correct
48 Correct 276 ms 17760 KB Output is correct
49 Correct 264 ms 17372 KB Output is correct
50 Correct 269 ms 17372 KB Output is correct
51 Correct 267 ms 17220 KB Output is correct
52 Correct 275 ms 17244 KB Output is correct
53 Correct 265 ms 17380 KB Output is correct
54 Correct 263 ms 16348 KB Output is correct
55 Correct 195 ms 12764 KB Output is correct
56 Correct 246 ms 15836 KB Output is correct
57 Correct 1796 ms 51760 KB Output is correct
58 Correct 1798 ms 51504 KB Output is correct
59 Correct 1661 ms 51568 KB Output is correct
60 Correct 1646 ms 51556 KB Output is correct
61 Correct 1636 ms 51528 KB Output is correct
62 Correct 1698 ms 51548 KB Output is correct
63 Correct 1408 ms 51188 KB Output is correct
64 Correct 1472 ms 51308 KB Output is correct
65 Correct 1453 ms 51396 KB Output is correct
66 Correct 1499 ms 51516 KB Output is correct
67 Correct 1522 ms 51284 KB Output is correct
68 Correct 1501 ms 51272 KB Output is correct
69 Correct 1589 ms 51436 KB Output is correct
70 Correct 1473 ms 51292 KB Output is correct
71 Correct 1517 ms 51136 KB Output is correct
72 Correct 1509 ms 50976 KB Output is correct
73 Correct 1420 ms 51116 KB Output is correct
74 Correct 1377 ms 50908 KB Output is correct
75 Correct 1485 ms 50880 KB Output is correct
76 Correct 1443 ms 50768 KB Output is correct
77 Correct 1390 ms 50908 KB Output is correct
78 Correct 1434 ms 50700 KB Output is correct
79 Correct 1026 ms 36544 KB Output is correct
80 Correct 1410 ms 50496 KB Output is correct