답안 #954261

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954261 2024-03-27T14:43:57 Z starchan Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
943 ms 122264 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
struct segment_tree//we need a seg tree for max
{
	vector<int> tree;
	void init(int n)
	{
		tree.resize(4*n+69, 0);
		return;
	}
	void upd(int pos, int val, int id, int l, int r)
	{
		if(l == r)
		{
			tree[id] = max(tree[id], val);
			return;
		}
		int m = (l+r)/2;
		if(pos <= m)
			upd(pos, val, 2*id, l, m);
		else
			upd(pos, val, 2*id+1, m+1, r);
		tree[id] = max(tree[2*id], tree[2*id+1]);
		return;
	}
	int query(int ql, int qr, int id, int l, int r)
	{
		if(qr < l || r < ql)
			return 0;
		if(ql <= l && r <= qr)
			return tree[id];
		int m = (l+r)/2;
		int s1 = query(ql, qr, 2*id, l, m);
		int s2 = query(ql, qr, 2*id+1, m+1, r);
		return max(s1, s2);
	}
};
signed main()
{
	fast();
	segment_tree work;
	int n, m;
	cin >> n >> m;
	work.init(n);
	vector<pair<in, in>> vv(m);
	vector<int> w(n+1);
	vector<int> pr(n+1);
	for(int i = 1; i <= n; i++)
	{
		pr[i] = i-1;
		cin >> w[i];
	}
	w[0] = INF;
	for(int i = 1; i <= n; i++)
	{
		while(w[pr[i]] <= w[i])
			pr[i] = pr[pr[i]];
	}
	for(int i = 0; i < m; i++)
	{
		int l, r, k;
		cin >> l >> r >> k;
		vv[i] = {{r, l}, {k, i}};
	}
	int ans[m];
	sort(vv.begin(), vv.end());
	int up = 0;
	for(auto Q: vv)
	{
		int l, r, k, i; l = Q.f.s; r = Q.f.f; k = Q.s.f, i = Q.s.s;
		while(up < r)
		{
			up++;
			work.upd(pr[up], w[up]+w[pr[up]], 1, 0, n);
		}
		int ANS = work.query(l, r, 1, 0, n);
		ans[i] = (ANS<=k);
	}
	for(int i = 0; i < m; i++)
		cout << ans[i] << "\n";
	return 0;
}	
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 3 ms 924 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 720 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 929 ms 120232 KB Output is correct
2 Correct 882 ms 121404 KB Output is correct
3 Correct 873 ms 121148 KB Output is correct
4 Correct 911 ms 121292 KB Output is correct
5 Correct 863 ms 121356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 11092 KB Output is correct
2 Correct 67 ms 11012 KB Output is correct
3 Correct 73 ms 11092 KB Output is correct
4 Correct 62 ms 11064 KB Output is correct
5 Correct 67 ms 11092 KB Output is correct
6 Correct 57 ms 10908 KB Output is correct
7 Correct 59 ms 11092 KB Output is correct
8 Correct 57 ms 10744 KB Output is correct
9 Correct 35 ms 5724 KB Output is correct
10 Correct 69 ms 10728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 3 ms 924 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 720 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 155 ms 24516 KB Output is correct
20 Correct 160 ms 24520 KB Output is correct
21 Correct 144 ms 24356 KB Output is correct
22 Correct 148 ms 24400 KB Output is correct
23 Correct 144 ms 24424 KB Output is correct
24 Correct 142 ms 24148 KB Output is correct
25 Correct 136 ms 24248 KB Output is correct
26 Correct 162 ms 24176 KB Output is correct
27 Correct 167 ms 24540 KB Output is correct
28 Correct 146 ms 24568 KB Output is correct
29 Correct 145 ms 24536 KB Output is correct
30 Correct 148 ms 24540 KB Output is correct
31 Correct 184 ms 24404 KB Output is correct
32 Correct 146 ms 24656 KB Output is correct
33 Correct 143 ms 24656 KB Output is correct
34 Correct 130 ms 24148 KB Output is correct
35 Correct 134 ms 24036 KB Output is correct
36 Correct 131 ms 23908 KB Output is correct
37 Correct 128 ms 24020 KB Output is correct
38 Correct 129 ms 24156 KB Output is correct
39 Correct 137 ms 23140 KB Output is correct
40 Correct 106 ms 19280 KB Output is correct
41 Correct 126 ms 22652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 3 ms 924 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 3 ms 720 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 929 ms 120232 KB Output is correct
20 Correct 882 ms 121404 KB Output is correct
21 Correct 873 ms 121148 KB Output is correct
22 Correct 911 ms 121292 KB Output is correct
23 Correct 863 ms 121356 KB Output is correct
24 Correct 69 ms 11092 KB Output is correct
25 Correct 67 ms 11012 KB Output is correct
26 Correct 73 ms 11092 KB Output is correct
27 Correct 62 ms 11064 KB Output is correct
28 Correct 67 ms 11092 KB Output is correct
29 Correct 57 ms 10908 KB Output is correct
30 Correct 59 ms 11092 KB Output is correct
31 Correct 57 ms 10744 KB Output is correct
32 Correct 35 ms 5724 KB Output is correct
33 Correct 69 ms 10728 KB Output is correct
34 Correct 155 ms 24516 KB Output is correct
35 Correct 160 ms 24520 KB Output is correct
36 Correct 144 ms 24356 KB Output is correct
37 Correct 148 ms 24400 KB Output is correct
38 Correct 144 ms 24424 KB Output is correct
39 Correct 142 ms 24148 KB Output is correct
40 Correct 136 ms 24248 KB Output is correct
41 Correct 162 ms 24176 KB Output is correct
42 Correct 167 ms 24540 KB Output is correct
43 Correct 146 ms 24568 KB Output is correct
44 Correct 145 ms 24536 KB Output is correct
45 Correct 148 ms 24540 KB Output is correct
46 Correct 184 ms 24404 KB Output is correct
47 Correct 146 ms 24656 KB Output is correct
48 Correct 143 ms 24656 KB Output is correct
49 Correct 130 ms 24148 KB Output is correct
50 Correct 134 ms 24036 KB Output is correct
51 Correct 131 ms 23908 KB Output is correct
52 Correct 128 ms 24020 KB Output is correct
53 Correct 129 ms 24156 KB Output is correct
54 Correct 137 ms 23140 KB Output is correct
55 Correct 106 ms 19280 KB Output is correct
56 Correct 126 ms 22652 KB Output is correct
57 Correct 893 ms 122260 KB Output is correct
58 Correct 863 ms 122264 KB Output is correct
59 Correct 877 ms 121864 KB Output is correct
60 Correct 848 ms 121872 KB Output is correct
61 Correct 888 ms 122176 KB Output is correct
62 Correct 828 ms 121984 KB Output is correct
63 Correct 691 ms 120024 KB Output is correct
64 Correct 723 ms 120012 KB Output is correct
65 Correct 815 ms 121836 KB Output is correct
66 Correct 821 ms 121840 KB Output is correct
67 Correct 862 ms 122048 KB Output is correct
68 Correct 864 ms 122080 KB Output is correct
69 Correct 943 ms 121964 KB Output is correct
70 Correct 840 ms 122180 KB Output is correct
71 Correct 850 ms 122120 KB Output is correct
72 Correct 837 ms 121952 KB Output is correct
73 Correct 687 ms 118608 KB Output is correct
74 Correct 707 ms 119476 KB Output is correct
75 Correct 673 ms 118600 KB Output is correct
76 Correct 675 ms 118664 KB Output is correct
77 Correct 657 ms 118612 KB Output is correct
78 Correct 768 ms 115900 KB Output is correct
79 Correct 581 ms 88608 KB Output is correct
80 Correct 708 ms 113232 KB Output is correct