답안 #540981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
540981 2022-03-22T05:42:35 Z l3nl3 Mountains (NOI20_mountains) C++14
100 / 100
339 ms 46724 KB
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/

#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 1e6;

int n, b[N], p[N], t[N*4], ans;
pair<int, int> a[N];

void clr() {
	for (int i = 1; i < N*4; i++) {
		t[i] = 0;
	}
	return;
}

void upd (int v, int tl, int tr, int p) {
	if (tl == tr) {
		t[v]++;
		return;
	}
	int tm = (tl+tr) / 2;
	if (p <= tm) upd(v+v, tl, tm, p);
	else upd(v+v+1, tm+1, tr, p);
	t[v] = t[v+v] + t[v+v+1];
}

int get (int v, int tl, int tr, int l, int r) {
	if (l <= tl && tr <= r) return t[v];
	if (tr < l || r < tl) return 0;
	int tm = (tl+tr) / 2;
	return get(v+v, tl, tm, l, r) + get(v+v+1, tm+1, tr, l, r);
}

signed main () {
 	//freopen("", "r", stdin);
 	//freopen("", "w", stdout);
 	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a+1, a+n+1);
	int num = 0;
	a[0].first = -100;
	for (int i = 1; i <= n; i++) {
		if (a[i].first > a[i-1].first) num++;
		b[a[i].second] = num;
	}             
	for (int i = 1; i <= n; i++) {
		p[i] = get(1, 1, n, 1, b[i] - 1);
		upd(1, 1, n, b[i]);
	}     
	clr();
	reverse(b+1, b+n+1);
	for (int i = 1; i <= n; i++) {
		int j = n-i+1;
		ans += p[j] * get(1, 1, n, 1, b[i]-1);
		upd(1, 1, n, b[i]);
	}	
	cout << ans;
}       
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 31572 KB Output is correct
2 Correct 200 ms 40948 KB Output is correct
3 Correct 231 ms 46680 KB Output is correct
4 Correct 191 ms 46576 KB Output is correct
5 Correct 210 ms 46568 KB Output is correct
6 Correct 200 ms 46592 KB Output is correct
7 Correct 193 ms 46584 KB Output is correct
8 Correct 208 ms 46668 KB Output is correct
9 Correct 201 ms 46628 KB Output is correct
10 Correct 192 ms 46616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 41096 KB Output is correct
2 Correct 151 ms 40988 KB Output is correct
3 Correct 151 ms 40992 KB Output is correct
4 Correct 145 ms 40972 KB Output is correct
5 Correct 144 ms 41064 KB Output is correct
6 Correct 149 ms 40952 KB Output is correct
7 Correct 147 ms 40980 KB Output is correct
8 Correct 133 ms 40984 KB Output is correct
9 Correct 123 ms 41012 KB Output is correct
10 Correct 12 ms 31572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 41096 KB Output is correct
2 Correct 151 ms 40988 KB Output is correct
3 Correct 151 ms 40992 KB Output is correct
4 Correct 145 ms 40972 KB Output is correct
5 Correct 144 ms 41064 KB Output is correct
6 Correct 149 ms 40952 KB Output is correct
7 Correct 147 ms 40980 KB Output is correct
8 Correct 133 ms 40984 KB Output is correct
9 Correct 123 ms 41012 KB Output is correct
10 Correct 12 ms 31572 KB Output is correct
11 Correct 214 ms 41888 KB Output is correct
12 Correct 219 ms 41884 KB Output is correct
13 Correct 198 ms 41780 KB Output is correct
14 Correct 199 ms 41892 KB Output is correct
15 Correct 201 ms 41884 KB Output is correct
16 Correct 190 ms 41888 KB Output is correct
17 Correct 202 ms 41892 KB Output is correct
18 Correct 137 ms 41836 KB Output is correct
19 Correct 134 ms 41804 KB Output is correct
20 Correct 12 ms 31572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 31624 KB Output is correct
2 Correct 13 ms 31572 KB Output is correct
3 Correct 11 ms 31572 KB Output is correct
4 Correct 14 ms 31572 KB Output is correct
5 Correct 17 ms 31668 KB Output is correct
6 Correct 13 ms 31596 KB Output is correct
7 Correct 13 ms 31608 KB Output is correct
8 Correct 13 ms 31572 KB Output is correct
9 Correct 12 ms 31572 KB Output is correct
10 Correct 13 ms 31572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 31624 KB Output is correct
2 Correct 13 ms 31572 KB Output is correct
3 Correct 11 ms 31572 KB Output is correct
4 Correct 14 ms 31572 KB Output is correct
5 Correct 17 ms 31668 KB Output is correct
6 Correct 13 ms 31596 KB Output is correct
7 Correct 13 ms 31608 KB Output is correct
8 Correct 13 ms 31572 KB Output is correct
9 Correct 12 ms 31572 KB Output is correct
10 Correct 13 ms 31572 KB Output is correct
11 Correct 20 ms 31888 KB Output is correct
12 Correct 26 ms 31952 KB Output is correct
13 Correct 22 ms 31956 KB Output is correct
14 Correct 21 ms 31956 KB Output is correct
15 Correct 21 ms 31956 KB Output is correct
16 Correct 20 ms 31888 KB Output is correct
17 Correct 22 ms 31864 KB Output is correct
18 Correct 21 ms 31956 KB Output is correct
19 Correct 18 ms 31956 KB Output is correct
20 Correct 12 ms 31576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 41096 KB Output is correct
2 Correct 151 ms 40988 KB Output is correct
3 Correct 151 ms 40992 KB Output is correct
4 Correct 145 ms 40972 KB Output is correct
5 Correct 144 ms 41064 KB Output is correct
6 Correct 149 ms 40952 KB Output is correct
7 Correct 147 ms 40980 KB Output is correct
8 Correct 133 ms 40984 KB Output is correct
9 Correct 123 ms 41012 KB Output is correct
10 Correct 12 ms 31572 KB Output is correct
11 Correct 214 ms 41888 KB Output is correct
12 Correct 219 ms 41884 KB Output is correct
13 Correct 198 ms 41780 KB Output is correct
14 Correct 199 ms 41892 KB Output is correct
15 Correct 201 ms 41884 KB Output is correct
16 Correct 190 ms 41888 KB Output is correct
17 Correct 202 ms 41892 KB Output is correct
18 Correct 137 ms 41836 KB Output is correct
19 Correct 134 ms 41804 KB Output is correct
20 Correct 12 ms 31572 KB Output is correct
21 Correct 310 ms 42760 KB Output is correct
22 Correct 264 ms 42760 KB Output is correct
23 Correct 261 ms 42760 KB Output is correct
24 Correct 281 ms 42760 KB Output is correct
25 Correct 271 ms 42840 KB Output is correct
26 Correct 263 ms 42700 KB Output is correct
27 Correct 256 ms 42700 KB Output is correct
28 Correct 162 ms 42796 KB Output is correct
29 Correct 156 ms 42760 KB Output is correct
30 Correct 12 ms 31572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 31572 KB Output is correct
2 Correct 200 ms 40948 KB Output is correct
3 Correct 231 ms 46680 KB Output is correct
4 Correct 191 ms 46576 KB Output is correct
5 Correct 210 ms 46568 KB Output is correct
6 Correct 200 ms 46592 KB Output is correct
7 Correct 193 ms 46584 KB Output is correct
8 Correct 208 ms 46668 KB Output is correct
9 Correct 201 ms 46628 KB Output is correct
10 Correct 192 ms 46616 KB Output is correct
11 Correct 150 ms 41096 KB Output is correct
12 Correct 151 ms 40988 KB Output is correct
13 Correct 151 ms 40992 KB Output is correct
14 Correct 145 ms 40972 KB Output is correct
15 Correct 144 ms 41064 KB Output is correct
16 Correct 149 ms 40952 KB Output is correct
17 Correct 147 ms 40980 KB Output is correct
18 Correct 133 ms 40984 KB Output is correct
19 Correct 123 ms 41012 KB Output is correct
20 Correct 12 ms 31572 KB Output is correct
21 Correct 214 ms 41888 KB Output is correct
22 Correct 219 ms 41884 KB Output is correct
23 Correct 198 ms 41780 KB Output is correct
24 Correct 199 ms 41892 KB Output is correct
25 Correct 201 ms 41884 KB Output is correct
26 Correct 190 ms 41888 KB Output is correct
27 Correct 202 ms 41892 KB Output is correct
28 Correct 137 ms 41836 KB Output is correct
29 Correct 134 ms 41804 KB Output is correct
30 Correct 12 ms 31572 KB Output is correct
31 Correct 12 ms 31624 KB Output is correct
32 Correct 13 ms 31572 KB Output is correct
33 Correct 11 ms 31572 KB Output is correct
34 Correct 14 ms 31572 KB Output is correct
35 Correct 17 ms 31668 KB Output is correct
36 Correct 13 ms 31596 KB Output is correct
37 Correct 13 ms 31608 KB Output is correct
38 Correct 13 ms 31572 KB Output is correct
39 Correct 12 ms 31572 KB Output is correct
40 Correct 13 ms 31572 KB Output is correct
41 Correct 20 ms 31888 KB Output is correct
42 Correct 26 ms 31952 KB Output is correct
43 Correct 22 ms 31956 KB Output is correct
44 Correct 21 ms 31956 KB Output is correct
45 Correct 21 ms 31956 KB Output is correct
46 Correct 20 ms 31888 KB Output is correct
47 Correct 22 ms 31864 KB Output is correct
48 Correct 21 ms 31956 KB Output is correct
49 Correct 18 ms 31956 KB Output is correct
50 Correct 12 ms 31576 KB Output is correct
51 Correct 310 ms 42760 KB Output is correct
52 Correct 264 ms 42760 KB Output is correct
53 Correct 261 ms 42760 KB Output is correct
54 Correct 281 ms 42760 KB Output is correct
55 Correct 271 ms 42840 KB Output is correct
56 Correct 263 ms 42700 KB Output is correct
57 Correct 256 ms 42700 KB Output is correct
58 Correct 162 ms 42796 KB Output is correct
59 Correct 156 ms 42760 KB Output is correct
60 Correct 12 ms 31572 KB Output is correct
61 Correct 323 ms 46724 KB Output is correct
62 Correct 324 ms 46548 KB Output is correct
63 Correct 322 ms 46624 KB Output is correct
64 Correct 310 ms 46632 KB Output is correct
65 Correct 319 ms 46584 KB Output is correct
66 Correct 338 ms 46620 KB Output is correct
67 Correct 339 ms 46580 KB Output is correct
68 Correct 312 ms 46688 KB Output is correct
69 Correct 269 ms 42816 KB Output is correct
70 Correct 12 ms 31572 KB Output is correct