#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define int long long
template <typename T>
using pbds_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
pbds_set<int> s;
pbds_set<int> t;
int n;
cin >> n;
int arr[n];
cin >> arr[0];
s.insert(arr[0]);
int demon[n];
demon[0] = 0;
int ans = 0;
for (int i = 1; i < n; i++) {
cin >> arr[i];
demon[i] = s.order_of_key(arr[i]);
s.insert(arr[i]);
}
t.insert(arr[n - 1]);
for (int i = n - 2; i >= 0; i--) {
int a = t.order_of_key(arr[i]);
ans += demon[i] * a;
t.insert(arr[i]);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
703 ms |
48020 KB |
Output is correct |
3 |
Correct |
597 ms |
47992 KB |
Output is correct |
4 |
Correct |
650 ms |
48208 KB |
Output is correct |
5 |
Correct |
625 ms |
47996 KB |
Output is correct |
6 |
Correct |
655 ms |
48252 KB |
Output is correct |
7 |
Correct |
630 ms |
48028 KB |
Output is correct |
8 |
Correct |
700 ms |
48212 KB |
Output is correct |
9 |
Correct |
410 ms |
48208 KB |
Output is correct |
10 |
Correct |
415 ms |
48272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
43212 KB |
Output is correct |
2 |
Correct |
210 ms |
43280 KB |
Output is correct |
3 |
Correct |
214 ms |
43084 KB |
Output is correct |
4 |
Correct |
209 ms |
43088 KB |
Output is correct |
5 |
Correct |
214 ms |
43280 KB |
Output is correct |
6 |
Correct |
202 ms |
43248 KB |
Output is correct |
7 |
Correct |
208 ms |
43088 KB |
Output is correct |
8 |
Correct |
484 ms |
43088 KB |
Output is correct |
9 |
Correct |
471 ms |
43092 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
43212 KB |
Output is correct |
2 |
Correct |
210 ms |
43280 KB |
Output is correct |
3 |
Correct |
214 ms |
43084 KB |
Output is correct |
4 |
Correct |
209 ms |
43088 KB |
Output is correct |
5 |
Correct |
214 ms |
43280 KB |
Output is correct |
6 |
Correct |
202 ms |
43248 KB |
Output is correct |
7 |
Correct |
208 ms |
43088 KB |
Output is correct |
8 |
Correct |
484 ms |
43088 KB |
Output is correct |
9 |
Correct |
471 ms |
43092 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
381 ms |
43464 KB |
Output is correct |
12 |
Correct |
320 ms |
43348 KB |
Output is correct |
13 |
Correct |
315 ms |
43368 KB |
Output is correct |
14 |
Correct |
327 ms |
43400 KB |
Output is correct |
15 |
Correct |
328 ms |
43344 KB |
Output is correct |
16 |
Correct |
313 ms |
43312 KB |
Output is correct |
17 |
Correct |
361 ms |
43640 KB |
Output is correct |
18 |
Correct |
372 ms |
43552 KB |
Output is correct |
19 |
Correct |
366 ms |
43600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
7 ms |
1884 KB |
Output is correct |
12 |
Correct |
9 ms |
1884 KB |
Output is correct |
13 |
Correct |
8 ms |
1884 KB |
Output is correct |
14 |
Correct |
7 ms |
1884 KB |
Output is correct |
15 |
Correct |
7 ms |
1880 KB |
Output is correct |
16 |
Correct |
7 ms |
1884 KB |
Output is correct |
17 |
Correct |
7 ms |
1884 KB |
Output is correct |
18 |
Correct |
7 ms |
1884 KB |
Output is correct |
19 |
Correct |
7 ms |
1884 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
43212 KB |
Output is correct |
2 |
Correct |
210 ms |
43280 KB |
Output is correct |
3 |
Correct |
214 ms |
43084 KB |
Output is correct |
4 |
Correct |
209 ms |
43088 KB |
Output is correct |
5 |
Correct |
214 ms |
43280 KB |
Output is correct |
6 |
Correct |
202 ms |
43248 KB |
Output is correct |
7 |
Correct |
208 ms |
43088 KB |
Output is correct |
8 |
Correct |
484 ms |
43088 KB |
Output is correct |
9 |
Correct |
471 ms |
43092 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
381 ms |
43464 KB |
Output is correct |
12 |
Correct |
320 ms |
43348 KB |
Output is correct |
13 |
Correct |
315 ms |
43368 KB |
Output is correct |
14 |
Correct |
327 ms |
43400 KB |
Output is correct |
15 |
Correct |
328 ms |
43344 KB |
Output is correct |
16 |
Correct |
313 ms |
43312 KB |
Output is correct |
17 |
Correct |
361 ms |
43640 KB |
Output is correct |
18 |
Correct |
372 ms |
43552 KB |
Output is correct |
19 |
Correct |
366 ms |
43600 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
423 ms |
44340 KB |
Output is correct |
22 |
Correct |
406 ms |
44200 KB |
Output is correct |
23 |
Correct |
401 ms |
44388 KB |
Output is correct |
24 |
Correct |
373 ms |
44372 KB |
Output is correct |
25 |
Correct |
402 ms |
44344 KB |
Output is correct |
26 |
Correct |
372 ms |
44672 KB |
Output is correct |
27 |
Correct |
392 ms |
44372 KB |
Output is correct |
28 |
Correct |
377 ms |
44624 KB |
Output is correct |
29 |
Correct |
359 ms |
44204 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
703 ms |
48020 KB |
Output is correct |
3 |
Correct |
597 ms |
47992 KB |
Output is correct |
4 |
Correct |
650 ms |
48208 KB |
Output is correct |
5 |
Correct |
625 ms |
47996 KB |
Output is correct |
6 |
Correct |
655 ms |
48252 KB |
Output is correct |
7 |
Correct |
630 ms |
48028 KB |
Output is correct |
8 |
Correct |
700 ms |
48212 KB |
Output is correct |
9 |
Correct |
410 ms |
48208 KB |
Output is correct |
10 |
Correct |
415 ms |
48272 KB |
Output is correct |
11 |
Correct |
206 ms |
43212 KB |
Output is correct |
12 |
Correct |
210 ms |
43280 KB |
Output is correct |
13 |
Correct |
214 ms |
43084 KB |
Output is correct |
14 |
Correct |
209 ms |
43088 KB |
Output is correct |
15 |
Correct |
214 ms |
43280 KB |
Output is correct |
16 |
Correct |
202 ms |
43248 KB |
Output is correct |
17 |
Correct |
208 ms |
43088 KB |
Output is correct |
18 |
Correct |
484 ms |
43088 KB |
Output is correct |
19 |
Correct |
471 ms |
43092 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
381 ms |
43464 KB |
Output is correct |
22 |
Correct |
320 ms |
43348 KB |
Output is correct |
23 |
Correct |
315 ms |
43368 KB |
Output is correct |
24 |
Correct |
327 ms |
43400 KB |
Output is correct |
25 |
Correct |
328 ms |
43344 KB |
Output is correct |
26 |
Correct |
313 ms |
43312 KB |
Output is correct |
27 |
Correct |
361 ms |
43640 KB |
Output is correct |
28 |
Correct |
372 ms |
43552 KB |
Output is correct |
29 |
Correct |
366 ms |
43600 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
7 ms |
1884 KB |
Output is correct |
42 |
Correct |
9 ms |
1884 KB |
Output is correct |
43 |
Correct |
8 ms |
1884 KB |
Output is correct |
44 |
Correct |
7 ms |
1884 KB |
Output is correct |
45 |
Correct |
7 ms |
1880 KB |
Output is correct |
46 |
Correct |
7 ms |
1884 KB |
Output is correct |
47 |
Correct |
7 ms |
1884 KB |
Output is correct |
48 |
Correct |
7 ms |
1884 KB |
Output is correct |
49 |
Correct |
7 ms |
1884 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
423 ms |
44340 KB |
Output is correct |
52 |
Correct |
406 ms |
44200 KB |
Output is correct |
53 |
Correct |
401 ms |
44388 KB |
Output is correct |
54 |
Correct |
373 ms |
44372 KB |
Output is correct |
55 |
Correct |
402 ms |
44344 KB |
Output is correct |
56 |
Correct |
372 ms |
44672 KB |
Output is correct |
57 |
Correct |
392 ms |
44372 KB |
Output is correct |
58 |
Correct |
377 ms |
44624 KB |
Output is correct |
59 |
Correct |
359 ms |
44204 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
406 ms |
48240 KB |
Output is correct |
62 |
Correct |
376 ms |
48112 KB |
Output is correct |
63 |
Correct |
392 ms |
48376 KB |
Output is correct |
64 |
Correct |
381 ms |
48212 KB |
Output is correct |
65 |
Correct |
431 ms |
48416 KB |
Output is correct |
66 |
Correct |
402 ms |
48208 KB |
Output is correct |
67 |
Correct |
394 ms |
48100 KB |
Output is correct |
68 |
Correct |
457 ms |
48060 KB |
Output is correct |
69 |
Correct |
458 ms |
44372 KB |
Output is correct |
70 |
Correct |
0 ms |
344 KB |
Output is correct |