#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;
const int MAXN = 3e5 + 5;
int N, L[MAXN], R[MAXN];
vector <long long> nen;
long long a[MAXN];
struct BIT{
int bit[MAXN];
void upd(int x, int val) {for (; x <= N; x += x &-x) bit[x] += val;}
int get(int x) {
int ans = 0;
for (; x; x -= x&-x) ans += bit[x];
return ans;
}
} mybit;
void calc(int *val) {
FOR(i, 1, N) {
val[i] = mybit.get(a[i] - 1);
mybit.upd(a[i], 1);
}
FOR(i, 1, N) {
mybit.upd(a[i], -1);
}
}
signed main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
//file("TASK");
cin >> N;
FOR(i, 1, N) cin >> a[i], nen.emplace_back(a[i]);
sort(ALL(nen)); nen.erase(unique(ALL(nen)), nen.end());
FOR(i, 1, N) a[i] = lower_bound(ALL(nen), a[i]) - nen.begin() + 1;
calc(L);
reverse(a + 1, a + N + 1);
calc(R);
reverse(R + 1, R + N + 1);
long long ans = 0;
FOR(i, 1, N) ans += 1ll * L[i] * R[i];
cout << ans;
cerr << "Time elapsed: " << TIME << " s.\n";
return (0 ^ 0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
94 ms |
14144 KB |
Output is correct |
3 |
Correct |
94 ms |
14164 KB |
Output is correct |
4 |
Correct |
94 ms |
14112 KB |
Output is correct |
5 |
Correct |
95 ms |
14084 KB |
Output is correct |
6 |
Correct |
97 ms |
14232 KB |
Output is correct |
7 |
Correct |
99 ms |
14100 KB |
Output is correct |
8 |
Correct |
103 ms |
14136 KB |
Output is correct |
9 |
Correct |
93 ms |
13756 KB |
Output is correct |
10 |
Correct |
94 ms |
13668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
8124 KB |
Output is correct |
2 |
Correct |
71 ms |
8060 KB |
Output is correct |
3 |
Correct |
70 ms |
8068 KB |
Output is correct |
4 |
Correct |
69 ms |
8056 KB |
Output is correct |
5 |
Correct |
70 ms |
8120 KB |
Output is correct |
6 |
Correct |
70 ms |
8120 KB |
Output is correct |
7 |
Correct |
72 ms |
8004 KB |
Output is correct |
8 |
Correct |
65 ms |
8112 KB |
Output is correct |
9 |
Correct |
65 ms |
8084 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
8124 KB |
Output is correct |
2 |
Correct |
71 ms |
8060 KB |
Output is correct |
3 |
Correct |
70 ms |
8068 KB |
Output is correct |
4 |
Correct |
69 ms |
8056 KB |
Output is correct |
5 |
Correct |
70 ms |
8120 KB |
Output is correct |
6 |
Correct |
70 ms |
8120 KB |
Output is correct |
7 |
Correct |
72 ms |
8004 KB |
Output is correct |
8 |
Correct |
65 ms |
8112 KB |
Output is correct |
9 |
Correct |
65 ms |
8084 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
79 ms |
8312 KB |
Output is correct |
12 |
Correct |
81 ms |
8368 KB |
Output is correct |
13 |
Correct |
82 ms |
8328 KB |
Output is correct |
14 |
Correct |
78 ms |
8328 KB |
Output is correct |
15 |
Correct |
79 ms |
8384 KB |
Output is correct |
16 |
Correct |
78 ms |
8316 KB |
Output is correct |
17 |
Correct |
79 ms |
8308 KB |
Output is correct |
18 |
Correct |
62 ms |
8372 KB |
Output is correct |
19 |
Correct |
57 ms |
8320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
5 ms |
856 KB |
Output is correct |
12 |
Correct |
5 ms |
860 KB |
Output is correct |
13 |
Correct |
4 ms |
860 KB |
Output is correct |
14 |
Correct |
5 ms |
924 KB |
Output is correct |
15 |
Correct |
5 ms |
852 KB |
Output is correct |
16 |
Correct |
5 ms |
852 KB |
Output is correct |
17 |
Correct |
4 ms |
852 KB |
Output is correct |
18 |
Correct |
5 ms |
852 KB |
Output is correct |
19 |
Correct |
4 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
8124 KB |
Output is correct |
2 |
Correct |
71 ms |
8060 KB |
Output is correct |
3 |
Correct |
70 ms |
8068 KB |
Output is correct |
4 |
Correct |
69 ms |
8056 KB |
Output is correct |
5 |
Correct |
70 ms |
8120 KB |
Output is correct |
6 |
Correct |
70 ms |
8120 KB |
Output is correct |
7 |
Correct |
72 ms |
8004 KB |
Output is correct |
8 |
Correct |
65 ms |
8112 KB |
Output is correct |
9 |
Correct |
65 ms |
8084 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
79 ms |
8312 KB |
Output is correct |
12 |
Correct |
81 ms |
8368 KB |
Output is correct |
13 |
Correct |
82 ms |
8328 KB |
Output is correct |
14 |
Correct |
78 ms |
8328 KB |
Output is correct |
15 |
Correct |
79 ms |
8384 KB |
Output is correct |
16 |
Correct |
78 ms |
8316 KB |
Output is correct |
17 |
Correct |
79 ms |
8308 KB |
Output is correct |
18 |
Correct |
62 ms |
8372 KB |
Output is correct |
19 |
Correct |
57 ms |
8320 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
129 ms |
9556 KB |
Output is correct |
22 |
Correct |
119 ms |
9576 KB |
Output is correct |
23 |
Correct |
112 ms |
9528 KB |
Output is correct |
24 |
Correct |
113 ms |
9576 KB |
Output is correct |
25 |
Correct |
112 ms |
9580 KB |
Output is correct |
26 |
Correct |
114 ms |
9612 KB |
Output is correct |
27 |
Correct |
115 ms |
9600 KB |
Output is correct |
28 |
Correct |
65 ms |
9504 KB |
Output is correct |
29 |
Correct |
64 ms |
9528 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
94 ms |
14144 KB |
Output is correct |
3 |
Correct |
94 ms |
14164 KB |
Output is correct |
4 |
Correct |
94 ms |
14112 KB |
Output is correct |
5 |
Correct |
95 ms |
14084 KB |
Output is correct |
6 |
Correct |
97 ms |
14232 KB |
Output is correct |
7 |
Correct |
99 ms |
14100 KB |
Output is correct |
8 |
Correct |
103 ms |
14136 KB |
Output is correct |
9 |
Correct |
93 ms |
13756 KB |
Output is correct |
10 |
Correct |
94 ms |
13668 KB |
Output is correct |
11 |
Correct |
70 ms |
8124 KB |
Output is correct |
12 |
Correct |
71 ms |
8060 KB |
Output is correct |
13 |
Correct |
70 ms |
8068 KB |
Output is correct |
14 |
Correct |
69 ms |
8056 KB |
Output is correct |
15 |
Correct |
70 ms |
8120 KB |
Output is correct |
16 |
Correct |
70 ms |
8120 KB |
Output is correct |
17 |
Correct |
72 ms |
8004 KB |
Output is correct |
18 |
Correct |
65 ms |
8112 KB |
Output is correct |
19 |
Correct |
65 ms |
8084 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
79 ms |
8312 KB |
Output is correct |
22 |
Correct |
81 ms |
8368 KB |
Output is correct |
23 |
Correct |
82 ms |
8328 KB |
Output is correct |
24 |
Correct |
78 ms |
8328 KB |
Output is correct |
25 |
Correct |
79 ms |
8384 KB |
Output is correct |
26 |
Correct |
78 ms |
8316 KB |
Output is correct |
27 |
Correct |
79 ms |
8308 KB |
Output is correct |
28 |
Correct |
62 ms |
8372 KB |
Output is correct |
29 |
Correct |
57 ms |
8320 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
5 ms |
856 KB |
Output is correct |
42 |
Correct |
5 ms |
860 KB |
Output is correct |
43 |
Correct |
4 ms |
860 KB |
Output is correct |
44 |
Correct |
5 ms |
924 KB |
Output is correct |
45 |
Correct |
5 ms |
852 KB |
Output is correct |
46 |
Correct |
5 ms |
852 KB |
Output is correct |
47 |
Correct |
4 ms |
852 KB |
Output is correct |
48 |
Correct |
5 ms |
852 KB |
Output is correct |
49 |
Correct |
4 ms |
724 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
129 ms |
9556 KB |
Output is correct |
52 |
Correct |
119 ms |
9576 KB |
Output is correct |
53 |
Correct |
112 ms |
9528 KB |
Output is correct |
54 |
Correct |
113 ms |
9576 KB |
Output is correct |
55 |
Correct |
112 ms |
9580 KB |
Output is correct |
56 |
Correct |
114 ms |
9612 KB |
Output is correct |
57 |
Correct |
115 ms |
9600 KB |
Output is correct |
58 |
Correct |
65 ms |
9504 KB |
Output is correct |
59 |
Correct |
64 ms |
9528 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
160 ms |
14340 KB |
Output is correct |
62 |
Correct |
152 ms |
14192 KB |
Output is correct |
63 |
Correct |
153 ms |
14100 KB |
Output is correct |
64 |
Correct |
151 ms |
14212 KB |
Output is correct |
65 |
Correct |
153 ms |
14228 KB |
Output is correct |
66 |
Correct |
152 ms |
14140 KB |
Output is correct |
67 |
Correct |
150 ms |
14156 KB |
Output is correct |
68 |
Correct |
161 ms |
13696 KB |
Output is correct |
69 |
Correct |
118 ms |
9744 KB |
Output is correct |
70 |
Correct |
0 ms |
336 KB |
Output is correct |