#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
const LL MAXN=300005;
LL a[MAXN],bit[2][MAXN],MAX;
void update(LL now,LL val,LL no){
for(LL i=now;i<=MAX;i+=(i&(-i)))bit[no][i]+=val;
}
LL query(LL now,LL no){
LL ret=0;
if(now==0)return ret;
for(LL i=now;i>0;i-=(i&(-i)))ret+=bit[no][i];
return ret;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
LL n;
cin >> n;
vector<pii> v;
for(LL i=1;i<=n;i++){
cin >> a[i];
v.push_back({a[i],i});
}
sort(v.begin(),v.end());
for(LL i=0;i<v.size();i++){
if(i==0 || v[i].first!=v[i-1].first)MAX++;
a[v[i].second]=MAX;
}
for(LL i=1;i<=n;i++)update(a[i],1,1);
LL ans=0;
for(LL i=1;i<=n;i++){
update(a[i],-1,1);
ans+=query(a[i]-1,0)*query(a[i]-1,1);
update(a[i],1,0);
}
cout << ans << '\n';
return 0;
}
Compilation message
Mountains.cpp: In function 'int main()':
Mountains.cpp:30:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(LL i=0;i<v.size();i++){
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
96 ms |
17752 KB |
Output is correct |
3 |
Correct |
103 ms |
17748 KB |
Output is correct |
4 |
Correct |
105 ms |
17748 KB |
Output is correct |
5 |
Correct |
101 ms |
17752 KB |
Output is correct |
6 |
Correct |
100 ms |
17872 KB |
Output is correct |
7 |
Correct |
108 ms |
17880 KB |
Output is correct |
8 |
Correct |
101 ms |
17748 KB |
Output is correct |
9 |
Correct |
104 ms |
15840 KB |
Output is correct |
10 |
Correct |
97 ms |
15840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
11376 KB |
Output is correct |
2 |
Correct |
62 ms |
11376 KB |
Output is correct |
3 |
Correct |
60 ms |
11376 KB |
Output is correct |
4 |
Correct |
57 ms |
11368 KB |
Output is correct |
5 |
Correct |
58 ms |
11376 KB |
Output is correct |
6 |
Correct |
55 ms |
11368 KB |
Output is correct |
7 |
Correct |
56 ms |
11368 KB |
Output is correct |
8 |
Correct |
35 ms |
11376 KB |
Output is correct |
9 |
Correct |
40 ms |
11364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
11376 KB |
Output is correct |
2 |
Correct |
62 ms |
11376 KB |
Output is correct |
3 |
Correct |
60 ms |
11376 KB |
Output is correct |
4 |
Correct |
57 ms |
11368 KB |
Output is correct |
5 |
Correct |
58 ms |
11376 KB |
Output is correct |
6 |
Correct |
55 ms |
11368 KB |
Output is correct |
7 |
Correct |
56 ms |
11368 KB |
Output is correct |
8 |
Correct |
35 ms |
11376 KB |
Output is correct |
9 |
Correct |
40 ms |
11364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
73 ms |
11620 KB |
Output is correct |
12 |
Correct |
71 ms |
11632 KB |
Output is correct |
13 |
Correct |
76 ms |
11624 KB |
Output is correct |
14 |
Correct |
70 ms |
11624 KB |
Output is correct |
15 |
Correct |
72 ms |
11620 KB |
Output is correct |
16 |
Correct |
72 ms |
11624 KB |
Output is correct |
17 |
Correct |
70 ms |
11632 KB |
Output is correct |
18 |
Correct |
40 ms |
11632 KB |
Output is correct |
19 |
Correct |
43 ms |
11624 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
1016 KB |
Output is correct |
12 |
Correct |
4 ms |
1024 KB |
Output is correct |
13 |
Correct |
4 ms |
1024 KB |
Output is correct |
14 |
Correct |
4 ms |
1024 KB |
Output is correct |
15 |
Correct |
4 ms |
1024 KB |
Output is correct |
16 |
Correct |
4 ms |
1024 KB |
Output is correct |
17 |
Correct |
4 ms |
1024 KB |
Output is correct |
18 |
Correct |
4 ms |
1024 KB |
Output is correct |
19 |
Correct |
3 ms |
896 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
11376 KB |
Output is correct |
2 |
Correct |
62 ms |
11376 KB |
Output is correct |
3 |
Correct |
60 ms |
11376 KB |
Output is correct |
4 |
Correct |
57 ms |
11368 KB |
Output is correct |
5 |
Correct |
58 ms |
11376 KB |
Output is correct |
6 |
Correct |
55 ms |
11368 KB |
Output is correct |
7 |
Correct |
56 ms |
11368 KB |
Output is correct |
8 |
Correct |
35 ms |
11376 KB |
Output is correct |
9 |
Correct |
40 ms |
11364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
73 ms |
11620 KB |
Output is correct |
12 |
Correct |
71 ms |
11632 KB |
Output is correct |
13 |
Correct |
76 ms |
11624 KB |
Output is correct |
14 |
Correct |
70 ms |
11624 KB |
Output is correct |
15 |
Correct |
72 ms |
11620 KB |
Output is correct |
16 |
Correct |
72 ms |
11624 KB |
Output is correct |
17 |
Correct |
70 ms |
11632 KB |
Output is correct |
18 |
Correct |
40 ms |
11632 KB |
Output is correct |
19 |
Correct |
43 ms |
11624 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
94 ms |
12400 KB |
Output is correct |
22 |
Correct |
104 ms |
12516 KB |
Output is correct |
23 |
Correct |
100 ms |
12388 KB |
Output is correct |
24 |
Correct |
96 ms |
12400 KB |
Output is correct |
25 |
Correct |
99 ms |
12388 KB |
Output is correct |
26 |
Correct |
99 ms |
12384 KB |
Output is correct |
27 |
Correct |
101 ms |
12388 KB |
Output is correct |
28 |
Correct |
68 ms |
12388 KB |
Output is correct |
29 |
Correct |
64 ms |
12388 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
96 ms |
17752 KB |
Output is correct |
3 |
Correct |
103 ms |
17748 KB |
Output is correct |
4 |
Correct |
105 ms |
17748 KB |
Output is correct |
5 |
Correct |
101 ms |
17752 KB |
Output is correct |
6 |
Correct |
100 ms |
17872 KB |
Output is correct |
7 |
Correct |
108 ms |
17880 KB |
Output is correct |
8 |
Correct |
101 ms |
17748 KB |
Output is correct |
9 |
Correct |
104 ms |
15840 KB |
Output is correct |
10 |
Correct |
97 ms |
15840 KB |
Output is correct |
11 |
Correct |
53 ms |
11376 KB |
Output is correct |
12 |
Correct |
62 ms |
11376 KB |
Output is correct |
13 |
Correct |
60 ms |
11376 KB |
Output is correct |
14 |
Correct |
57 ms |
11368 KB |
Output is correct |
15 |
Correct |
58 ms |
11376 KB |
Output is correct |
16 |
Correct |
55 ms |
11368 KB |
Output is correct |
17 |
Correct |
56 ms |
11368 KB |
Output is correct |
18 |
Correct |
35 ms |
11376 KB |
Output is correct |
19 |
Correct |
40 ms |
11364 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
73 ms |
11620 KB |
Output is correct |
22 |
Correct |
71 ms |
11632 KB |
Output is correct |
23 |
Correct |
76 ms |
11624 KB |
Output is correct |
24 |
Correct |
70 ms |
11624 KB |
Output is correct |
25 |
Correct |
72 ms |
11620 KB |
Output is correct |
26 |
Correct |
72 ms |
11624 KB |
Output is correct |
27 |
Correct |
70 ms |
11632 KB |
Output is correct |
28 |
Correct |
40 ms |
11632 KB |
Output is correct |
29 |
Correct |
43 ms |
11624 KB |
Output is correct |
30 |
Correct |
0 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
0 ms |
384 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
0 ms |
384 KB |
Output is correct |
41 |
Correct |
6 ms |
1016 KB |
Output is correct |
42 |
Correct |
4 ms |
1024 KB |
Output is correct |
43 |
Correct |
4 ms |
1024 KB |
Output is correct |
44 |
Correct |
4 ms |
1024 KB |
Output is correct |
45 |
Correct |
4 ms |
1024 KB |
Output is correct |
46 |
Correct |
4 ms |
1024 KB |
Output is correct |
47 |
Correct |
4 ms |
1024 KB |
Output is correct |
48 |
Correct |
4 ms |
1024 KB |
Output is correct |
49 |
Correct |
3 ms |
896 KB |
Output is correct |
50 |
Correct |
0 ms |
384 KB |
Output is correct |
51 |
Correct |
94 ms |
12400 KB |
Output is correct |
52 |
Correct |
104 ms |
12516 KB |
Output is correct |
53 |
Correct |
100 ms |
12388 KB |
Output is correct |
54 |
Correct |
96 ms |
12400 KB |
Output is correct |
55 |
Correct |
99 ms |
12388 KB |
Output is correct |
56 |
Correct |
99 ms |
12384 KB |
Output is correct |
57 |
Correct |
101 ms |
12388 KB |
Output is correct |
58 |
Correct |
68 ms |
12388 KB |
Output is correct |
59 |
Correct |
64 ms |
12388 KB |
Output is correct |
60 |
Correct |
0 ms |
384 KB |
Output is correct |
61 |
Correct |
150 ms |
17760 KB |
Output is correct |
62 |
Correct |
140 ms |
17784 KB |
Output is correct |
63 |
Correct |
138 ms |
17748 KB |
Output is correct |
64 |
Correct |
144 ms |
17748 KB |
Output is correct |
65 |
Correct |
135 ms |
17748 KB |
Output is correct |
66 |
Correct |
134 ms |
17748 KB |
Output is correct |
67 |
Correct |
137 ms |
17896 KB |
Output is correct |
68 |
Correct |
130 ms |
15972 KB |
Output is correct |
69 |
Correct |
99 ms |
12512 KB |
Output is correct |
70 |
Correct |
0 ms |
384 KB |
Output is correct |