Submission #889136

# Submission time Handle Problem Language Result Execution time Memory
889136 2023-12-19T02:26:39 Z dimashhh Mountains (NOI20_mountains) C++17
100 / 100
266 ms 28656 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1, MOD = 998244353;
typedef long long ll;

ll n,a[N],t[N * 4];
vector<ll> v;
void cl(){
    for(int i = 1;i <= n * 4;i++){
        t[i] =0;
    }
}
void upd(int pos,int v = 1,int tl =1,int tr = n){
    t[v]++;
    if(tl ==tr) return;
    int tm = (tl + tr) >> 1;
    if(pos <= tm) upd(pos,v+v,tl,tm);
    else upd(pos,v+v+1,tm+1,tr);
}
ll get(int l,int r,int v = 1,int tl = 1,int tr =n){
    if(l > r || tl > r || l > tr) return 0;
    if(tl >= l && tr <= r) return t[v];
    int tm = (tl + tr) >> 1;
    return get(l,r,v+v,tl,tm) + get(l,r,v+v+1,tm+1,tr);
}
ll l[N],res = 0;
void test(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        v.push_back(a[i]);
    }
    sort(v.begin(),v.end());
    for(int i = 1;i <= n;i++){
        a[i] = (lower_bound(v.begin(),v.end(),a[i]) - v.begin()) + 1;
        l[i] = get(1,a[i] - 1);
        upd(a[i]);
    }
    cl();
    for(int i = n;i >= 1;i--){
        // cout << get(a[i] + 1,n) << '\n';
        res += l[i] * get(1,a[i] - 1);
        upd(a[i]);
    }
    cout << res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;//cin >> T;
    while (T--) test();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 156 ms 27016 KB Output is correct
