#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(),x.end()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
struct BIT
{
int t[maxn];
void up(int x,int val)
{
for( ; x < maxn ; x += lb(x)) t[x] += val;
}
int get(int x)
{
int ans = 0;
for( ; x ; x -= lb(x)) ans += t[x];
return ans;
}
}t1,t2;
int n,a[maxn];
vi nen;
int p[maxn],s[maxn];
main()
{
#define name "TASK"
if (fopen(name ".inp", "r"))
{
freopen(name ".inp", "r", stdin);
freopen(name ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
fo(i,1,n)
{
cin >> a[i];
nen.pb(a[i]);
}
sort(all(nen));
nen.erase(unique(all(nen)),nen.end());
fo(i,1,n)
{
a[i] = lower_bound(all(nen),a[i]) - nen.begin() + 1;
p[i] = t1.get(a[i] - 1);
t1.up(a[i],1);
}
fod(i,n,1)
{
s[i] = t2.get(a[i] - 1);
t2.up(a[i],1);
}
int ans = 0;
fo(i,1,n) ans += s[i] * p[i];
cout << ans;
}
Compilation message
Mountains.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
60 | main()
| ^~~~
Mountains.cpp: In function 'int main()':
Mountains.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen(name ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen(name ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
16732 KB |
Output is correct |
2 |
Correct |
75 ms |
33524 KB |
Output is correct |
3 |
Correct |
70 ms |
33820 KB |
Output is correct |
4 |
Correct |
69 ms |
33472 KB |
Output is correct |
5 |
Correct |
78 ms |
32324 KB |
Output is correct |
6 |
Correct |
70 ms |
33876 KB |
Output is correct |
7 |
Correct |
68 ms |
33044 KB |
Output is correct |
8 |
Correct |
69 ms |
32452 KB |
Output is correct |
9 |
Correct |
71 ms |
33528 KB |
Output is correct |
10 |
Correct |
76 ms |
34496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
26816 KB |
Output is correct |
2 |
Correct |
63 ms |
27580 KB |
Output is correct |
3 |
Correct |
61 ms |
26768 KB |
Output is correct |
4 |
Correct |
60 ms |
27064 KB |
Output is correct |
5 |
Correct |
67 ms |
26800 KB |
Output is correct |
6 |
Correct |
60 ms |
27088 KB |
Output is correct |
7 |
Correct |
61 ms |
27584 KB |
Output is correct |
8 |
Correct |
60 ms |
28352 KB |
Output is correct |
9 |
Correct |
63 ms |
29896 KB |
Output is correct |
10 |
Correct |
2 ms |
16732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
26816 KB |
Output is correct |
2 |
Correct |
63 ms |
27580 KB |
Output is correct |
3 |
Correct |
61 ms |
26768 KB |
Output is correct |
4 |
Correct |
60 ms |
27064 KB |
Output is correct |
5 |
Correct |
67 ms |
26800 KB |
Output is correct |
6 |
Correct |
60 ms |
27088 KB |
Output is correct |
7 |
Correct |
61 ms |
27584 KB |
Output is correct |
8 |
Correct |
60 ms |
28352 KB |
Output is correct |
9 |
Correct |
63 ms |
29896 KB |
Output is correct |
10 |
Correct |
2 ms |
16732 KB |
Output is correct |
11 |
Correct |
58 ms |
27220 KB |
Output is correct |
12 |
Correct |
57 ms |
26732 KB |
Output is correct |
13 |
Correct |
56 ms |
26812 KB |
Output is correct |
14 |
Correct |
57 ms |
26400 KB |
Output is correct |
15 |
Correct |
62 ms |
26976 KB |
Output is correct |
16 |
Correct |
65 ms |
29376 KB |
Output is correct |
17 |
Correct |
54 ms |
26820 KB |
Output is correct |
18 |
Correct |
52 ms |
28644 KB |
Output is correct |
19 |
Correct |
55 ms |
28360 KB |
Output is correct |
20 |
Correct |
2 ms |
14876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14684 KB |
Output is correct |
4 |
Correct |
1 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14680 KB |
Output is correct |
6 |
Correct |
2 ms |
14884 KB |
Output is correct |
7 |
Correct |
2 ms |
14832 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14684 KB |
Output is correct |
4 |
Correct |
1 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14680 KB |
Output is correct |
6 |
Correct |
2 ms |
14884 KB |
Output is correct |
7 |
Correct |
2 ms |
14832 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
5 ms |
15196 KB |
Output is correct |
12 |
Correct |
6 ms |
15376 KB |
Output is correct |
13 |
Correct |
5 ms |
15196 KB |
Output is correct |
14 |
Correct |
5 ms |
15192 KB |
Output is correct |
15 |
Correct |
5 ms |
15192 KB |
Output is correct |
16 |
Correct |
5 ms |
15192 KB |
Output is correct |
17 |
Correct |
5 ms |
15196 KB |
Output is correct |
18 |
Correct |
5 ms |
15196 KB |
Output is correct |
19 |
Correct |
4 ms |
15176 KB |
Output is correct |
20 |
Correct |
2 ms |
16728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
26816 KB |
Output is correct |
2 |
Correct |
63 ms |
27580 KB |
Output is correct |
3 |
Correct |
61 ms |
26768 KB |
Output is correct |
4 |
Correct |
60 ms |
27064 KB |
Output is correct |
5 |
Correct |
67 ms |
26800 KB |
Output is correct |
6 |
Correct |
60 ms |
27088 KB |
Output is correct |
7 |
Correct |
61 ms |
27584 KB |
Output is correct |
8 |
Correct |
60 ms |
28352 KB |
Output is correct |
9 |
Correct |
63 ms |
29896 KB |
Output is correct |
10 |
Correct |
2 ms |
16732 KB |
Output is correct |
11 |
Correct |
58 ms |
27220 KB |
Output is correct |
12 |
Correct |
57 ms |
26732 KB |
Output is correct |
13 |
Correct |
56 ms |
26812 KB |
Output is correct |
14 |
Correct |
57 ms |
26400 KB |
Output is correct |
15 |
Correct |
62 ms |
26976 KB |
Output is correct |
16 |
Correct |
65 ms |
29376 KB |
Output is correct |
17 |
Correct |
54 ms |
26820 KB |
Output is correct |
18 |
Correct |
52 ms |
28644 KB |
Output is correct |
19 |
Correct |
55 ms |
28360 KB |
Output is correct |
20 |
Correct |
2 ms |
14876 KB |
Output is correct |
21 |
Correct |
104 ms |
28096 KB |
Output is correct |
22 |
Correct |
104 ms |
29336 KB |
Output is correct |
23 |
Correct |
107 ms |
28608 KB |
Output is correct |
24 |
Correct |
98 ms |
27992 KB |
Output is correct |
25 |
Correct |
110 ms |
29496 KB |
Output is correct |
26 |
Correct |
99 ms |
29252 KB |
Output is correct |
27 |
Correct |
106 ms |
29232 KB |
Output is correct |
28 |
Correct |
56 ms |
29632 KB |
Output is correct |
29 |
Correct |
58 ms |
29372 KB |
Output is correct |
30 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
16732 KB |
Output is correct |
2 |
Correct |
75 ms |
33524 KB |
Output is correct |
3 |
Correct |
70 ms |
33820 KB |
Output is correct |
4 |
Correct |
69 ms |
33472 KB |
Output is correct |
5 |
Correct |
78 ms |
32324 KB |
Output is correct |
6 |
Correct |
70 ms |
33876 KB |
Output is correct |
7 |
Correct |
68 ms |
33044 KB |
Output is correct |
8 |
Correct |
69 ms |
32452 KB |
Output is correct |
9 |
Correct |
71 ms |
33528 KB |
Output is correct |
10 |
Correct |
76 ms |
34496 KB |
Output is correct |
11 |
Correct |
61 ms |
26816 KB |
Output is correct |
12 |
Correct |
63 ms |
27580 KB |
Output is correct |
13 |
Correct |
61 ms |
26768 KB |
Output is correct |
14 |
Correct |
60 ms |
27064 KB |
Output is correct |
15 |
Correct |
67 ms |
26800 KB |
Output is correct |
16 |
Correct |
60 ms |
27088 KB |
Output is correct |
17 |
Correct |
61 ms |
27584 KB |
Output is correct |
18 |
Correct |
60 ms |
28352 KB |
Output is correct |
19 |
Correct |
63 ms |
29896 KB |
Output is correct |
20 |
Correct |
2 ms |
16732 KB |
Output is correct |
21 |
Correct |
58 ms |
27220 KB |
Output is correct |
22 |
Correct |
57 ms |
26732 KB |
Output is correct |
23 |
Correct |
56 ms |
26812 KB |
Output is correct |
24 |
Correct |
57 ms |
26400 KB |
Output is correct |
25 |
Correct |
62 ms |
26976 KB |
Output is correct |
26 |
Correct |
65 ms |
29376 KB |
Output is correct |
27 |
Correct |
54 ms |
26820 KB |
Output is correct |
28 |
Correct |
52 ms |
28644 KB |
Output is correct |
29 |
Correct |
55 ms |
28360 KB |
Output is correct |
30 |
Correct |
2 ms |
14876 KB |
Output is correct |
31 |
Correct |
2 ms |
14684 KB |
Output is correct |
32 |
Correct |
2 ms |
14684 KB |
Output is correct |
33 |
Correct |
2 ms |
14684 KB |
Output is correct |
34 |
Correct |
1 ms |
14684 KB |
Output is correct |
35 |
Correct |
2 ms |
14680 KB |
Output is correct |
36 |
Correct |
2 ms |
14884 KB |
Output is correct |
37 |
Correct |
2 ms |
14832 KB |
Output is correct |
38 |
Correct |
2 ms |
14684 KB |
Output is correct |
39 |
Correct |
2 ms |
14684 KB |
Output is correct |
40 |
Correct |
2 ms |
14684 KB |
Output is correct |
41 |
Correct |
5 ms |
15196 KB |
Output is correct |
42 |
Correct |
6 ms |
15376 KB |
Output is correct |
43 |
Correct |
5 ms |
15196 KB |
Output is correct |
44 |
Correct |
5 ms |
15192 KB |
Output is correct |
45 |
Correct |
5 ms |
15192 KB |
Output is correct |
46 |
Correct |
5 ms |
15192 KB |
Output is correct |
47 |
Correct |
5 ms |
15196 KB |
Output is correct |
48 |
Correct |
5 ms |
15196 KB |
Output is correct |
49 |
Correct |
4 ms |
15176 KB |
Output is correct |
50 |
Correct |
2 ms |
16728 KB |
Output is correct |
51 |
Correct |
104 ms |
28096 KB |
Output is correct |
52 |
Correct |
104 ms |
29336 KB |
Output is correct |
53 |
Correct |
107 ms |
28608 KB |
Output is correct |
54 |
Correct |
98 ms |
27992 KB |
Output is correct |
55 |
Correct |
110 ms |
29496 KB |
Output is correct |
56 |
Correct |
99 ms |
29252 KB |
Output is correct |
57 |
Correct |
106 ms |
29232 KB |
Output is correct |
58 |
Correct |
56 ms |
29632 KB |
Output is correct |
59 |
Correct |
58 ms |
29372 KB |
Output is correct |
60 |
Correct |
2 ms |
14684 KB |
Output is correct |
61 |
Correct |
127 ms |
32708 KB |
Output is correct |
62 |
Correct |
125 ms |
31424 KB |
Output is correct |
63 |
Correct |
123 ms |
32444 KB |
Output is correct |
64 |
Correct |
127 ms |
30848 KB |
Output is correct |
65 |
Correct |
124 ms |
32796 KB |
Output is correct |
66 |
Correct |
122 ms |
30388 KB |
Output is correct |
67 |
Correct |
132 ms |
33220 KB |
Output is correct |
68 |
Correct |
131 ms |
33988 KB |
Output is correct |
69 |
Correct |
109 ms |
29372 KB |
Output is correct |
70 |
Correct |
2 ms |
16732 KB |
Output is correct |