답안 #761540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761540 2023-06-19T23:06:02 Z NK_ Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
693 ms 75044 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'

template<class T> using V = vector<T>;



const int INF = 1e9+10;
struct BIT {
	int N; V<int> A; void init(int n) { N = n; A = V<int>(N, INF); }
	void upd(int p, int x) { p = N - 1 - p; for(++p;p<=N;p+=p&-p) A[p-1] = min(A[p-1], x);}
	int get(int r) { r = N - 1 - r; int s = INF; for(++r;r;r-=r&-r) s = min(A[r-1], s); return s; }
};

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, K; cin >> N >> K;
	V<int> A(N); for(auto& x : A) cin >> x;

	BIT B; B.init(N);

	V<array<int, 4>> Q(K); for(int i = 0; i < K; i++) {
		cin >> Q[i][1] >> Q[i][2] >> Q[i][0];
		--Q[i][1], --Q[i][2];
		Q[i][3] = i;
	}

	V<array<int, 3>> E;
	V<pair<int, int>> stk = {{-1, -1}};
	for(int i = N - 1; i >= 0; i--) {
		int pos = i;
		while(stk.back().first != -1 && A[stk.back().first] < A[i]) {
			int x = A[stk.back().first] + A[i];
			// cout << x << " " << i << " " << pos << endl;
			E.push_back({x, i, pos});
			pos = max(pos, stk.back().second);

			stk.pop_back();
		}	
		B.upd(i, N);
		stk.push_back({i, pos});
	}

	sort(rbegin(Q), rend(Q));
	sort(rbegin(E), rend(E));

	vector<int> ans(K);

	int j = 0;
	for(int q = 0; q < K; q++) {
		// cout << q << endl;
		while(j < int(size(E)) && E[j][0] > Q[q][0]) {
			auto [k, i, x] = E[j];
			// cout << i << " " << x << endl;
			B.upd(i, x);
			j++;
		}

		auto [k, l, r, i] = Q[q];

		int x = B.get(l); 
		// cout << l << " " << r << " " << x << endl;
		ans[i] = x >= r;
	}

	for(auto x : ans) cout << x << nl;

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 2 ms 660 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 5 ms 724 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 632 ms 41444 KB Output is correct
2 Correct 633 ms 41436 KB Output is correct
3 Correct 625 ms 41376 KB Output is correct
4 Correct 613 ms 41380 KB Output is correct
5 Correct 504 ms 37540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 4428 KB Output is correct
2 Correct 67 ms 6356 KB Output is correct
3 Correct 43 ms 5992 KB Output is correct
4 Correct 41 ms 5960 KB Output is correct
5 Correct 41 ms 5960 KB Output is correct
6 Correct 43 ms 6088 KB Output is correct
7 Correct 42 ms 6088 KB Output is correct
8 Correct 45 ms 6236 KB Output is correct
9 Correct 32 ms 3744 KB Output is correct
10 Correct 44 ms 6032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 2 ms 660 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 5 ms 724 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 124 ms 15040 KB Output is correct
20 Correct 126 ms 15116 KB Output is correct
21 Correct 121 ms 14912 KB Output is correct
22 Correct 121 ms 14968 KB Output is correct
23 Correct 121 ms 14984 KB Output is correct
24 Correct 95 ms 14088 KB Output is correct
25 Correct 92 ms 14020 KB Output is correct
26 Correct 93 ms 14272 KB Output is correct
27 Correct 92 ms 14272 KB Output is correct
28 Correct 102 ms 14212 KB Output is correct
29 Correct 94 ms 14352 KB Output is correct
30 Correct 94 ms 14276 KB Output is correct
31 Correct 95 ms 14344 KB Output is correct
32 Correct 101 ms 14348 KB Output is correct
33 Correct 95 ms 14276 KB Output is correct
34 Correct 97 ms 13964 KB Output is correct
35 Correct 97 ms 13984 KB Output is correct
36 Correct 100 ms 13788 KB Output is correct
37 Correct 95 ms 13764 KB Output is correct
38 Correct 98 ms 13964 KB Output is correct
39 Correct 101 ms 13700 KB Output is correct
40 Correct 83 ms 11924 KB Output is correct
41 Correct 102 ms 13316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 2 ms 660 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 5 ms 724 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 2 ms 596 KB Output is correct
18 Correct 3 ms 596 KB Output is correct
19 Correct 632 ms 41444 KB Output is correct
20 Correct 633 ms 41436 KB Output is correct
21 Correct 625 ms 41376 KB Output is correct
22 Correct 613 ms 41380 KB Output is correct
23 Correct 504 ms 37540 KB Output is correct
24 Correct 62 ms 4428 KB Output is correct
25 Correct 67 ms 6356 KB Output is correct
26 Correct 43 ms 5992 KB Output is correct
27 Correct 41 ms 5960 KB Output is correct
28 Correct 41 ms 5960 KB Output is correct
29 Correct 43 ms 6088 KB Output is correct
30 Correct 42 ms 6088 KB Output is correct
31 Correct 45 ms 6236 KB Output is correct
32 Correct 32 ms 3744 KB Output is correct
33 Correct 44 ms 6032 KB Output is correct
34 Correct 124 ms 15040 KB Output is correct
35 Correct 126 ms 15116 KB Output is correct
36 Correct 121 ms 14912 KB Output is correct
37 Correct 121 ms 14968 KB Output is correct
38 Correct 121 ms 14984 KB Output is correct
39 Correct 95 ms 14088 KB Output is correct
40 Correct 92 ms 14020 KB Output is correct
41 Correct 93 ms 14272 KB Output is correct
42 Correct 92 ms 14272 KB Output is correct
43 Correct 102 ms 14212 KB Output is correct
44 Correct 94 ms 14352 KB Output is correct
45 Correct 94 ms 14276 KB Output is correct
46 Correct 95 ms 14344 KB Output is correct
47 Correct 101 ms 14348 KB Output is correct
48 Correct 95 ms 14276 KB Output is correct
49 Correct 97 ms 13964 KB Output is correct
50 Correct 97 ms 13984 KB Output is correct
51 Correct 100 ms 13788 KB Output is correct
52 Correct 95 ms 13764 KB Output is correct
53 Correct 98 ms 13964 KB Output is correct
54 Correct 101 ms 13700 KB Output is correct
55 Correct 83 ms 11924 KB Output is correct
56 Correct 102 ms 13316 KB Output is correct
57 Correct 657 ms 75044 KB Output is correct
58 Correct 646 ms 75044 KB Output is correct
59 Correct 693 ms 74972 KB Output is correct
60 Correct 656 ms 74952 KB Output is correct
61 Correct 654 ms 74904 KB Output is correct
62 Correct 654 ms 74864 KB Output is correct
63 Correct 473 ms 69188 KB Output is correct
64 Correct 481 ms 69100 KB Output is correct
65 Correct 493 ms 71104 KB Output is correct
66 Correct 485 ms 71040 KB Output is correct
67 Correct 489 ms 71012 KB Output is correct
68 Correct 486 ms 71160 KB Output is correct
69 Correct 498 ms 71176 KB Output is correct
70 Correct 517 ms 71132 KB Output is correct
71 Correct 492 ms 71044 KB Output is correct
72 Correct 481 ms 71144 KB Output is correct
73 Correct 502 ms 67808 KB Output is correct
74 Correct 589 ms 68824 KB Output is correct
75 Correct 503 ms 67728 KB Output is correct
76 Correct 524 ms 67664 KB Output is correct
77 Correct 497 ms 67684 KB Output is correct
78 Correct 517 ms 66536 KB Output is correct
79 Correct 439 ms 54728 KB Output is correct
80 Correct 503 ms 66660 KB Output is correct