답안 #384761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384761 2021-04-02T07:39:12 Z ritul_kr_singh Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1436 ms 110524 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'

struct SegmentTree{
	vector<int> a; int sz = 1, ID = -1e18;
	SegmentTree(vector<int> &v){
		while(sz < (int)v.size()) sz += sz;
		a.assign(2*sz, ID);
		build(v, 0, 0, sz);
	}
	void build(vector<int> &v, int x, int lx, int rx){
		if(rx-lx==1){
			if(lx < (int)v.size()) a[x] = v[lx];
			return;
		}
		int mx = (lx+rx)/2;
		build(v, 2*x+1, lx, mx);
		build(v, 2*x+2, mx, rx);
		a[x] = max(a[2*x+1], a[2*x+2]);
	}
	void update(int i, int val, int x, int lx, int rx){
		if(rx-lx==1) return void(a[x] = val);
		int mx = (lx+rx)/2;
		if(i < mx) update(i, val, 2*x+1, lx, mx);
		else update(i, val, 2*x+2, mx, rx);
		a[x] = max(a[2*x+1], a[2*x+2]);
	}
	void update(int i, int val){ update(i, val, 0, 0, sz); }
	int get(int l, int r, int x, int lx, int rx){
		if(r<=lx or rx<=l) return ID;
		if(l<=lx and rx<=r) return a[x];
		int mx = (lx+rx)/2;
		return max(get(l, r, 2*x+1, lx, mx), get(l, r, 2*x+2, mx, rx));
	}
	int get(int r){ return get(0, r+1, 0, 0, sz); }
};

