#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define N 300005
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define sz(i) (int)i.size()
#define endl '\n'
using namespace std;
int n;
ll a[N];
namespace sub1
{
ll res;
int bit[N][2];
void upd(int id,int v,int k)
{
for(id;id<=n;id+=(id&(-id)))
bit[id][k]+=v;
}
int get(int id,int k)
{
int t=0;
for(id;id>0;id-=((id&(-id))))
t+=bit[id][k];
return t;
}
void compress()
{
vector<ll>v;
for(int i=1;i<=n;i++)
v.push_back(a[i]);
sort(v.begin(),v.end());
v.resize(unique(v.begin(),v.end())-v.begin());
for(int i=1;i<=n;i++)
a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin()+1;
}
void solve()
{
compress();
for(int i=2;i<=n;i++)
upd(a[i],1,1);
upd(a[1],1,0);
for(int i=2;i<n;i++)
{
res+=1LL*get(a[i]-1,0)*get(a[i]-1,1);
upd(a[i],-1,1);
upd(a[i],1,0);
}
cout<<res;
}
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sub1::solve();
}
Compilation message
Mountains.cpp: In function 'void sub1::upd(int, int, int)':
Mountains.cpp:19:7: warning: statement has no effect [-Wunused-value]
19 | for(id;id<=n;id+=(id&(-id)))
| ^~
Mountains.cpp: In function 'int sub1::get(int, int)':
Mountains.cpp:25:7: warning: statement has no effect [-Wunused-value]
25 | for(id;id>0;id-=((id&(-id))))
| ^~
Mountains.cpp: At global scope:
Mountains.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
54 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
64 ms |
7240 KB |
Output is correct |
3 |
Correct |
63 ms |
7624 KB |
Output is correct |
4 |
Correct |
61 ms |
7244 KB |
Output is correct |
5 |
Correct |
62 ms |
8144 KB |
Output is correct |
6 |
Correct |
64 ms |
8396 KB |
Output is correct |
7 |
Correct |
63 ms |
7372 KB |
Output is correct |
8 |
Correct |
69 ms |
7624 KB |
Output is correct |
9 |
Correct |
65 ms |
7888 KB |
Output is correct |
10 |
Correct |
66 ms |
8396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
7380 KB |
Output is correct |
2 |
Correct |
65 ms |
7376 KB |
Output is correct |
3 |
Correct |
70 ms |
8148 KB |
Output is correct |
4 |
Correct |
65 ms |
8912 KB |
Output is correct |
5 |
Correct |
70 ms |
8656 KB |
Output is correct |
6 |
Correct |
67 ms |
9172 KB |
Output is correct |
7 |
Correct |
64 ms |
8404 KB |
Output is correct |
8 |
Correct |
65 ms |
7376 KB |
Output is correct |
9 |
Correct |
57 ms |
7120 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
7380 KB |
Output is correct |
2 |
Correct |
65 ms |
7376 KB |
Output is correct |
3 |
Correct |
70 ms |
8148 KB |
Output is correct |
4 |
Correct |
65 ms |
8912 KB |
Output is correct |
5 |
Correct |
70 ms |
8656 KB |
Output is correct |
6 |
Correct |
67 ms |
9172 KB |
Output is correct |
7 |
Correct |
64 ms |
8404 KB |
Output is correct |
8 |
Correct |
65 ms |
7376 KB |
Output is correct |
9 |
Correct |
57 ms |
7120 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
70 ms |
7636 KB |
Output is correct |
12 |
Correct |
67 ms |
8400 KB |
Output is correct |
13 |
Correct |
67 ms |
8656 KB |
Output is correct |
14 |
Correct |
74 ms |
7892 KB |
Output is correct |
15 |
Correct |
70 ms |
7120 KB |
Output is correct |
16 |
Correct |
68 ms |
8404 KB |
Output is correct |
17 |
Correct |
62 ms |
7124 KB |
Output is correct |
18 |
Correct |
47 ms |
7120 KB |
Output is correct |
19 |
Correct |
45 ms |
7124 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2512 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2512 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
3 ms |
2652 KB |
Output is correct |
12 |
Correct |
3 ms |
2652 KB |
Output is correct |
13 |
Correct |
3 ms |
2652 KB |
Output is correct |
14 |
Correct |
3 ms |
2652 KB |
Output is correct |
15 |
Correct |
3 ms |
2652 KB |
Output is correct |
16 |
Correct |
3 ms |
2652 KB |
Output is correct |
17 |
Correct |
3 ms |
2652 KB |
Output is correct |
18 |
Correct |
3 ms |
2700 KB |
Output is correct |
19 |
Correct |
2 ms |
2652 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
7380 KB |
Output is correct |
2 |
Correct |
65 ms |
7376 KB |
Output is correct |
3 |
Correct |
70 ms |
8148 KB |
Output is correct |
4 |
Correct |
65 ms |
8912 KB |
Output is correct |
5 |
Correct |
70 ms |
8656 KB |
Output is correct |
6 |
Correct |
67 ms |
9172 KB |
Output is correct |
7 |
Correct |
64 ms |
8404 KB |
Output is correct |
8 |
Correct |
65 ms |
7376 KB |
Output is correct |
9 |
Correct |
57 ms |
7120 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
70 ms |
7636 KB |
Output is correct |
12 |
Correct |
67 ms |
8400 KB |
Output is correct |
13 |
Correct |
67 ms |
8656 KB |
Output is correct |
14 |
Correct |
74 ms |
7892 KB |
Output is correct |
15 |
Correct |
70 ms |
7120 KB |
Output is correct |
16 |
Correct |
68 ms |
8404 KB |
Output is correct |
17 |
Correct |
62 ms |
7124 KB |
Output is correct |
18 |
Correct |
47 ms |
7120 KB |
Output is correct |
19 |
Correct |
45 ms |
7124 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
105 ms |
8908 KB |
Output is correct |
22 |
Correct |
105 ms |
8144 KB |
Output is correct |
23 |
Correct |
103 ms |
8656 KB |
Output is correct |
24 |
Correct |
105 ms |
8404 KB |
Output is correct |
25 |
Correct |
100 ms |
7116 KB |
Output is correct |
26 |
Correct |
94 ms |
7124 KB |
Output is correct |
27 |
Correct |
105 ms |
8780 KB |
Output is correct |
28 |
Correct |
46 ms |
7124 KB |
Output is correct |
29 |
Correct |
45 ms |
7124 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
64 ms |
7240 KB |
Output is correct |
3 |
Correct |
63 ms |
7624 KB |
Output is correct |
4 |
Correct |
61 ms |
7244 KB |
Output is correct |
5 |
Correct |
62 ms |
8144 KB |
Output is correct |
6 |
Correct |
64 ms |
8396 KB |
Output is correct |
7 |
Correct |
63 ms |
7372 KB |
Output is correct |
8 |
Correct |
69 ms |
7624 KB |
Output is correct |
9 |
Correct |
65 ms |
7888 KB |
Output is correct |
10 |
Correct |
66 ms |
8396 KB |
Output is correct |
11 |
Correct |
69 ms |
7380 KB |
Output is correct |
12 |
Correct |
65 ms |
7376 KB |
Output is correct |
13 |
Correct |
70 ms |
8148 KB |
Output is correct |
14 |
Correct |
65 ms |
8912 KB |
Output is correct |
15 |
Correct |
70 ms |
8656 KB |
Output is correct |
16 |
Correct |
67 ms |
9172 KB |
Output is correct |
17 |
Correct |
64 ms |
8404 KB |
Output is correct |
18 |
Correct |
65 ms |
7376 KB |
Output is correct |
19 |
Correct |
57 ms |
7120 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
70 ms |
7636 KB |
Output is correct |
22 |
Correct |
67 ms |
8400 KB |
Output is correct |
23 |
Correct |
67 ms |
8656 KB |
Output is correct |
24 |
Correct |
74 ms |
7892 KB |
Output is correct |
25 |
Correct |
70 ms |
7120 KB |
Output is correct |
26 |
Correct |
68 ms |
8404 KB |
Output is correct |
27 |
Correct |
62 ms |
7124 KB |
Output is correct |
28 |
Correct |
47 ms |
7120 KB |
Output is correct |
29 |
Correct |
45 ms |
7124 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
0 ms |
2512 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
3 ms |
2652 KB |
Output is correct |
42 |
Correct |
3 ms |
2652 KB |
Output is correct |
43 |
Correct |
3 ms |
2652 KB |
Output is correct |
44 |
Correct |
3 ms |
2652 KB |
Output is correct |
45 |
Correct |
3 ms |
2652 KB |
Output is correct |
46 |
Correct |
3 ms |
2652 KB |
Output is correct |
47 |
Correct |
3 ms |
2652 KB |
Output is correct |
48 |
Correct |
3 ms |
2700 KB |
Output is correct |
49 |
Correct |
2 ms |
2652 KB |
Output is correct |
50 |
Correct |
0 ms |
2396 KB |
Output is correct |
51 |
Correct |
105 ms |
8908 KB |
Output is correct |
52 |
Correct |
105 ms |
8144 KB |
Output is correct |
53 |
Correct |
103 ms |
8656 KB |
Output is correct |
54 |
Correct |
105 ms |
8404 KB |
Output is correct |
55 |
Correct |
100 ms |
7116 KB |
Output is correct |
56 |
Correct |
94 ms |
7124 KB |
Output is correct |
57 |
Correct |
105 ms |
8780 KB |
Output is correct |
58 |
Correct |
46 ms |
7124 KB |
Output is correct |
59 |
Correct |
45 ms |
7124 KB |
Output is correct |
60 |
Correct |
1 ms |
2396 KB |
Output is correct |
61 |
Correct |
135 ms |
8776 KB |
Output is correct |
62 |
Correct |
119 ms |
7116 KB |
Output is correct |
63 |
Correct |
126 ms |
8904 KB |
Output is correct |
64 |
Correct |
116 ms |
6988 KB |
Output is correct |
65 |
Correct |
125 ms |
7884 KB |
Output is correct |
66 |
Correct |
133 ms |
8508 KB |
Output is correct |
67 |
Correct |
126 ms |
7880 KB |
Output is correct |
68 |
Correct |
124 ms |
7880 KB |
Output is correct |
69 |
Correct |
104 ms |
7376 KB |
Output is correct |
70 |
Correct |
1 ms |
2396 KB |
Output is correct |