# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1095357 | 2024-10-02T01:55:17 Z | kh0i | Mountains (NOI20_mountains) | C++17 | 140 ms | 19460 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define F first #define S second #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll get_rand(ll l, ll r){ assert(l <= r); return uniform_int_distribution<ll>(l, r)(rng); } const int N = 3e5 + 3; struct Fenwick{ #define gb(x) (x) & -(x) int n; vector<ll> bit; Fenwick(int n) : n(n), bit(n + 2) {} void add(int pos, ll x){ for(; pos <= n; pos += gb(pos)) bit[pos] += x; } ll get(int l, int r){ ll res = 0; --l; for(; r > 0; r -= gb(r)) res += bit[r]; for(; l > 0; l -= gb(l)) res -= bit[l]; return res; } }; int n; ll a[N], r[N]; vector<ll> xx; void solve(){ cin >> n; for(int i = 1; i <= n; ++i){ cin >> a[i]; xx.push_back(a[i]); } sort(all(xx)); xx.resize(unique(all(xx)) - xx.begin()); for(int i = 1; i <= n; ++i) a[i] = lower_bound(all(xx), a[i]) - xx.begin() + 1; Fenwick fi(n); for(int i = n; i >= 1; --i){ r[i] = fi.get(1, a[i] - 1); fi.add(a[i], 1); } Fenwick se(n); ll res = 0; for(int i = 1; i <= n; ++i){ res += se.get(1, a[i] - 1) * r[i]; se.add(a[i], 1); } cout << res; } signed main(){ cin.tie(nullptr)->sync_with_stdio(false); #define task "troll" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } solve(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 63 ms | 17648 KB | Output is correct |
3 | Correct | 61 ms | 18628 KB | Output is correct |
4 | Correct | 63 ms | 18876 KB | Output is correct |
5 | Correct | 62 ms | 18112 KB | Output is correct |
6 | Correct | 63 ms | 18112 KB | Output is correct |
7 | Correct | 62 ms | 18416 KB | Output is correct |
8 | Correct | 67 ms | 18484 KB | Output is correct |
9 | Correct | 67 ms | 19132 KB | Output is correct |
10 | Correct | 65 ms | 18808 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 14204 KB | Output is correct |
2 | Correct | 50 ms | 13256 KB | Output is correct |
3 | Correct | 48 ms | 12744 KB | Output is correct |
4 | Correct | 49 ms | 12716 KB | Output is correct |
5 | Correct | 47 ms | 12736 KB | Output is correct |
6 | Correct | 49 ms | 13704 KB | Output is correct |
7 | Correct | 46 ms | 13700 KB | Output is correct |
8 | Correct | 44 ms | 13768 KB | Output is correct |
9 | Correct | 46 ms | 14272 KB | Output is correct |
10 | Correct | 0 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 14204 KB | Output is correct |
2 | Correct | 50 ms | 13256 KB | Output is correct |
3 | Correct | 48 ms | 12744 KB | Output is correct |
4 | Correct | 49 ms | 12716 KB | Output is correct |
5 | Correct | 47 ms | 12736 KB | Output is correct |
6 | Correct | 49 ms | 13704 KB | Output is correct |
7 | Correct | 46 ms | 13700 KB | Output is correct |
8 | Correct | 44 ms | 13768 KB | Output is correct |
9 | Correct | 46 ms | 14272 KB | Output is correct |
10 | Correct | 0 ms | 2396 KB | Output is correct |
11 | Correct | 53 ms | 13256 KB | Output is correct |
12 | Correct | 55 ms | 14268 KB | Output is correct |
13 | Correct | 54 ms | 14528 KB | Output is correct |
14 | Correct | 53 ms | 13500 KB | Output is correct |
15 | Correct | 55 ms | 12988 KB | Output is correct |
16 | Correct | 53 ms | 13408 KB | Output is correct |
17 | Correct | 52 ms | 13688 KB | Output is correct |
18 | Correct | 47 ms | 14292 KB | Output is correct |
19 | Correct | 42 ms | 14792 KB | Output is correct |
20 | Correct | 0 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2396 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2396 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 1 ms | 2396 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
11 | Correct | 3 ms | 2908 KB | Output is correct |
12 | Correct | 3 ms | 2904 KB | Output is correct |
13 | Correct | 4 ms | 2908 KB | Output is correct |
14 | Correct | 4 ms | 2920 KB | Output is correct |
15 | Correct | 4 ms | 2908 KB | Output is correct |
16 | Correct | 3 ms | 3072 KB | Output is correct |
17 | Correct | 3 ms | 2908 KB | Output is correct |
18 | Correct | 3 ms | 2908 KB | Output is correct |
19 | Correct | 3 ms | 2908 KB | Output is correct |
20 | Correct | 0 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 14204 KB | Output is correct |
2 | Correct | 50 ms | 13256 KB | Output is correct |
3 | Correct | 48 ms | 12744 KB | Output is correct |
4 | Correct | 49 ms | 12716 KB | Output is correct |
5 | Correct | 47 ms | 12736 KB | Output is correct |
6 | Correct | 49 ms | 13704 KB | Output is correct |
7 | Correct | 46 ms | 13700 KB | Output is correct |
8 | Correct | 44 ms | 13768 KB | Output is correct |
9 | Correct | 46 ms | 14272 KB | Output is correct |
10 | Correct | 0 ms | 2396 KB | Output is correct |
11 | Correct | 53 ms | 13256 KB | Output is correct |
12 | Correct | 55 ms | 14268 KB | Output is correct |
13 | Correct | 54 ms | 14528 KB | Output is correct |
14 | Correct | 53 ms | 13500 KB | Output is correct |
15 | Correct | 55 ms | 12988 KB | Output is correct |
16 | Correct | 53 ms | 13408 KB | Output is correct |
17 | Correct | 52 ms | 13688 KB | Output is correct |
18 | Correct | 47 ms | 14292 KB | Output is correct |
19 | Correct | 42 ms | 14792 KB | Output is correct |
20 | Correct | 0 ms | 2396 KB | Output is correct |
21 | Correct | 98 ms | 14016 KB | Output is correct |
22 | Correct | 99 ms | 14448 KB | Output is correct |
23 | Correct | 103 ms | 15556 KB | Output is correct |
24 | Correct | 109 ms | 15548 KB | Output is correct |
25 | Correct | 104 ms | 15192 KB | Output is correct |
26 | Correct | 98 ms | 14040 KB | Output is correct |
27 | Correct | 99 ms | 14736 KB | Output is correct |
28 | Correct | 47 ms | 15104 KB | Output is correct |
29 | Correct | 47 ms | 15560 KB | Output is correct |
30 | Correct | 1 ms | 2396 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 63 ms | 17648 KB | Output is correct |
3 | Correct | 61 ms | 18628 KB | Output is correct |
4 | Correct | 63 ms | 18876 KB | Output is correct |
5 | Correct | 62 ms | 18112 KB | Output is correct |
6 | Correct | 63 ms | 18112 KB | Output is correct |
7 | Correct | 62 ms | 18416 KB | Output is correct |
8 | Correct | 67 ms | 18484 KB | Output is correct |
9 | Correct | 67 ms | 19132 KB | Output is correct |
10 | Correct | 65 ms | 18808 KB | Output is correct |
11 | Correct | 53 ms | 14204 KB | Output is correct |
12 | Correct | 50 ms | 13256 KB | Output is correct |
13 | Correct | 48 ms | 12744 KB | Output is correct |
14 | Correct | 49 ms | 12716 KB | Output is correct |
15 | Correct | 47 ms | 12736 KB | Output is correct |
16 | Correct | 49 ms | 13704 KB | Output is correct |
17 | Correct | 46 ms | 13700 KB | Output is correct |
18 | Correct | 44 ms | 13768 KB | Output is correct |
19 | Correct | 46 ms | 14272 KB | Output is correct |
20 | Correct | 0 ms | 2396 KB | Output is correct |
21 | Correct | 53 ms | 13256 KB | Output is correct |
22 | Correct | 55 ms | 14268 KB | Output is correct |
23 | Correct | 54 ms | 14528 KB | Output is correct |
24 | Correct | 53 ms | 13500 KB | Output is correct |
25 | Correct | 55 ms | 12988 KB | Output is correct |
26 | Correct | 53 ms | 13408 KB | Output is correct |
27 | Correct | 52 ms | 13688 KB | Output is correct |
28 | Correct | 47 ms | 14292 KB | Output is correct |
29 | Correct | 42 ms | 14792 KB | Output is correct |
30 | Correct | 0 ms | 2396 KB | Output is correct |
31 | Correct | 1 ms | 2396 KB | Output is correct |
32 | Correct | 0 ms | 2396 KB | Output is correct |
33 | Correct | 1 ms | 2396 KB | Output is correct |
34 | Correct | 1 ms | 2396 KB | Output is correct |
35 | Correct | 1 ms | 2396 KB | Output is correct |
36 | Correct | 1 ms | 2396 KB | Output is correct |
37 | Correct | 1 ms | 2396 KB | Output is correct |
38 | Correct | 1 ms | 2396 KB | Output is correct |
39 | Correct | 1 ms | 2396 KB | Output is correct |
40 | Correct | 1 ms | 2396 KB | Output is correct |
41 | Correct | 3 ms | 2908 KB | Output is correct |
42 | Correct | 3 ms | 2904 KB | Output is correct |
43 | Correct | 4 ms | 2908 KB | Output is correct |
44 | Correct | 4 ms | 2920 KB | Output is correct |
45 | Correct | 4 ms | 2908 KB | Output is correct |
46 | Correct | 3 ms | 3072 KB | Output is correct |
47 | Correct | 3 ms | 2908 KB | Output is correct |
48 | Correct | 3 ms | 2908 KB | Output is correct |
49 | Correct | 3 ms | 2908 KB | Output is correct |
50 | Correct | 0 ms | 2396 KB | Output is correct |
51 | Correct | 98 ms | 14016 KB | Output is correct |
52 | Correct | 99 ms | 14448 KB | Output is correct |
53 | Correct | 103 ms | 15556 KB | Output is correct |
54 | Correct | 109 ms | 15548 KB | Output is correct |
55 | Correct | 104 ms | 15192 KB | Output is correct |
56 | Correct | 98 ms | 14040 KB | Output is correct |
57 | Correct | 99 ms | 14736 KB | Output is correct |
58 | Correct | 47 ms | 15104 KB | Output is correct |
59 | Correct | 47 ms | 15560 KB | Output is correct |
60 | Correct | 1 ms | 2396 KB | Output is correct |
61 | Correct | 133 ms | 19124 KB | Output is correct |
62 | Correct | 140 ms | 19328 KB | Output is correct |
63 | Correct | 130 ms | 19272 KB | Output is correct |
64 | Correct | 139 ms | 19392 KB | Output is correct |
65 | Correct | 122 ms | 18372 KB | Output is correct |
66 | Correct | 121 ms | 18264 KB | Output is correct |
67 | Correct | 132 ms | 19460 KB | Output is correct |
68 | Correct | 120 ms | 17912 KB | Output is correct |
69 | Correct | 101 ms | 15040 KB | Output is correct |
70 | Correct | 1 ms | 2392 KB | Output is correct |