답안 #380556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380556 2021-03-22T09:28:26 Z wind_reaper Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1379 ms 61676 KB
#include <bits/stdc++.h>

using namespace std;

struct SegmentTree{
	vector<int64_t> tree;
	int sz = 1;

	SegmentTree(int n){
		while(sz < n)
			sz <<= 1;
		tree.resize(2*sz);
	}

	void upd(int idx, int64_t val, int x, int lx, int rx){
		if(rx - lx == 1){
			tree[x] = max(tree[x], val);
			return;
		}

		int mid = (lx + rx) >> 1;
		if(idx < mid) upd(idx, val, 2*x+1, lx, mid);
		else upd(idx, val, 2*x+2, mid, rx);

		tree[x] = max(tree[2*x+1], tree[2*x+2]);
	}

	int64_t query(int l, int r, int x, int lx, int rx){
		if(rx <= l || lx >= r)
			return 0LL;
		if(l <= lx && r >= rx)
			return tree[x];

		int mid = (lx + rx) >> 1;
		return max(query(l, r, 2*x+1, lx, mid), query(l, r, 2*x+2, mid, rx));
	}

	void upd(int idx, int val) { upd(idx, val, 0, 0, sz); }

	int64_t query(int l, int r) { return query(l, r, 0, 0, sz); } 
};

int32_t main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	
	int n, m;
	cin >> n >> m;

	vector<int64_t> W(n);
	for(int i = 0; i < n; i++)
		cin >> W[i];

	vector<array<int64_t, 4>> query(m);
	for(int i = 0; i < m; i++){
		auto& [l, r, k, idx] = query[i];
		cin >> l >> r >> k;
		idx = i;
		--l, --r;
	}

	sort(query.begin(), query.end(), [](const array<int64_t, 4>& a, const array<int64_t, 4>& b){
		if(a[1] == b[1])
			return a[0] < b[0];

		return a[1] < b[1];
	});

	vector<int> st;
	SegmentTree S(n);
	vector<bool> ans(m);

	int i = 0;
	for(auto& [l, r, k, idx] : query){
		while(i <= r){
			while(!st.empty() && W[st.back()] <= W[i])
				st.pop_back();
			if(!st.empty())
				S.upd(st.back(), W[i] + W[st.back()]);
			st.push_back(i);
			i++;
		}

		ans[idx] = (S.query(l, r+1) <= k);
	}

	for(auto k : ans)
		cout << k << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 4 ms 748 KB Output is correct
