답안 #571830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571830 2022-06-02T19:54:50 Z AzamatRustamov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
852 ms 99404 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
int n;
vector<ll> fenwick; // for max

void upd(int i, ll val)
{
	while (i > 0)
	{
		fenwick[i] = max(fenwick[i], val);
		i -= -i&i;
	}
}

ll get(int r)
{
	ll mx = 0;
	while (r < n)
	{
		mx = max(mx, fenwick[r]);
		r += -r&r;
	}
	return mx;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int m;
	cin >> n >> m;
	fenwick.assign(n, 0);
	ll w[n];
	for (int i=1; i<=n; i++)
		cin >> w[i];
	vector< pair< pair <ll, ll>, ll > > que[n+1];
	for (int i=0; i<m; i++)
	{
		ll l, r, k;
		cin >> l >> r >> k;
		que[r].push_back({{l, k}, i});
	}
	ll ans[m];
	stack<int> st;
	st.push(0);
	for (int i=1; i<=n; i++)
	{
		while (!st.empty() and w[i] >= w[st.top()])
			st.pop();
		if (!st.empty())
			upd(st.top(), w[st.top()]+w[i]);
		for (auto q : que[i])
		{
			ans[q.second] = get(q.first.first)<=q.first.second;
		}
		st.push(i);
	}
	for (int i=0; i<m; i++) cout << ans[i] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 624 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 3 ms 844 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 831 ms 88772 KB Output is correct
2 Correct 828 ms 82556 KB Output is correct
3 Correct 813 ms 82360 KB Output is correct
4 Correct 852 ms 87956 KB Output is correct
5 Correct 784 ms 83288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 10404 KB Output is correct
2 Correct 54 ms 10496 KB Output is correct
3 Correct 48 ms 10428 KB Output is correct
4 Correct 52 ms 10436 KB Output is correct
5 Correct 49 ms 10440 KB Output is correct
6 Correct 41 ms 10308 KB Output is correct
7 Correct 47 ms 10316 KB Output is correct
8 Correct 45 ms 9728 KB Output is correct
9 Correct 29 ms 5508 KB Output is correct
10 Correct 50 ms 9720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 624 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 3 ms 844 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 139 ms 22836 KB Output is correct
20 Correct 140 ms 22832 KB Output is correct
21 Correct 116 ms 23780 KB Output is correct
22 Correct 113 ms 23532 KB Output is correct
23 Correct 114 ms 23532 KB Output is correct
24 Correct 106 ms 23556 KB Output is correct
25 Correct 105 ms 23756 KB Output is correct
26 Correct 115 ms 23400 KB Output is correct
27 Correct 117 ms 23372 KB Output is correct
28 Correct 119 ms 23268 KB Output is correct
29 Correct 125 ms 23116 KB Output is correct
30 Correct 158 ms 23212 KB Output is correct
31 Correct 125 ms 23116 KB Output is correct
32 Correct 134 ms 23144 KB Output is correct
33 Correct 138 ms 23148 KB Output is correct
34 Correct 102 ms 22860 KB Output is correct
35 Correct 98 ms 22896 KB Output is correct
36 Correct 94 ms 22816 KB Output is correct
37 Correct 93 ms 22744 KB Output is correct
38 Correct 99 ms 22860 KB Output is correct
39 Correct 115 ms 21248 KB Output is correct
40 Correct 91 ms 17420 KB Output is correct
41 Correct 115 ms 20580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 368 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 624 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 3 ms 844 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 2 ms 724 KB Output is correct
18 Correct 3 ms 716 KB Output is correct
19 Correct 831 ms 88772 KB Output is correct
20 Correct 828 ms 82556 KB Output is correct
21 Correct 813 ms 82360 KB Output is correct
22 Correct 852 ms 87956 KB Output is correct
23 Correct 784 ms 83288 KB Output is correct
24 Correct 63 ms 10404 KB Output is correct
25 Correct 54 ms 10496 KB Output is correct
26 Correct 48 ms 10428 KB Output is correct
27 Correct 52 ms 10436 KB Output is correct
28 Correct 49 ms 10440 KB Output is correct
29 Correct 41 ms 10308 KB Output is correct
30 Correct 47 ms 10316 KB Output is correct
31 Correct 45 ms 9728 KB Output is correct
32 Correct 29 ms 5508 KB Output is correct
33 Correct 50 ms 9720 KB Output is correct
34 Correct 139 ms 22836 KB Output is correct
35 Correct 140 ms 22832 KB Output is correct
36 Correct 116 ms 23780 KB Output is correct
37 Correct 113 ms 23532 KB Output is correct
38 Correct 114 ms 23532 KB Output is correct
39 Correct 106 ms 23556 KB Output is correct
40 Correct 105 ms 23756 KB Output is correct
41 Correct 115 ms 23400 KB Output is correct
42 Correct 117 ms 23372 KB Output is correct
43 Correct 119 ms 23268 KB Output is correct
44 Correct 125 ms 23116 KB Output is correct
45 Correct 158 ms 23212 KB Output is correct
46 Correct 125 ms 23116 KB Output is correct
47 Correct 134 ms 23144 KB Output is correct
48 Correct 138 ms 23148 KB Output is correct
49 Correct 102 ms 22860 KB Output is correct
50 Correct 98 ms 22896 KB Output is correct
51 Correct 94 ms 22816 KB Output is correct
52 Correct 93 ms 22744 KB Output is correct
53 Correct 99 ms 22860 KB Output is correct
54 Correct 115 ms 21248 KB Output is correct
55 Correct 91 ms 17420 KB Output is correct
56 Correct 115 ms 20580 KB Output is correct
57 Correct 821 ms 98524 KB Output is correct
58 Correct 782 ms 83792 KB Output is correct
59 Correct 738 ms 84472 KB Output is correct
60 Correct 743 ms 84672 KB Output is correct
61 Correct 749 ms 84536 KB Output is correct
62 Correct 714 ms 84540 KB Output is correct
63 Correct 484 ms 86428 KB Output is correct
64 Correct 494 ms 86352 KB Output is correct
65 Correct 681 ms 84492 KB Output is correct
66 Correct 706 ms 99404 KB Output is correct
67 Correct 746 ms 99092 KB Output is correct
68 Correct 755 ms 83356 KB Output is correct
69 Correct 748 ms 83300 KB Output is correct
70 Correct 762 ms 98004 KB Output is correct
71 Correct 762 ms 98340 KB Output is correct
72 Correct 733 ms 83404 KB Output is correct
73 Correct 437 ms 81484 KB Output is correct
74 Correct 466 ms 81368 KB Output is correct
75 Correct 444 ms 81252 KB Output is correct
76 Correct 450 ms 81676 KB Output is correct
77 Correct 445 ms 81300 KB Output is correct
78 Correct 656 ms 80580 KB Output is correct
79 Correct 501 ms 59396 KB Output is correct
80 Correct 639 ms 79112 KB Output is correct