답안 #223635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223635 2020-04-15T21:04:38 Z wilwxk Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1625 ms 83880 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.begin(), qv.end());

	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.begin(), seg_ind.end());

	int p = n-1;
	for(int i = q-1; i >= 0; i--) {
		int ql, qr, x, id;
		tie(ql, qr, x, id) = qv[i];
		while(p >= 0 && 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);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 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
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 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 896 KB Output is correct
15 Correct 11 ms 768 KB Output is correct
16 Correct 9 ms 768 KB Output is correct
17 Correct 9 ms 768 KB Output is correct
18 Correct 9 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1550 ms 82088 KB Output is correct
2 Correct 1566 ms 83088 KB Output is correct
3 Correct 1625 ms 83112 KB Output is correct
4 Correct 1548 ms 83252 KB Output is correct
5 Correct 1261 ms 75068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 7780 KB Output is correct
2 Correct 125 ms 7656 KB Output is correct
3 Correct 104 ms 6720 KB Output is correct
4 Correct 109 ms 6756 KB Output is correct
5 Correct 108 ms 6720 KB Output is correct
6 Correct 102 ms 6756 KB Output is correct
7 Correct 100 ms 6628 KB Output is correct
8 Correct 102 ms 7144 KB Output is correct
9 Correct 62 ms 3940 KB Output is correct
10 Correct 103 ms 7016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 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 896 KB Output is correct
15 Correct 11 ms 768 KB Output is correct
16 Correct 9 ms 768 KB Output is correct
17 Correct 9 ms 768 KB Output is correct
18 Correct 9 ms 768 KB Output is correct
19 Correct 289 ms 17960 KB Output is correct
20 Correct 295 ms 17764 KB Output is correct
21 Correct 275 ms 17628 KB Output is correct
22 Correct 267 ms 17628 KB Output is correct
23 Correct 271 ms 17628 KB Output is correct
24 Correct 233 ms 15324 KB Output is correct
25 Correct 232 ms 15540 KB Output is correct
26 Correct 236 ms 15556 KB Output is correct
27 Correct 235 ms 15580 KB Output is correct
28 Correct 238 ms 15708 KB Output is correct
29 Correct 232 ms 15708 KB Output is correct
30 Correct 234 ms 15708 KB Output is correct
31 Correct 244 ms 15836 KB Output is correct
32 Correct 235 ms 15708 KB Output is correct
33 Correct 247 ms 15836 KB Output is correct
34 Correct 221 ms 15332 KB Output is correct
35 Correct 211 ms 15328 KB Output is correct
36 Correct 209 ms 15196 KB Output is correct
37 Correct 219 ms 15104 KB Output is correct
38 Correct 211 ms 15324 KB Output is correct
39 Correct 236 ms 14940 KB Output is correct
40 Correct 181 ms 12124 KB Output is correct
41 Correct 224 ms 15192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 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 896 KB Output is correct
15 Correct 11 ms 768 KB Output is correct
16 Correct 9 ms 768 KB Output is correct
17 Correct 9 ms 768 KB Output is correct
18 Correct 9 ms 768 KB Output is correct
19 Correct 1550 ms 82088 KB Output is correct
20 Correct 1566 ms 83088 KB Output is correct
21 Correct 1625 ms 83112 KB Output is correct
22 Correct 1548 ms 83252 KB Output is correct
23 Correct 1261 ms 75068 KB Output is correct
24 Correct 126 ms 7780 KB Output is correct
25 Correct 125 ms 7656 KB Output is correct
26 Correct 104 ms 6720 KB Output is correct
27 Correct 109 ms 6756 KB Output is correct
28 Correct 108 ms 6720 KB Output is correct
29 Correct 102 ms 6756 KB Output is correct
30 Correct 100 ms 6628 KB Output is correct
31 Correct 102 ms 7144 KB Output is correct
32 Correct 62 ms 3940 KB Output is correct
33 Correct 103 ms 7016 KB Output is correct
34 Correct 289 ms 17960 KB Output is correct
35 Correct 295 ms 17764 KB Output is correct
36 Correct 275 ms 17628 KB Output is correct
37 Correct 267 ms 17628 KB Output is correct
38 Correct 271 ms 17628 KB Output is correct
39 Correct 233 ms 15324 KB Output is correct
40 Correct 232 ms 15540 KB Output is correct
41 Correct 236 ms 15556 KB Output is correct
42 Correct 235 ms 15580 KB Output is correct
43 Correct 238 ms 15708 KB Output is correct
44 Correct 232 ms 15708 KB Output is correct
45 Correct 234 ms 15708 KB Output is correct
46 Correct 244 ms 15836 KB Output is correct
47 Correct 235 ms 15708 KB Output is correct
48 Correct 247 ms 15836 KB Output is correct
49 Correct 221 ms 15332 KB Output is correct
50 Correct 211 ms 15328 KB Output is correct
51 Correct 209 ms 15196 KB Output is correct
52 Correct 219 ms 15104 KB Output is correct
53 Correct 211 ms 15324 KB Output is correct
54 Correct 236 ms 14940 KB Output is correct
55 Correct 181 ms 12124 KB Output is correct
56 Correct 224 ms 15192 KB Output is correct
57 Correct 1529 ms 83688 KB Output is correct
58 Correct 1522 ms 83772 KB Output is correct
59 Correct 1489 ms 83624 KB Output is correct
60 Correct 1521 ms 83880 KB Output is correct
61 Correct 1536 ms 83764 KB Output is correct
62 Correct 1516 ms 83620 KB Output is correct
63 Correct 1167 ms 73512 KB Output is correct
64 Correct 1170 ms 73616 KB Output is correct
65 Correct 1261 ms 75268 KB Output is correct
66 Correct 1240 ms 75312 KB Output is correct
67 Correct 1268 ms 75424 KB Output is correct
68 Correct 1323 ms 75556 KB Output is correct
69 Correct 1293 ms 75420 KB Output is correct
70 Correct 1241 ms 75624 KB Output is correct
71 Correct 1238 ms 75516 KB Output is correct
72 Correct 1231 ms 75516 KB Output is correct
73 Correct 1105 ms 72104 KB Output is correct
74 Correct 1099 ms 73244 KB Output is correct
75 Correct 1167 ms 72148 KB Output is correct
76 Correct 1125 ms 72192 KB Output is correct
77 Correct 1165 ms 72036 KB Output is correct
78 Correct 1262 ms 72056 KB Output is correct
79 Correct 908 ms 55832 KB Output is correct
80 Correct 1254 ms 72448 KB Output is correct