답안 #529075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529075 2022-02-22T05:28:58 Z fhvirus Construction of Highway (JOI18_construction) C++17
16 / 100
2000 ms 8336 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll; typedef pair<int, int> pii;
#define pb emplace_back
#define AI(x) begin(x),end(x)
#define ff first
#define ss second
#ifdef OWO
#define debug(args...) LKJ("\033[0;32m[ " + string(#args) + " ]\033[0m", args)
template <class I> void LKJ(I&&x) { cerr << x << endl; }
template <class I, class...T> void LKJ(I&&x, T&&...t) { cerr << x << ", "; LKJ(t...); }
template <class I> void OI(I a, I b) { while (a < b) cerr << *a << " \n"[next(a) == b]; }
#else
#define debug(...) 0
#define OI(...) 0
#endif

struct LISAN : vector<int> {
	void done() { sort(AI()); erase(unique(AI()), end()); }
	int operator () (const int& v) const { return lower_bound(AI(), v) - begin(); }
};
struct BIT {
	int n; vector<int> val;
	BIT(int _n = 0): n(_n), val(n + 1, 0) {}
	void modify(int p, int v) {
		for (; p <= n; p += p & -p)
			val[p] += v;
	}
	int query(int p) {
		int r = 0;
		for (; p > 0; p -= p & -p)
			r += val[p];
		return r;
	}
} bit;

const int kN = 100'001;
int N, C[kN], A[kN], B[kN];
int par[kN];
vector<int> chi[kN];