signed main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, m; cin >> n >> m;
	int a[n]; for(int &i : a) cin >> i;

	vector<int> closest(n, -1), s, sum(n, -1e18);
	vector<pair<int, int>> byLeft;
	for(int i=0; i<n; ++i){
		while(!s.empty() and a[s.back()] <= a[i]) s.pop_back();
		if(!s.empty()){
			closest[i] = s.back();
			sum[i] = a[i] + a[s.back()];
			byLeft.emplace_back(s.back(), i);
		}
		s.push_back(i);
	}
	SegmentTree st(sum);
	sort(byLeft.rbegin(), byLeft.rend());
	array<int, 4> q[m];
	bool ans[m];
	for(int i=0; i<m; ++i){
		cin >> q[i][0] >> q[i][1] >> q[i][2];
		q[i][3] = i;
		--q[i][0], --q[i][1];
	}
	sort(q, q+m);
	for(auto &i : q){
		while(!byLeft.empty() and byLeft.back().first < i[0]){
			st.update(byLeft.back().second, -1e18);
			byLeft.pop_back();
		}
		ans[i[3]] = st.get(i[1]) <= i[2];
	}
	for(auto i : ans) cout << i nl;
}
# 결과 실행 시간 메모리 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 2 ms 364 KB Output is correct
6 Correct 2 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 2 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 2 ms 364 KB Output is correct
6 Correct 2 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 2 ms 364 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 5 ms 876 KB Output is correct
13 Correct 5 ms 876 KB Output is correct
14 Correct 6 ms 1004 KB Output is correct
15 Correct 6 ms 1004 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 5 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1372 ms 108828 KB Output is correct
2 Correct 1436 ms 105532 KB Output is correct
3 Correct 1338 ms 105460 KB Output is correct
4 Correct 1390 ms 105660 KB Output is correct
5 Correct 1039 ms 89724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 11884 KB Output is correct
2 Correct 90 ms 11876 KB Output is correct
3 Correct 81 ms 10220 KB Output is correct
4 Correct 80 ms 10220 KB Output is correct
5 Correct 76 ms 10220 KB Output is correct
6 Correct 75 ms 10264 KB Output is correct
7 Correct 86 ms 10352 KB Output is correct
8 Correct 96 ms 11108 KB Output is correct
9 Correct 53 ms 5100 KB Output is correct
10 Correct 85 ms 10856 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 2 ms 364 KB Output is correct
6 Correct 2 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 2 ms 364 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 5 ms 876 KB Output is correct
13 Correct 5 ms 876 KB Output is correct
14 Correct 6 ms 1004 KB Output is correct
15 Correct 6 ms 1004 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 5 ms 1004 KB Output is correct
19 Correct 268 ms 25828 KB Output is correct
20 Correct 233 ms 25820 KB Output is correct
21 Correct 201 ms 25820 KB Output is correct
22 Correct 212 ms 25824 KB Output is correct
23 Correct 195 ms 25692 KB Output is correct
24 Correct 173 ms 22284 KB Output is correct
25 Correct 181 ms 22252 KB Output is correct
26 Correct 175 ms 22636 KB Output is correct
27 Correct 174 ms 22508 KB Output is correct
28 Correct 180 ms 22636 KB Output is correct
29 Correct 181 ms 22636 KB Output is correct
30 Correct 177 ms 22636 KB Output is correct
31 Correct 211 ms 22688 KB Output is correct
32 Correct 221 ms 22636 KB Output is correct
33 Correct 177 ms 22636 KB Output is correct
34 Correct 176 ms 22252 KB Output is correct
35 Correct 168 ms 22252 KB Output is correct
36 Correct 169 ms 21996 KB Output is correct
37 Correct 168 ms 22124 KB Output is correct
38 Correct 170 ms 22252 KB Output is correct
39 Correct 185 ms 22372 KB Output is correct
40 Correct 148 ms 17516 KB Output is correct
41 Correct 201 ms 22884 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 2 ms 364 KB Output is correct
6 Correct 2 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 2 ms 364 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 5 ms 876 KB Output is correct
13 Correct 5 ms 876 KB Output is correct
14 Correct 6 ms 1004 KB Output is correct
15 Correct 6 ms 1004 KB Output is correct
16 Correct 5 ms 876 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 5 ms 1004 KB Output is correct
19 Correct 1372 ms 108828 KB Output is correct
20 Correct 1436 ms 105532 KB Output is correct
21 Correct 1338 ms 105460 KB Output is correct
22 Correct 1390 ms 105660 KB Output is correct
23 Correct 1039 ms 89724 KB Output is correct
24 Correct 104 ms 11884 KB Output is correct
25 Correct 90 ms 11876 KB Output is correct
26 Correct 81 ms 10220 KB Output is correct
27 Correct 80 ms 10220 KB Output is correct
28 Correct 76 ms 10220 KB Output is correct
29 Correct 75 ms 10264 KB Output is correct
30 Correct 86 ms 10352 KB Output is correct
31 Correct 96 ms 11108 KB Output is correct
32 Correct 53 ms 5100 KB Output is correct
33 Correct 85 ms 10856 KB Output is correct
34 Correct 268 ms 25828 KB Output is correct
35 Correct 233 ms 25820 KB Output is correct
36 Correct 201 ms 25820 KB Output is correct
37 Correct 212 ms 25824 KB Output is correct
38 Correct 195 ms 25692 KB Output is correct
39 Correct 173 ms 22284 KB Output is correct
40 Correct 181 ms 22252 KB Output is correct
41 Correct 175 ms 22636 KB Output is correct
42 Correct 174 ms 22508 KB Output is correct
43 Correct 180 ms 22636 KB Output is correct
44 Correct 181 ms 22636 KB Output is correct
45 Correct 177 ms 22636 KB Output is correct
46 Correct 211 ms 22688 KB Output is correct
47 Correct 221 ms 22636 KB Output is correct
48 Correct 177 ms 22636 KB Output is correct
49 Correct 176 ms 22252 KB Output is correct
50 Correct 168 ms 22252 KB Output is correct
51 Correct 169 ms 21996 KB Output is correct
52 Correct 168 ms 22124 KB Output is correct
53 Correct 170 ms 22252 KB Output is correct
54 Correct 185 ms 22372 KB Output is correct
55 Correct 148 ms 17516 KB Output is correct
56 Correct 201 ms 22884 KB Output is correct
57 Correct 1309 ms 106164 KB Output is correct
58 Correct 1298 ms 105816 KB Output is correct
59 Correct 1168 ms 105740 KB Output is correct
60 Correct 1160 ms 105920 KB Output is correct
61 Correct 1198 ms 105808 KB Output is correct
62 Correct 1148 ms 106044 KB Output is correct
63 Correct 860 ms 89708 KB Output is correct
64 Correct 868 ms 89736 KB Output is correct
65 Correct 961 ms 90208 KB Output is correct
66 Correct 972 ms 90092 KB Output is correct
67 Correct 952 ms 89964 KB Output is correct
68 Correct 964 ms 90092 KB Output is correct
69 Correct 962 ms 90092 KB Output is correct
70 Correct 966 ms 90136 KB Output is correct
71 Correct 959 ms 90124 KB Output is correct
72 Correct 986 ms 90116 KB Output is correct
73 Correct 912 ms 104580 KB Output is correct
74 Correct 880 ms 96356 KB Output is correct
75 Correct 858 ms 104700 KB Output is correct
76 Correct 859 ms 104760 KB Output is correct
77 Correct 861 ms 104648 KB Output is correct
78 Correct 1060 ms 107328 KB Output is correct
79 Correct 766 ms 79984 KB Output is correct
80 Correct 1096 ms 110524 KB Output is correct