3 Correct 143 ms 26940 KB Output is correct
4 Correct 146 ms 28092 KB Output is correct
5 Correct 142 ms 27560 KB Output is correct
6 Correct 142 ms 28304 KB Output is correct
7 Correct 143 ms 28608 KB Output is correct
8 Correct 142 ms 28304 KB Output is correct
9 Correct 129 ms 28372 KB Output is correct
10 Correct 131 ms 27444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 22212 KB Output is correct
2 Correct 65 ms 22468 KB Output is correct
3 Correct 65 ms 22976 KB Output is correct
4 Correct 73 ms 23236 KB Output is correct
5 Correct 70 ms 23072 KB Output is correct
6 Correct 68 ms 21968 KB Output is correct
7 Correct 64 ms 23248 KB Output is correct
8 Correct 66 ms 23380 KB Output is correct
9 Correct 68 ms 23236 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 22212 KB Output is correct
2 Correct 65 ms 22468 KB Output is correct
3 Correct 65 ms 22976 KB Output is correct
4 Correct 73 ms 23236 KB Output is correct
5 Correct 70 ms 23072 KB Output is correct
6 Correct 68 ms 21968 KB Output is correct
7 Correct 64 ms 23248 KB Output is correct
8 Correct 66 ms 23380 KB Output is correct
9 Correct 68 ms 23236 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 141 ms 23516 KB Output is correct
12 Correct 132 ms 22240 KB Output is correct
13 Correct 132 ms 23820 KB Output is correct
14 Correct 132 ms 23488 KB Output is correct
15 Correct 139 ms 23488 KB Output is correct
16 Correct 132 ms 22744 KB Output is correct
17 Correct 136 ms 23228 KB Output is correct
18 Correct 73 ms 23480 KB Output is correct
19 Correct 80 ms 22304 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4572 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4572 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 7 ms 4952 KB Output is correct
12 Correct 8 ms 4836 KB Output is correct
13 Correct 7 ms 4956 KB Output is correct
14 Correct 7 ms 4956 KB Output is correct
15 Correct 7 ms 4956 KB Output is correct
16 Correct 7 ms 4956 KB Output is correct
17 Correct 7 ms 4952 KB Output is correct
18 Correct 7 ms 4956 KB Output is correct
19 Correct 6 ms 4696 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 22212 KB Output is correct
2 Correct 65 ms 22468 KB Output is correct
3 Correct 65 ms 22976 KB Output is correct
4 Correct 73 ms 23236 KB Output is correct
5 Correct 70 ms 23072 KB Output is correct
6 Correct 68 ms 21968 KB Output is correct
7 Correct 64 ms 23248 KB Output is correct
8 Correct 66 ms 23380 KB Output is correct
9 Correct 68 ms 23236 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 141 ms 23516 KB Output is correct
12 Correct 132 ms 22240 KB Output is correct
13 Correct 132 ms 23820 KB Output is correct
14 Correct 132 ms 23488 KB Output is correct
15 Correct 139 ms 23488 KB Output is correct
16 Correct 132 ms 22744 KB Output is correct
17 Correct 136 ms 23228 KB Output is correct
18 Correct 73 ms 23480 KB Output is correct
19 Correct 80 ms 22304 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 232 ms 24768 KB Output is correct
22 Correct 235 ms 23628 KB Output is correct
23 Correct 228 ms 23876 KB Output is correct
24 Correct 235 ms 23740 KB Output is correct
25 Correct 232 ms 23756 KB Output is correct
26 Correct 236 ms 24500 KB Output is correct
27 Correct 235 ms 23388 KB Output is correct
28 Correct 108 ms 24348 KB Output is correct
29 Correct 113 ms 23484 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 156 ms 27016 KB Output is correct
3 Correct 143 ms 26940 KB Output is correct
4 Correct 146 ms 28092 KB Output is correct
5 Correct 142 ms 27560 KB Output is correct
6 Correct 142 ms 28304 KB Output is correct
7 Correct 143 ms 28608 KB Output is correct
8 Correct 142 ms 28304 KB Output is correct
9 Correct 129 ms 28372 KB Output is correct
10 Correct 131 ms 27444 KB Output is correct
11 Correct 62 ms 22212 KB Output is correct
12 Correct 65 ms 22468 KB Output is correct
13 Correct 65 ms 22976 KB Output is correct
14 Correct 73 ms 23236 KB Output is correct
15 Correct 70 ms 23072 KB Output is correct
16 Correct 68 ms 21968 KB Output is correct
17 Correct 64 ms 23248 KB Output is correct
18 Correct 66 ms 23380 KB Output is correct
19 Correct 68 ms 23236 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Correct 141 ms 23516 KB Output is correct
22 Correct 132 ms 22240 KB Output is correct
23 Correct 132 ms 23820 KB Output is correct
24 Correct 132 ms 23488 KB Output is correct
25 Correct 139 ms 23488 KB Output is correct
26 Correct 132 ms 22744 KB Output is correct
27 Correct 136 ms 23228 KB Output is correct
28 Correct 73 ms 23480 KB Output is correct
29 Correct 80 ms 22304 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4572 KB Output is correct
33 Correct 1 ms 4440 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 7 ms 4952 KB Output is correct
42 Correct 8 ms 4836 KB Output is correct
43 Correct 7 ms 4956 KB Output is correct
44 Correct 7 ms 4956 KB Output is correct
45 Correct 7 ms 4956 KB Output is correct
46 Correct 7 ms 4956 KB Output is correct
47 Correct 7 ms 4952 KB Output is correct
48 Correct 7 ms 4956 KB Output is correct
49 Correct 6 ms 4696 KB Output is correct
50 Correct 1 ms 4440 KB Output is correct
51 Correct 232 ms 24768 KB Output is correct
52 Correct 235 ms 23628 KB Output is correct
53 Correct 228 ms 23876 KB Output is correct
54 Correct 235 ms 23740 KB Output is correct
55 Correct 232 ms 23756 KB Output is correct
56 Correct 236 ms 24500 KB Output is correct
57 Correct 235 ms 23388 KB Output is correct
58 Correct 108 ms 24348 KB Output is correct
59 Correct 113 ms 23484 KB Output is correct
60 Correct 1 ms 4444 KB Output is correct
61 Correct 259 ms 28184 KB Output is correct
62 Correct 254 ms 26756 KB Output is correct
63 Correct 253 ms 28656 KB Output is correct
64 Correct 252 ms 26964 KB Output is correct
65 Correct 253 ms 27876 KB Output is correct
66 Correct 266 ms 28608 KB Output is correct
67 Correct 250 ms 27580 KB Output is correct
68 Correct 260 ms 27148 KB Output is correct
69 Correct 238 ms 25028 KB Output is correct
70 Correct 1 ms 4440 KB Output is correct