int get_inversion(vector<int>& val) {
	int ans = 0;
	for (int &i: val) {
		ans += bit.query(i - 1);
		bit.modify(i, 1);
	}
	for (int &i: val)
		bit.modify(i, -1);
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> N;
	LISAN lisan;
	for (int i = 1; i <= N; ++i) {
		cin >> C[i];
		lisan.pb(C[i]);
	}
	lisan.done();
	for (int i = 1; i <= N; ++i)
		C[i] = lisan(C[i]) + 1;
	bit = BIT(lisan.size());
	for (int i = 1; i < N; ++i) {
		cin >> A[i] >> B[i];
		par[B[i]] = A[i];
		chi[A[i]].pb(B[i]);
	}

	for (int i = 1; i < N; ++i) {
		int u = A[i];
		vector<int> val;
		do {
			val.pb(C[u]);
			u = par[u];
		} while (u != 0);

		cout << get_inversion(val) << '\n';

		// set value for 1 -> B[j];
		u = A[i];
		do {
			C[u] = C[B[i]];
			u = par[u];
		} while (u != 0);
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 6 ms 2636 KB Output is correct
9 Correct 6 ms 2712 KB Output is correct
10 Correct 5 ms 2712 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2704 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2684 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 5 ms 2636 KB Output is correct
27 Correct 4 ms 2636 KB Output is correct
28 Correct 3 ms 2636 KB Output is correct
29 Correct 3 ms 2636 KB Output is correct
30 Correct 2 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 3 ms 2636 KB Output is correct
33 Correct 3 ms 2636 KB Output is correct
34 Correct 2 ms 2636 KB Output is correct
35 Correct 2 ms 2636 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 3 ms 2636 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 2 ms 2636 KB Output is correct
40 Correct 3 ms 2636 KB Output is correct
41 Correct 2 ms 2636 KB Output is correct
42 Correct 2 ms 2636 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 6 ms 2636 KB Output is correct
9 Correct 6 ms 2712 KB Output is correct
10 Correct 5 ms 2712 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2704 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2684 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 5 ms 2636 KB Output is correct
27 Correct 4 ms 2636 KB Output is correct
28 Correct 3 ms 2636 KB Output is correct
29 Correct 3 ms 2636 KB Output is correct
30 Correct 2 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 3 ms 2636 KB Output is correct
33 Correct 3 ms 2636 KB Output is correct
34 Correct 2 ms 2636 KB Output is correct
35 Correct 2 ms 2636 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 3 ms 2636 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 2 ms 2636 KB Output is correct
40 Correct 3 ms 2636 KB Output is correct
41 Correct 2 ms 2636 KB Output is correct
42 Correct 2 ms 2636 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2636 KB Output is correct
46 Correct 5 ms 2764 KB Output is correct
47 Correct 5 ms 2840 KB Output is correct
48 Correct 6 ms 2764 KB Output is correct
49 Correct 218 ms 2924 KB Output is correct
50 Correct 237 ms 2920 KB Output is correct
51 Correct 217 ms 3028 KB Output is correct
52 Correct 108 ms 2764 KB Output is correct
53 Correct 111 ms 2840 KB Output is correct
54 Correct 113 ms 2852 KB Output is correct
55 Correct 117 ms 2764 KB Output is correct
56 Correct 112 ms 2848 KB Output is correct
57 Correct 5 ms 2764 KB Output is correct
58 Correct 6 ms 2764 KB Output is correct
59 Correct 6 ms 2764 KB Output is correct
60 Correct 6 ms 2764 KB Output is correct
61 Correct 111 ms 2840 KB Output is correct
62 Correct 109 ms 2860 KB Output is correct
63 Correct 115 ms 2856 KB Output is correct
64 Correct 4 ms 2764 KB Output is correct
65 Correct 4 ms 2764 KB Output is correct
66 Correct 5 ms 2764 KB Output is correct
67 Correct 6 ms 2764 KB Output is correct
68 Correct 148 ms 2900 KB Output is correct
69 Correct 109 ms 2848 KB Output is correct
70 Correct 79 ms 2840 KB Output is correct
71 Correct 79 ms 2840 KB Output is correct
72 Correct 6 ms 2764 KB Output is correct
73 Correct 5 ms 2764 KB Output is correct
74 Correct 82 ms 2844 KB Output is correct
75 Correct 57 ms 2764 KB Output is correct
76 Correct 40 ms 2848 KB Output is correct
77 Correct 30 ms 2764 KB Output is correct
78 Correct 40 ms 2836 KB Output is correct
79 Correct 30 ms 2764 KB Output is correct
80 Correct 22 ms 2836 KB Output is correct
81 Correct 61 ms 2844 KB Output is correct
82 Correct 40 ms 2844 KB Output is correct
83 Correct 31 ms 2844 KB Output is correct
84 Correct 40 ms 2836 KB Output is correct
85 Correct 28 ms 2764 KB Output is correct
86 Correct 25 ms 2832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 2 ms 2636 KB Output is correct
8 Correct 6 ms 2636 KB Output is correct
9 Correct 6 ms 2712 KB Output is correct
10 Correct 5 ms 2712 KB Output is correct
11 Correct 3 ms 2636 KB Output is correct
12 Correct 3 ms 2636 KB Output is correct
13 Correct 3 ms 2636 KB Output is correct
14 Correct 3 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2704 KB Output is correct
17 Correct 2 ms 2636 KB Output is correct
18 Correct 2 ms 2684 KB Output is correct
19 Correct 3 ms 2636 KB Output is correct
20 Correct 3 ms 2636 KB Output is correct
21 Correct 3 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 2 ms 2636 KB Output is correct
24 Correct 2 ms 2636 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 5 ms 2636 KB Output is correct
27 Correct 4 ms 2636 KB Output is correct
28 Correct 3 ms 2636 KB Output is correct
29 Correct 3 ms 2636 KB Output is correct
30 Correct 2 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 3 ms 2636 KB Output is correct
33 Correct 3 ms 2636 KB Output is correct
34 Correct 2 ms 2636 KB Output is correct
35 Correct 2 ms 2636 KB Output is correct
36 Correct 2 ms 2636 KB Output is correct
37 Correct 3 ms 2636 KB Output is correct
38 Correct 2 ms 2636 KB Output is correct
39 Correct 2 ms 2636 KB Output is correct
40 Correct 3 ms 2636 KB Output is correct
41 Correct 2 ms 2636 KB Output is correct
42 Correct 2 ms 2636 KB Output is correct
43 Correct 2 ms 2636 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2636 KB Output is correct
46 Correct 5 ms 2764 KB Output is correct
47 Correct 5 ms 2840 KB Output is correct
48 Correct 6 ms 2764 KB Output is correct
49 Correct 218 ms 2924 KB Output is correct
50 Correct 237 ms 2920 KB Output is correct
51 Correct 217 ms 3028 KB Output is correct
52 Correct 108 ms 2764 KB Output is correct
53 Correct 111 ms 2840 KB Output is correct
54 Correct 113 ms 2852 KB Output is correct
55 Correct 117 ms 2764 KB Output is correct
56 Correct 112 ms 2848 KB Output is correct
57 Correct 5 ms 2764 KB Output is correct
58 Correct 6 ms 2764 KB Output is correct
59 Correct 6 ms 2764 KB Output is correct
60 Correct 6 ms 2764 KB Output is correct
61 Correct 111 ms 2840 KB Output is correct
62 Correct 109 ms 2860 KB Output is correct
63 Correct 115 ms 2856 KB Output is correct
64 Correct 4 ms 2764 KB Output is correct
65 Correct 4 ms 2764 KB Output is correct
66 Correct 5 ms 2764 KB Output is correct
67 Correct 6 ms 2764 KB Output is correct
68 Correct 148 ms 2900 KB Output is correct
69 Correct 109 ms 2848 KB Output is correct
70 Correct 79 ms 2840 KB Output is correct
71 Correct 79 ms 2840 KB Output is correct
72 Correct 6 ms 2764 KB Output is correct
73 Correct 5 ms 2764 KB Output is correct
74 Correct 82 ms 2844 KB Output is correct
75 Correct 57 ms 2764 KB Output is correct
76 Correct 40 ms 2848 KB Output is correct
77 Correct 30 ms 2764 KB Output is correct
78 Correct 40 ms 2836 KB Output is correct
79 Correct 30 ms 2764 KB Output is correct
80 Correct 22 ms 2836 KB Output is correct
81 Correct 61 ms 2844 KB Output is correct
82 Correct 40 ms 2844 KB Output is correct
83 Correct 31 ms 2844 KB Output is correct
84 Correct 40 ms 2836 KB Output is correct
85 Correct 28 ms 2764 KB Output is correct
86 Correct 25 ms 2832 KB Output is correct
87 Correct 16 ms 3092 KB Output is correct
88 Correct 42 ms 3936 KB Output is correct
89 Correct 137 ms 6904 KB Output is correct
90 Correct 125 ms 6852 KB Output is correct
91 Correct 132 ms 6788 KB Output is correct
92 Execution timed out 2070 ms 8336 KB Time limit exceeded
93 Halted 0 ms 0 KB -