#include <bits/stdc++.h>
#define ll long long
#define int 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;
int a[N];
namespace sub1
{
int 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<int>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+=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(long long int, long long int, long long int)':
Mountains.cpp:20:7: warning: statement has no effect [-Wunused-value]
20 | for(id;id<=n;id+=(id&(-id)))
| ^~
Mountains.cpp: In function 'long long int sub1::get(long long int, long long int)':
Mountains.cpp:26:7: warning: statement has no effect [-Wunused-value]
26 | for(id;id>0;id-=((id&(-id))))
| ^~
Mountains.cpp: At global scope:
Mountains.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
55 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
98 ms |
13776 KB |
Output is correct |
3 |
Correct |
78 ms |
14116 KB |
Output is correct |
4 |
Correct |
69 ms |
13040 KB |
Output is correct |
5 |
Correct |
69 ms |
13092 KB |
Output is correct |
6 |
Correct |
68 ms |
12964 KB |
Output is correct |
7 |
Correct |
71 ms |
13092 KB |
Output is correct |
8 |
Correct |
90 ms |
13216 KB |
Output is correct |
9 |
Correct |
79 ms |
13028 KB |
Output is correct |
10 |
Correct |
89 ms |
12744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
7636 KB |
Output is correct |
2 |
Correct |
74 ms |
7632 KB |
Output is correct |
3 |
Correct |
81 ms |
8660 KB |
Output is correct |
4 |
Correct |
77 ms |
9424 KB |
Output is correct |
5 |
Correct |
78 ms |
8144 KB |
Output is correct |
6 |
Correct |
79 ms |
8148 KB |
Output is correct |
7 |
Correct |
79 ms |
9684 KB |
Output is correct |
8 |
Correct |
63 ms |
7636 KB |
Output is correct |
9 |
Correct |
70 ms |
7892 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
7636 KB |
Output is correct |
2 |
Correct |
74 ms |
7632 KB |
Output is correct |
3 |
Correct |
81 ms |
8660 KB |
Output is correct |
4 |
Correct |
77 ms |
9424 KB |
Output is correct |
5 |
Correct |
78 ms |
8144 KB |
Output is correct |
6 |
Correct |
79 ms |
8148 KB |
Output is correct |
7 |
Correct |
79 ms |
9684 KB |
Output is correct |
8 |
Correct |
63 ms |
7636 KB |
Output is correct |
9 |
Correct |
70 ms |
7892 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
89 ms |
7892 KB |
Output is correct |
12 |
Correct |
85 ms |
8288 KB |
Output is correct |
13 |
Correct |
83 ms |
8236 KB |
Output is correct |
14 |
Correct |
88 ms |
8148 KB |
Output is correct |
15 |
Correct |
81 ms |
9684 KB |
Output is correct |
16 |
Correct |
68 ms |
8144 KB |
Output is correct |
17 |
Correct |
72 ms |
7892 KB |
Output is correct |
18 |
Correct |
58 ms |
7892 KB |
Output is correct |
19 |
Correct |
67 ms |
8912 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
4 ms |
860 KB |
Output is correct |
12 |
Correct |
3 ms |
1024 KB |
Output is correct |
13 |
Correct |
5 ms |
860 KB |
Output is correct |
14 |
Correct |
5 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
2908 KB |
Output is correct |
16 |
Correct |
4 ms |
2904 KB |
Output is correct |
17 |
Correct |
3 ms |
2908 KB |
Output is correct |
18 |
Correct |
3 ms |
2908 KB |
Output is correct |
19 |
Correct |
2 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
7636 KB |
Output is correct |
2 |
Correct |
74 ms |
7632 KB |
Output is correct |
3 |
Correct |
81 ms |
8660 KB |
Output is correct |
4 |
Correct |
77 ms |
9424 KB |
Output is correct |
5 |
Correct |
78 ms |
8144 KB |
Output is correct |
6 |
Correct |
79 ms |
8148 KB |
Output is correct |
7 |
Correct |
79 ms |
9684 KB |
Output is correct |
8 |
Correct |
63 ms |
7636 KB |
Output is correct |
9 |
Correct |
70 ms |
7892 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
89 ms |
7892 KB |
Output is correct |
12 |
Correct |
85 ms |
8288 KB |
Output is correct |
13 |
Correct |
83 ms |
8236 KB |
Output is correct |
14 |
Correct |
88 ms |
8148 KB |
Output is correct |
15 |
Correct |
81 ms |
9684 KB |
Output is correct |
16 |
Correct |
68 ms |
8144 KB |
Output is correct |
17 |
Correct |
72 ms |
7892 KB |
Output is correct |
18 |
Correct |
58 ms |
7892 KB |
Output is correct |
19 |
Correct |
67 ms |
8912 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
104 ms |
8832 KB |
Output is correct |
22 |
Correct |
99 ms |
8656 KB |
Output is correct |
23 |
Correct |
102 ms |
8652 KB |
Output is correct |
24 |
Correct |
121 ms |
10704 KB |
Output is correct |
25 |
Correct |
99 ms |
8660 KB |
Output is correct |
26 |
Correct |
99 ms |
8660 KB |
Output is correct |
27 |
Correct |
100 ms |
8660 KB |
Output is correct |
28 |
Correct |
54 ms |
9164 KB |
Output is correct |
29 |
Correct |
53 ms |
8660 KB |
Output is correct |
30 |
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 |
98 ms |
13776 KB |
Output is correct |
3 |
Correct |
78 ms |
14116 KB |
Output is correct |
4 |
Correct |
69 ms |
13040 KB |
Output is correct |
5 |
Correct |
69 ms |
13092 KB |
Output is correct |
6 |
Correct |
68 ms |
12964 KB |
Output is correct |
7 |
Correct |
71 ms |
13092 KB |
Output is correct |
8 |
Correct |
90 ms |
13216 KB |
Output is correct |
9 |
Correct |
79 ms |
13028 KB |
Output is correct |
10 |
Correct |
89 ms |
12744 KB |
Output is correct |
11 |
Correct |
68 ms |
7636 KB |
Output is correct |
12 |
Correct |
74 ms |
7632 KB |
Output is correct |
13 |
Correct |
81 ms |
8660 KB |
Output is correct |
14 |
Correct |
77 ms |
9424 KB |
Output is correct |
15 |
Correct |
78 ms |
8144 KB |
Output is correct |
16 |
Correct |
79 ms |
8148 KB |
Output is correct |
17 |
Correct |
79 ms |
9684 KB |
Output is correct |
18 |
Correct |
63 ms |
7636 KB |
Output is correct |
19 |
Correct |
70 ms |
7892 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
89 ms |
7892 KB |
Output is correct |
22 |
Correct |
85 ms |
8288 KB |
Output is correct |
23 |
Correct |
83 ms |
8236 KB |
Output is correct |
24 |
Correct |
88 ms |
8148 KB |
Output is correct |
25 |
Correct |
81 ms |
9684 KB |
Output is correct |
26 |
Correct |
68 ms |
8144 KB |
Output is correct |
27 |
Correct |
72 ms |
7892 KB |
Output is correct |
28 |
Correct |
58 ms |
7892 KB |
Output is correct |
29 |
Correct |
67 ms |
8912 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 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 |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
4 ms |
860 KB |
Output is correct |
42 |
Correct |
3 ms |
1024 KB |
Output is correct |
43 |
Correct |
5 ms |
860 KB |
Output is correct |
44 |
Correct |
5 ms |
860 KB |
Output is correct |
45 |
Correct |
5 ms |
2908 KB |
Output is correct |
46 |
Correct |
4 ms |
2904 KB |
Output is correct |
47 |
Correct |
3 ms |
2908 KB |
Output is correct |
48 |
Correct |
3 ms |
2908 KB |
Output is correct |
49 |
Correct |
2 ms |
2652 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
104 ms |
8832 KB |
Output is correct |
52 |
Correct |
99 ms |
8656 KB |
Output is correct |
53 |
Correct |
102 ms |
8652 KB |
Output is correct |
54 |
Correct |
121 ms |
10704 KB |
Output is correct |
55 |
Correct |
99 ms |
8660 KB |
Output is correct |
56 |
Correct |
99 ms |
8660 KB |
Output is correct |
57 |
Correct |
100 ms |
8660 KB |
Output is correct |
58 |
Correct |
54 ms |
9164 KB |
Output is correct |
59 |
Correct |
53 ms |
8660 KB |
Output is correct |
60 |
Correct |
0 ms |
348 KB |
Output is correct |
61 |
Correct |
122 ms |
12948 KB |
Output is correct |
62 |
Correct |
124 ms |
13056 KB |
Output is correct |
63 |
Correct |
132 ms |
14496 KB |
Output is correct |
64 |
Correct |
127 ms |
14388 KB |
Output is correct |
65 |
Correct |
136 ms |
13880 KB |
Output is correct |
66 |
Correct |
134 ms |
14524 KB |
Output is correct |
67 |
Correct |
134 ms |
12952 KB |
Output is correct |
68 |
Correct |
142 ms |
13516 KB |
Output is correct |
69 |
Correct |
120 ms |
9936 KB |
Output is correct |
70 |
Correct |
1 ms |
348 KB |
Output is correct |