# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
830144 |
2023-08-18T20:00:40 Z |
NK_ |
Mountains (NOI20_mountains) |
C++17 |
|
146 ms |
9744 KB |
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pi = pair<int, int>;
using vpi = V<pi>;
using vl = V<ll>;
using db = long double;
const int INF = 1e9 + 10;
struct BIT {
int N; vl A; void init(int n) { N = n; A = vl(N, 0); }
void upd(int p, int x) { for(++p;p<=N;p+=p&-p) A[p-1] += x; }
ll sum(int l, int r) { return sum(r + 1) - sum(l); }
ll sum(int r) { ll s = 0; for(;r;r-=r&-r) s += A[r-1]; return s; }
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int N; cin >> N;
vl A(N); for(auto& x : A) cin >> x;
vl X = A; sort(begin(X), end(X));
X.erase(unique(begin(X), end(X)), end(X));
for(auto& x : A) x = lower_bound(begin(X), end(X), x) - begin(X);
int M = sz(X);
BIT up, dwn; up.init(M); dwn.init(M);
ll ans = 0;
for(auto& x : A) {
ans += dwn.sum(x + 1, M - 1);
ll DWN = up.sum(0, x - 1);
dwn.upd(x, DWN);
up.upd(x, 1);
}
cout << ans << nl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
90 ms |
9616 KB |
Output is correct |
3 |
Correct |
92 ms |
9708 KB |
Output is correct |
4 |
Correct |
83 ms |
9704 KB |
Output is correct |
5 |
Correct |
87 ms |
9704 KB |
Output is correct |
6 |
Correct |
95 ms |
9708 KB |
Output is correct |
7 |
Correct |
88 ms |
9616 KB |
Output is correct |
8 |
Correct |
86 ms |
9704 KB |
Output is correct |
9 |
Correct |
86 ms |
7444 KB |
Output is correct |
10 |
Correct |
83 ms |
7396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
4984 KB |
Output is correct |
2 |
Correct |
27 ms |
5012 KB |
Output is correct |
3 |
Correct |
24 ms |
4984 KB |
Output is correct |
4 |
Correct |
25 ms |
4984 KB |
Output is correct |
5 |
Correct |
24 ms |
4988 KB |
Output is correct |
6 |
Correct |
24 ms |
4948 KB |
Output is correct |
7 |
Correct |
24 ms |
4988 KB |
Output is correct |
8 |
Correct |
22 ms |
4988 KB |
Output is correct |
9 |
Correct |
23 ms |
4948 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
4984 KB |
Output is correct |
2 |
Correct |
27 ms |
5012 KB |
Output is correct |
3 |
Correct |
24 ms |
4984 KB |
Output is correct |
4 |
Correct |
25 ms |
4984 KB |
Output is correct |
5 |
Correct |
24 ms |
4988 KB |
Output is correct |
6 |
Correct |
24 ms |
4948 KB |
Output is correct |
7 |
Correct |
24 ms |
4988 KB |
Output is correct |
8 |
Correct |
22 ms |
4988 KB |
Output is correct |
9 |
Correct |
23 ms |
4948 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
44 ms |
4980 KB |
Output is correct |
12 |
Correct |
45 ms |
4984 KB |
Output is correct |
13 |
Correct |
45 ms |
5008 KB |
Output is correct |
14 |
Correct |
44 ms |
5008 KB |
Output is correct |
15 |
Correct |
46 ms |
5028 KB |
Output is correct |
16 |
Correct |
43 ms |
5008 KB |
Output is correct |
17 |
Correct |
45 ms |
4976 KB |
Output is correct |
18 |
Correct |
26 ms |
4988 KB |
Output is correct |
19 |
Correct |
23 ms |
4948 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
4 ms |
596 KB |
Output is correct |
13 |
Correct |
3 ms |
596 KB |
Output is correct |
14 |
Correct |
3 ms |
596 KB |
Output is correct |
15 |
Correct |
3 ms |
540 KB |
Output is correct |
16 |
Correct |
4 ms |
608 KB |
Output is correct |
17 |
Correct |
3 ms |
596 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
4984 KB |
Output is correct |
2 |
Correct |
27 ms |
5012 KB |
Output is correct |
3 |
Correct |
24 ms |
4984 KB |
Output is correct |
4 |
Correct |
25 ms |
4984 KB |
Output is correct |
5 |
Correct |
24 ms |
4988 KB |
Output is correct |
6 |
Correct |
24 ms |
4948 KB |
Output is correct |
7 |
Correct |
24 ms |
4988 KB |
Output is correct |
8 |
Correct |
22 ms |
4988 KB |
Output is correct |
9 |
Correct |
23 ms |
4948 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
44 ms |
4980 KB |
Output is correct |
12 |
Correct |
45 ms |
4984 KB |
Output is correct |
13 |
Correct |
45 ms |
5008 KB |
Output is correct |
14 |
Correct |
44 ms |
5008 KB |
Output is correct |
15 |
Correct |
46 ms |
5028 KB |
Output is correct |
16 |
Correct |
43 ms |
5008 KB |
Output is correct |
17 |
Correct |
45 ms |
4976 KB |
Output is correct |
18 |
Correct |
26 ms |
4988 KB |
Output is correct |
19 |
Correct |
23 ms |
4948 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
108 ms |
6412 KB |
Output is correct |
22 |
Correct |
101 ms |
6496 KB |
Output is correct |
23 |
Correct |
100 ms |
6416 KB |
Output is correct |
24 |
Correct |
104 ms |
6500 KB |
Output is correct |
25 |
Correct |
103 ms |
6420 KB |
Output is correct |
26 |
Correct |
100 ms |
6416 KB |
Output is correct |
27 |
Correct |
102 ms |
6412 KB |
Output is correct |
28 |
Correct |
56 ms |
6476 KB |
Output is correct |
29 |
Correct |
59 ms |
6412 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
90 ms |
9616 KB |
Output is correct |
3 |
Correct |
92 ms |
9708 KB |
Output is correct |
4 |
Correct |
83 ms |
9704 KB |
Output is correct |
5 |
Correct |
87 ms |
9704 KB |
Output is correct |
6 |
Correct |
95 ms |
9708 KB |
Output is correct |
7 |
Correct |
88 ms |
9616 KB |
Output is correct |
8 |
Correct |
86 ms |
9704 KB |
Output is correct |
9 |
Correct |
86 ms |
7444 KB |
Output is correct |
10 |
Correct |
83 ms |
7396 KB |
Output is correct |
11 |
Correct |
24 ms |
4984 KB |
Output is correct |
12 |
Correct |
27 ms |
5012 KB |
Output is correct |
13 |
Correct |
24 ms |
4984 KB |
Output is correct |
14 |
Correct |
25 ms |
4984 KB |
Output is correct |
15 |
Correct |
24 ms |
4988 KB |
Output is correct |
16 |
Correct |
24 ms |
4948 KB |
Output is correct |
17 |
Correct |
24 ms |
4988 KB |
Output is correct |
18 |
Correct |
22 ms |
4988 KB |
Output is correct |
19 |
Correct |
23 ms |
4948 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
44 ms |
4980 KB |
Output is correct |
22 |
Correct |
45 ms |
4984 KB |
Output is correct |
23 |
Correct |
45 ms |
5008 KB |
Output is correct |
24 |
Correct |
44 ms |
5008 KB |
Output is correct |
25 |
Correct |
46 ms |
5028 KB |
Output is correct |
26 |
Correct |
43 ms |
5008 KB |
Output is correct |
27 |
Correct |
45 ms |
4976 KB |
Output is correct |
28 |
Correct |
26 ms |
4988 KB |
Output is correct |
29 |
Correct |
23 ms |
4948 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
3 ms |
596 KB |
Output is correct |
42 |
Correct |
4 ms |
596 KB |
Output is correct |
43 |
Correct |
3 ms |
596 KB |
Output is correct |
44 |
Correct |
3 ms |
596 KB |
Output is correct |
45 |
Correct |
3 ms |
540 KB |
Output is correct |
46 |
Correct |
4 ms |
608 KB |
Output is correct |
47 |
Correct |
3 ms |
596 KB |
Output is correct |
48 |
Correct |
3 ms |
468 KB |
Output is correct |
49 |
Correct |
2 ms |
468 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
108 ms |
6412 KB |
Output is correct |
52 |
Correct |
101 ms |
6496 KB |
Output is correct |
53 |
Correct |
100 ms |
6416 KB |
Output is correct |
54 |
Correct |
104 ms |
6500 KB |
Output is correct |
55 |
Correct |
103 ms |
6420 KB |
Output is correct |
56 |
Correct |
100 ms |
6416 KB |
Output is correct |
57 |
Correct |
102 ms |
6412 KB |
Output is correct |
58 |
Correct |
56 ms |
6476 KB |
Output is correct |
59 |
Correct |
59 ms |
6412 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
131 ms |
9620 KB |
Output is correct |
62 |
Correct |
132 ms |
9676 KB |
Output is correct |
63 |
Correct |
133 ms |
9744 KB |
Output is correct |
64 |
Correct |
131 ms |
9616 KB |
Output is correct |
65 |
Correct |
146 ms |
9584 KB |
Output is correct |
66 |
Correct |
134 ms |
9712 KB |
Output is correct |
67 |
Correct |
129 ms |
9704 KB |
Output is correct |
68 |
Correct |
123 ms |
7392 KB |
Output is correct |
69 |
Correct |
103 ms |
7044 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |