#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
const ll MN = 1000000007;
using namespace std;
ll n;
ll tree[300001];
ll niza[300001];
ll query(ll pos) {
ll ret = 0;
while (pos > 0) {
ret += tree[pos];
pos -= pos&(-pos);
}
return ret;
}
void update(ll pos, ll val) {
while (pos <= n) {
tree[pos] += val;
pos += pos&(-pos);
}
}
ll presmetaj (ll pos) {
ll levo = query(pos-1);
ll site = query(n);
return levo*(site-levo);
}
int main()
{
#if LOCAL_DEBUG
fstream cin("in.txt");
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
MS(tree,0);
cin>>n;
for (ll i = 1; i<=n; i++) cin>>niza[i];
vector<pair<ll,ll>> sorti(n+1);
for (ll i = 1; i<=n; i++) sorti[i] = {niza[i],i};
sort(sorti.begin(),sorti.end());
vector<ll> moment;
ll sea = -1, res = 0;
for (ll i = 1; i<=n; i++) {
ll a = sorti[i].first;
if (a != sea) {
for (auto it:moment) res += presmetaj(it);
for (auto it:moment) update(it,1);
vector<ll> nov;
swap(moment,nov);
}
sea = a;
moment.pb(sorti[i].second);
}
for (auto it:moment) res += presmetaj(it);
cout<<res<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
74 ms |
9712 KB |
Output is correct |
3 |
Correct |
71 ms |
9652 KB |
Output is correct |
4 |
Correct |
66 ms |
9628 KB |
Output is correct |
5 |
Correct |
65 ms |
9692 KB |
Output is correct |
6 |
Correct |
67 ms |
9676 KB |
Output is correct |
7 |
Correct |
66 ms |
9648 KB |
Output is correct |
8 |
Correct |
69 ms |
9704 KB |
Output is correct |
9 |
Correct |
78 ms |
9632 KB |
Output is correct |
10 |
Correct |
82 ms |
9708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
12900 KB |
Output is correct |
2 |
Correct |
50 ms |
13472 KB |
Output is correct |
3 |
Correct |
50 ms |
13464 KB |
Output is correct |
4 |
Correct |
52 ms |
13540 KB |
Output is correct |
5 |
Correct |
52 ms |
13472 KB |
Output is correct |
6 |
Correct |
53 ms |
13536 KB |
Output is correct |
7 |
Correct |
49 ms |
13636 KB |
Output is correct |
8 |
Correct |
41 ms |
13456 KB |
Output is correct |
9 |
Correct |
35 ms |
13408 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
12900 KB |
Output is correct |
2 |
Correct |
50 ms |
13472 KB |
Output is correct |
3 |
Correct |
50 ms |
13464 KB |
Output is correct |
4 |
Correct |
52 ms |
13540 KB |
Output is correct |
5 |
Correct |
52 ms |
13472 KB |
Output is correct |
6 |
Correct |
53 ms |
13536 KB |
Output is correct |
7 |
Correct |
49 ms |
13636 KB |
Output is correct |
8 |
Correct |
41 ms |
13456 KB |
Output is correct |
9 |
Correct |
35 ms |
13408 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
61 ms |
10556 KB |
Output is correct |
12 |
Correct |
61 ms |
10556 KB |
Output is correct |
13 |
Correct |
62 ms |
10556 KB |
Output is correct |
14 |
Correct |
69 ms |
10608 KB |
Output is correct |
15 |
Correct |
62 ms |
10556 KB |
Output is correct |
16 |
Correct |
61 ms |
10556 KB |
Output is correct |
17 |
Correct |
60 ms |
10700 KB |
Output is correct |
18 |
Correct |
39 ms |
10556 KB |
Output is correct |
19 |
Correct |
40 ms |
10624 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2676 KB |
Output is correct |
10 |
Correct |
1 ms |
2676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2676 KB |
Output is correct |
10 |
Correct |
1 ms |
2676 KB |
Output is correct |
11 |
Correct |
5 ms |
3028 KB |
Output is correct |
12 |
Correct |
5 ms |
3056 KB |
Output is correct |
13 |
Correct |
5 ms |
3028 KB |
Output is correct |
14 |
Correct |
5 ms |
3028 KB |
Output is correct |
15 |
Correct |
5 ms |
3028 KB |
Output is correct |
16 |
Correct |
6 ms |
3076 KB |
Output is correct |
17 |
Correct |
4 ms |
3068 KB |
Output is correct |
18 |
Correct |
7 ms |
3068 KB |
Output is correct |
19 |
Correct |
4 ms |
2900 KB |
Output is correct |
20 |
Correct |
1 ms |
2672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
12900 KB |
Output is correct |
2 |
Correct |
50 ms |
13472 KB |
Output is correct |
3 |
Correct |
50 ms |
13464 KB |
Output is correct |
4 |
Correct |
52 ms |
13540 KB |
Output is correct |
5 |
Correct |
52 ms |
13472 KB |
Output is correct |
6 |
Correct |
53 ms |
13536 KB |
Output is correct |
7 |
Correct |
49 ms |
13636 KB |
Output is correct |
8 |
Correct |
41 ms |
13456 KB |
Output is correct |
9 |
Correct |
35 ms |
13408 KB |
Output is correct |
10 |
Correct |
1 ms |
2644 KB |
Output is correct |
11 |
Correct |
61 ms |
10556 KB |
Output is correct |
12 |
Correct |
61 ms |
10556 KB |
Output is correct |
13 |
Correct |
62 ms |
10556 KB |
Output is correct |
14 |
Correct |
69 ms |
10608 KB |
Output is correct |
15 |
Correct |
62 ms |
10556 KB |
Output is correct |
16 |
Correct |
61 ms |
10556 KB |
Output is correct |
17 |
Correct |
60 ms |
10700 KB |
Output is correct |
18 |
Correct |
39 ms |
10556 KB |
Output is correct |
19 |
Correct |
40 ms |
10624 KB |
Output is correct |
20 |
Correct |
2 ms |
2644 KB |
Output is correct |
21 |
Correct |
75 ms |
11340 KB |
Output is correct |
22 |
Correct |
74 ms |
11340 KB |
Output is correct |
23 |
Correct |
73 ms |
11436 KB |
Output is correct |
24 |
Correct |
79 ms |
11384 KB |
Output is correct |
25 |
Correct |
84 ms |
11440 KB |
Output is correct |
26 |
Correct |
80 ms |
11436 KB |
Output is correct |
27 |
Correct |
74 ms |
11328 KB |
Output is correct |
28 |
Correct |
48 ms |
11340 KB |
Output is correct |
29 |
Correct |
48 ms |
11412 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
74 ms |
9712 KB |
Output is correct |
3 |
Correct |
71 ms |
9652 KB |
Output is correct |
4 |
Correct |
66 ms |
9628 KB |
Output is correct |
5 |
Correct |
65 ms |
9692 KB |
Output is correct |
6 |
Correct |
67 ms |
9676 KB |
Output is correct |
7 |
Correct |
66 ms |
9648 KB |
Output is correct |
8 |
Correct |
69 ms |
9704 KB |
Output is correct |
9 |
Correct |
78 ms |
9632 KB |
Output is correct |
10 |
Correct |
82 ms |
9708 KB |
Output is correct |
11 |
Correct |
50 ms |
12900 KB |
Output is correct |
12 |
Correct |
50 ms |
13472 KB |
Output is correct |
13 |
Correct |
50 ms |
13464 KB |
Output is correct |
14 |
Correct |
52 ms |
13540 KB |
Output is correct |
15 |
Correct |
52 ms |
13472 KB |
Output is correct |
16 |
Correct |
53 ms |
13536 KB |
Output is correct |
17 |
Correct |
49 ms |
13636 KB |
Output is correct |
18 |
Correct |
41 ms |
13456 KB |
Output is correct |
19 |
Correct |
35 ms |
13408 KB |
Output is correct |
20 |
Correct |
1 ms |
2644 KB |
Output is correct |
21 |
Correct |
61 ms |
10556 KB |
Output is correct |
22 |
Correct |
61 ms |
10556 KB |
Output is correct |
23 |
Correct |
62 ms |
10556 KB |
Output is correct |
24 |
Correct |
69 ms |
10608 KB |
Output is correct |
25 |
Correct |
62 ms |
10556 KB |
Output is correct |
26 |
Correct |
61 ms |
10556 KB |
Output is correct |
27 |
Correct |
60 ms |
10700 KB |
Output is correct |
28 |
Correct |
39 ms |
10556 KB |
Output is correct |
29 |
Correct |
40 ms |
10624 KB |
Output is correct |
30 |
Correct |
2 ms |
2644 KB |
Output is correct |
31 |
Correct |
2 ms |
2644 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2644 KB |
Output is correct |
35 |
Correct |
1 ms |
2644 KB |
Output is correct |
36 |
Correct |
1 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
1 ms |
2644 KB |
Output is correct |
39 |
Correct |
2 ms |
2676 KB |
Output is correct |
40 |
Correct |
1 ms |
2676 KB |
Output is correct |
41 |
Correct |
5 ms |
3028 KB |
Output is correct |
42 |
Correct |
5 ms |
3056 KB |
Output is correct |
43 |
Correct |
5 ms |
3028 KB |
Output is correct |
44 |
Correct |
5 ms |
3028 KB |
Output is correct |
45 |
Correct |
5 ms |
3028 KB |
Output is correct |
46 |
Correct |
6 ms |
3076 KB |
Output is correct |
47 |
Correct |
4 ms |
3068 KB |
Output is correct |
48 |
Correct |
7 ms |
3068 KB |
Output is correct |
49 |
Correct |
4 ms |
2900 KB |
Output is correct |
50 |
Correct |
1 ms |
2672 KB |
Output is correct |
51 |
Correct |
75 ms |
11340 KB |
Output is correct |
52 |
Correct |
74 ms |
11340 KB |
Output is correct |
53 |
Correct |
73 ms |
11436 KB |
Output is correct |
54 |
Correct |
79 ms |
11384 KB |
Output is correct |
55 |
Correct |
84 ms |
11440 KB |
Output is correct |
56 |
Correct |
80 ms |
11436 KB |
Output is correct |
57 |
Correct |
74 ms |
11328 KB |
Output is correct |
58 |
Correct |
48 ms |
11340 KB |
Output is correct |
59 |
Correct |
48 ms |
11412 KB |
Output is correct |
60 |
Correct |
2 ms |
2644 KB |
Output is correct |
61 |
Correct |
120 ms |
15228 KB |
Output is correct |
62 |
Correct |
125 ms |
15264 KB |
Output is correct |
63 |
Correct |
114 ms |
15244 KB |
Output is correct |
64 |
Correct |
95 ms |
15240 KB |
Output is correct |
65 |
Correct |
124 ms |
15248 KB |
Output is correct |
66 |
Correct |
122 ms |
15208 KB |
Output is correct |
67 |
Correct |
96 ms |
15204 KB |
Output is correct |
68 |
Correct |
111 ms |
15272 KB |
Output is correct |
69 |
Correct |
80 ms |
11560 KB |
Output is correct |
70 |
Correct |
2 ms |
2644 KB |
Output is correct |