#include <bits/stdc++.h>
using namespace std;
#define oo 1e15
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)
#define int long long
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
typedef pair<pair<long long,long long>,pair<long long,long long>> pllll;
typedef pair<pair<long long,long long>,bool> pllb;
const ll base=361;
const ll mod=998244353;
const ld eps=1e-5;
const ll maxn=1e6;
struct segtree_ele{
int val,l,r;
} segtree[10000009];
ll res;
int sizet,l[400009],a[400009],n,i,cnt;
vector<pll> g;
int getnode(int &x) {
if (x==0) {
sizet++;
x=sizet;
segtree[x]={0,0,0};
}
return x;
}
void update(int id,int l,int r,int u) {
if (l>r||r<u||l>u) {
return;
}
if (l==u&&r==u) {
segtree[id].val++;
return;
}
int mid=(r+l)/2;
if (mid<u) {
update(getnode(segtree[id].r),mid+1,r,u);
}
else {
update(getnode(segtree[id].l),l,mid,u);
}
segtree[id].val=segtree[getnode(segtree[id].l)].val+segtree[getnode(segtree[id].r)].val;
}
int get(int id,int l,int r,int u,int v) {
if (l>r||r<u||l>v) {
return 0;
}
if (u<=l&&r<=v) {
return segtree[id].val;
}
int mid=(r+l)/2;
return get(getnode(segtree[id].l),l,mid,u,v)+get(getnode(segtree[id].r),mid+1,r,u,v);
}
int32_t main(){
IO;
cin>>n;
g.push_back({-1,0});
for (i=1;i<=n;i++) {
cin>>a[i];
g.push_back({a[i],i});
}
sort(g.begin(),g.end());
for (i=1;i<=n;i++) {
if (g[i].fi!=g[i-1].fi) {
cnt++;
}
a[g[i].se]=cnt;
}
sizet=0;
getnode(a[0]);
for (i=1;i<=n;i++) {
//cout<<a[i]<<' ';
l[i]=get(1,1,maxn,1,a[i]-1);
update(1,1,maxn,a[i]);
}
//cout<<'\n';
sizet=0;
a[0]=0;
getnode(a[0]);
for (i=n;i>=1;i--) {
//cout<<l[i]<<' '<<get(1,1,maxn,1,a[i]-1)<<'\n';
res+=ll(l[i])*ll(get(1,1,maxn,1,a[i]-1));
update(1,1,maxn,a[i]);
}
cout<<res<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
312 ms |
29392 KB |
Output is correct |
3 |
Correct |
310 ms |
29356 KB |
Output is correct |
4 |
Correct |
316 ms |
29480 KB |
Output is correct |
5 |
Correct |
315 ms |
29492 KB |
Output is correct |
6 |
Correct |
314 ms |
29540 KB |
Output is correct |
7 |
Correct |
327 ms |
29476 KB |
Output is correct |
8 |
Correct |
318 ms |
29476 KB |
Output is correct |
9 |
Correct |
340 ms |
22588 KB |
Output is correct |
10 |
Correct |
329 ms |
22788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
10640 KB |
Output is correct |
2 |
Correct |
215 ms |
10672 KB |
Output is correct |
3 |
Correct |
214 ms |
10620 KB |
Output is correct |
4 |
Correct |
221 ms |
10744 KB |
Output is correct |
5 |
Correct |
219 ms |
10648 KB |
Output is correct |
6 |
Correct |
218 ms |
10676 KB |
Output is correct |
7 |
Correct |
231 ms |
10688 KB |
Output is correct |
8 |
Correct |
193 ms |
10712 KB |
Output is correct |
9 |
Correct |
191 ms |
10704 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
10640 KB |
Output is correct |
2 |
Correct |
215 ms |
10672 KB |
Output is correct |
3 |
Correct |
214 ms |
10620 KB |
Output is correct |
4 |
Correct |
221 ms |
10744 KB |
Output is correct |
5 |
Correct |
219 ms |
10648 KB |
Output is correct |
6 |
Correct |
218 ms |
10676 KB |
Output is correct |
7 |
Correct |
231 ms |
10688 KB |
Output is correct |
8 |
Correct |
193 ms |
10712 KB |
Output is correct |
9 |
Correct |
191 ms |
10704 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
300 ms |
10648 KB |
Output is correct |
12 |
Correct |
303 ms |
10672 KB |
Output is correct |
13 |
Correct |
297 ms |
10668 KB |
Output is correct |
14 |
Correct |
302 ms |
10676 KB |
Output is correct |
15 |
Correct |
298 ms |
10640 KB |
Output is correct |
16 |
Correct |
296 ms |
10688 KB |
Output is correct |
17 |
Correct |
295 ms |
10620 KB |
Output is correct |
18 |
Correct |
246 ms |
10688 KB |
Output is correct |
19 |
Correct |
254 ms |
10676 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
14 ms |
1360 KB |
Output is correct |
12 |
Correct |
14 ms |
1412 KB |
Output is correct |
13 |
Correct |
14 ms |
1376 KB |
Output is correct |
14 |
Correct |
14 ms |
1360 KB |
Output is correct |
15 |
Correct |
14 ms |
1400 KB |
Output is correct |
16 |
Correct |
14 ms |
1360 KB |
Output is correct |
17 |
Correct |
14 ms |
1344 KB |
Output is correct |
18 |
Correct |
13 ms |
1104 KB |
Output is correct |
19 |
Correct |
11 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
10640 KB |
Output is correct |
2 |
Correct |
215 ms |
10672 KB |
Output is correct |
3 |
Correct |
214 ms |
10620 KB |
Output is correct |
4 |
Correct |
221 ms |
10744 KB |
Output is correct |
5 |
Correct |
219 ms |
10648 KB |
Output is correct |
6 |
Correct |
218 ms |
10676 KB |
Output is correct |
7 |
Correct |
231 ms |
10688 KB |
Output is correct |
8 |
Correct |
193 ms |
10712 KB |
Output is correct |
9 |
Correct |
191 ms |
10704 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
300 ms |
10648 KB |
Output is correct |
12 |
Correct |
303 ms |
10672 KB |
Output is correct |
13 |
Correct |
297 ms |
10668 KB |
Output is correct |
14 |
Correct |
302 ms |
10676 KB |
Output is correct |
15 |
Correct |
298 ms |
10640 KB |
Output is correct |
16 |
Correct |
296 ms |
10688 KB |
Output is correct |
17 |
Correct |
295 ms |
10620 KB |
Output is correct |
18 |
Correct |
246 ms |
10688 KB |
Output is correct |
19 |
Correct |
254 ms |
10676 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
417 ms |
14308 KB |
Output is correct |
22 |
Correct |
434 ms |
14372 KB |
Output is correct |
23 |
Correct |
427 ms |
14244 KB |
Output is correct |
24 |
Correct |
389 ms |
14244 KB |
Output is correct |
25 |
Correct |
422 ms |
14408 KB |
Output is correct |
26 |
Correct |
408 ms |
14252 KB |
Output is correct |
27 |
Correct |
400 ms |
14256 KB |
Output is correct |
28 |
Correct |
269 ms |
14320 KB |
Output is correct |
29 |
Correct |
272 ms |
14240 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
312 ms |
29392 KB |
Output is correct |
3 |
Correct |
310 ms |
29356 KB |
Output is correct |
4 |
Correct |
316 ms |
29480 KB |
Output is correct |
5 |
Correct |
315 ms |
29492 KB |
Output is correct |
6 |
Correct |
314 ms |
29540 KB |
Output is correct |
7 |
Correct |
327 ms |
29476 KB |
Output is correct |
8 |
Correct |
318 ms |
29476 KB |
Output is correct |
9 |
Correct |
340 ms |
22588 KB |
Output is correct |
10 |
Correct |
329 ms |
22788 KB |
Output is correct |
11 |
Correct |
212 ms |
10640 KB |
Output is correct |
12 |
Correct |
215 ms |
10672 KB |
Output is correct |
13 |
Correct |
214 ms |
10620 KB |
Output is correct |
14 |
Correct |
221 ms |
10744 KB |
Output is correct |
15 |
Correct |
219 ms |
10648 KB |
Output is correct |
16 |
Correct |
218 ms |
10676 KB |
Output is correct |
17 |
Correct |
231 ms |
10688 KB |
Output is correct |
18 |
Correct |
193 ms |
10712 KB |
Output is correct |
19 |
Correct |
191 ms |
10704 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
300 ms |
10648 KB |
Output is correct |
22 |
Correct |
303 ms |
10672 KB |
Output is correct |
23 |
Correct |
297 ms |
10668 KB |
Output is correct |
24 |
Correct |
302 ms |
10676 KB |
Output is correct |
25 |
Correct |
298 ms |
10640 KB |
Output is correct |
26 |
Correct |
296 ms |
10688 KB |
Output is correct |
27 |
Correct |
295 ms |
10620 KB |
Output is correct |
28 |
Correct |
246 ms |
10688 KB |
Output is correct |
29 |
Correct |
254 ms |
10676 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
2 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
2 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
328 KB |
Output is correct |
41 |
Correct |
14 ms |
1360 KB |
Output is correct |
42 |
Correct |
14 ms |
1412 KB |
Output is correct |
43 |
Correct |
14 ms |
1376 KB |
Output is correct |
44 |
Correct |
14 ms |
1360 KB |
Output is correct |
45 |
Correct |
14 ms |
1400 KB |
Output is correct |
46 |
Correct |
14 ms |
1360 KB |
Output is correct |
47 |
Correct |
14 ms |
1344 KB |
Output is correct |
48 |
Correct |
13 ms |
1104 KB |
Output is correct |
49 |
Correct |
11 ms |
856 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
417 ms |
14308 KB |
Output is correct |
52 |
Correct |
434 ms |
14372 KB |
Output is correct |
53 |
Correct |
427 ms |
14244 KB |
Output is correct |
54 |
Correct |
389 ms |
14244 KB |
Output is correct |
55 |
Correct |
422 ms |
14408 KB |
Output is correct |
56 |
Correct |
408 ms |
14252 KB |
Output is correct |
57 |
Correct |
400 ms |
14256 KB |
Output is correct |
58 |
Correct |
269 ms |
14320 KB |
Output is correct |
59 |
Correct |
272 ms |
14240 KB |
Output is correct |
60 |
Correct |
1 ms |
332 KB |
Output is correct |
61 |
Correct |
562 ms |
29488 KB |
Output is correct |
62 |
Correct |
559 ms |
29448 KB |
Output is correct |
63 |
Correct |
565 ms |
29392 KB |
Output is correct |
64 |
Correct |
544 ms |
29468 KB |
Output is correct |
65 |
Correct |
630 ms |
29600 KB |
Output is correct |
66 |
Correct |
566 ms |
29424 KB |
Output is correct |
67 |
Correct |
605 ms |
29372 KB |
Output is correct |
68 |
Correct |
537 ms |
22636 KB |
Output is correct |
69 |
Correct |
483 ms |
17800 KB |
Output is correct |
70 |
Correct |
1 ms |
332 KB |
Output is correct |