13 Correct 5 ms 748 KB Output is correct
14 Correct 6 ms 876 KB Output is correct
15 Correct 6 ms 876 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 4 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1373 ms 58004 KB Output is correct
2 Correct 1334 ms 59500 KB Output is correct
3 Correct 1323 ms 59628 KB Output is correct
4 Correct 1324 ms 59684 KB Output is correct
5 Correct 1128 ms 59628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 6636 KB Output is correct
2 Correct 104 ms 8620 KB Output is correct
3 Correct 86 ms 8556 KB Output is correct
4 Correct 92 ms 8684 KB Output is correct
5 Correct 102 ms 8456 KB Output is correct
6 Correct 77 ms 8300 KB Output is correct
7 Correct 79 ms 8300 KB Output is correct
8 Correct 82 ms 8172 KB Output is correct
9 Correct 48 ms 4972 KB Output is correct
10 Correct 82 ms 8172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 4 ms 748 KB Output is correct
13 Correct 5 ms 748 KB Output is correct
14 Correct 6 ms 876 KB Output is correct
15 Correct 6 ms 876 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 4 ms 748 KB Output is correct
19 Correct 239 ms 19296 KB Output is correct
20 Correct 238 ms 19436 KB Output is correct
21 Correct 228 ms 19308 KB Output is correct
22 Correct 238 ms 19224 KB Output is correct
23 Correct 224 ms 19180 KB Output is correct
24 Correct 187 ms 19052 KB Output is correct
25 Correct 180 ms 19052 KB Output is correct
26 Correct 192 ms 19344 KB Output is correct
27 Correct 194 ms 19180 KB Output is correct
28 Correct 211 ms 19436 KB Output is correct
29 Correct 205 ms 19308 KB Output is correct
30 Correct 199 ms 19436 KB Output is correct
31 Correct 229 ms 19308 KB Output is correct
32 Correct 198 ms 19308 KB Output is correct
33 Correct 202 ms 19344 KB Output is correct
34 Correct 190 ms 18968 KB Output is correct
35 Correct 186 ms 18968 KB Output is correct
36 Correct 175 ms 18704 KB Output is correct
37 Correct 172 ms 18668 KB Output is correct
38 Correct 185 ms 19180 KB Output is correct
39 Correct 185 ms 17816 KB Output is correct
40 Correct 142 ms 14628 KB Output is correct
41 Correct 187 ms 17388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 4 ms 748 KB Output is correct
13 Correct 5 ms 748 KB Output is correct
14 Correct 6 ms 876 KB Output is correct
15 Correct 6 ms 876 KB Output is correct
16 Correct 5 ms 748 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 4 ms 748 KB Output is correct
19 Correct 1373 ms 58004 KB Output is correct
20 Correct 1334 ms 59500 KB Output is correct
21 Correct 1323 ms 59628 KB Output is correct
22 Correct 1324 ms 59684 KB Output is correct
23 Correct 1128 ms 59628 KB Output is correct
24 Correct 106 ms 6636 KB Output is correct
25 Correct 104 ms 8620 KB Output is correct
26 Correct 86 ms 8556 KB Output is correct
27 Correct 92 ms 8684 KB Output is correct
28 Correct 102 ms 8456 KB Output is correct
29 Correct 77 ms 8300 KB Output is correct
30 Correct 79 ms 8300 KB Output is correct
31 Correct 82 ms 8172 KB Output is correct
32 Correct 48 ms 4972 KB Output is correct
33 Correct 82 ms 8172 KB Output is correct
34 Correct 239 ms 19296 KB Output is correct
35 Correct 238 ms 19436 KB Output is correct
36 Correct 228 ms 19308 KB Output is correct
37 Correct 238 ms 19224 KB Output is correct
38 Correct 224 ms 19180 KB Output is correct
39 Correct 187 ms 19052 KB Output is correct
40 Correct 180 ms 19052 KB Output is correct
41 Correct 192 ms 19344 KB Output is correct
42 Correct 194 ms 19180 KB Output is correct
43 Correct 211 ms 19436 KB Output is correct
44 Correct 205 ms 19308 KB Output is correct
45 Correct 199 ms 19436 KB Output is correct
46 Correct 229 ms 19308 KB Output is correct
47 Correct 198 ms 19308 KB Output is correct
48 Correct 202 ms 19344 KB Output is correct
49 Correct 190 ms 18968 KB Output is correct
50 Correct 186 ms 18968 KB Output is correct
51 Correct 175 ms 18704 KB Output is correct
52 Correct 172 ms 18668 KB Output is correct
53 Correct 185 ms 19180 KB Output is correct
54 Correct 185 ms 17816 KB Output is correct
55 Correct 142 ms 14628 KB Output is correct
56 Correct 187 ms 17388 KB Output is correct
57 Correct 1358 ms 59848 KB Output is correct
58 Correct 1379 ms 59756 KB Output is correct
59 Correct 1279 ms 59736 KB Output is correct
60 Correct 1289 ms 59756 KB Output is correct
61 Correct 1267 ms 59756 KB Output is correct
62 Correct 1295 ms 59828 KB Output is correct
63 Correct 929 ms 59584 KB Output is correct
64 Correct 939 ms 59544 KB Output is correct
65 Correct 1076 ms 60012 KB Output is correct
66 Correct 1113 ms 59868 KB Output is correct
67 Correct 1079 ms 59972 KB Output is correct
68 Correct 1123 ms 59984 KB Output is correct
69 Correct 1143 ms 60012 KB Output is correct
70 Correct 1130 ms 60236 KB Output is correct
71 Correct 1145 ms 60140 KB Output is correct
72 Correct 1115 ms 60048 KB Output is correct
73 Correct 877 ms 59756 KB Output is correct
74 Correct 916 ms 59756 KB Output is correct
75 Correct 890 ms 59500 KB Output is correct
76 Correct 894 ms 59516 KB Output is correct
77 Correct 880 ms 59628 KB Output is correct
78 Correct 1028 ms 61676 KB Output is correct
79 Correct 729 ms 47416 KB Output is correct
80 Correct 1040 ms 59244 KB Output is correct