Submission #282495

# Submission time Handle Problem Language Result Execution time Memory
282495 2020-08-24T13:12:25 Z its_aks_ulure Mountains (NOI20_mountains) C++14
100 / 100
1360 ms 44808 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const long long mod = 1e9 + 7;

int n;
long long arr[N];
int segtree[2 * N];
long merge(long x, long y){
    return x + y;
}
void segtree_update(int ind, int val, int n_){
    for(segtree[ind += n_] += val; ind > 1; ind >>= 1)
        segtree[ind >> 1] = merge(segtree[ind], segtree[ind ^ 1]);
}
long segtree_query(int l, int r, int n_){
    long res = 0;
    for(l += n_, r += n_; l < r; l >>= 1, r >>= 1){
        if((l & 1) == 1)
            res = merge(res, segtree[l++]);
        if((r & 1) == 1)
            res = merge(res, segtree[--r]);
    }
    return res;
}
void solve(int test){
    set<long long> s;
    int i = 0;
    for(i = 0; i < n; i++)
        s.insert(arr[i]);
    map<long long, int> mp;
    int x = 0;
    for(long long xx : s)
        mp[xx] = x++;
    vector<int> cnt(n);
    int n_ = s.size();
    for(i = 0; i < n; i++){
        //cout <<
        cnt[i] = segtree_query(0, mp[arr[i]], n_);
        segtree_update(mp[arr[i]], 1, n_);
    }
    memset(segtree, 0, sizeof(segtree));
    long long ans = 0;
    for(i = n - 1; i >= 0; i--){
        ans += cnt[i] * 1LL * segtree_query(0, mp[arr[i]], n_);
        segtree_update(mp[arr[i]], 1, n_);
    }
    cout << ans << "\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    for(int test = 1; test <= t; test++){
        int i = 0;
        cin >> n;
        for(i = 0; i < n; i++)
            cin >> arr[i];
        solve(test);
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 396 ms 44792 KB Output is correct
3 Correct 420 ms 44664 KB Output is correct
4 Correct 478 ms 44644 KB Output is correct
5 Correct 432 ms 44664 KB Output is correct
6 Correct 432 ms 44660 KB Output is correct
7 Correct 452 ms 44660 KB Output is correct
8 Correct 425 ms 44664 KB Output is correct
9 Correct 338 ms 28792 KB Output is correct
10 Correct 333 ms 28920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 6776 KB Output is correct
2 Correct 36 ms 6788 KB Output is correct
3 Correct 43 ms 6776 KB Output is correct
4 Correct 34 ms 6784 KB Output is correct
5 Correct 35 ms 6776 KB Output is correct
6 Correct 34 ms 6776 KB Output is correct
7 Correct 35 ms 6784 KB Output is correct
8 Correct 28 ms 6776 KB Output is correct
9 Correct 32 ms 6904 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 6776 KB Output is correct
2 Correct 36 ms 6788 KB Output is correct
3 Correct 43 ms 6776 KB Output is correct
4 Correct 34 ms 6784 KB Output is correct
5 Correct 35 ms 6776 KB Output is correct
6 Correct 34 ms 6776 KB Output is correct
7 Correct 35 ms 6784 KB Output is correct
8 Correct 28 ms 6776 KB Output is correct
9 Correct 32 ms 6904 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 89 ms 7144 KB Output is correct
12 Correct 93 ms 7032 KB Output is correct
13 Correct 96 ms 7032 KB Output is correct
14 Correct 100 ms 7160 KB Output is correct
15 Correct 88 ms 7032 KB Output is correct
16 Correct 94 ms 7036 KB Output is correct
17 Correct 89 ms 7160 KB Output is correct
18 Correct 45 ms 7032 KB Output is correct
19 Correct 45 ms 7136 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2944 KB Output is correct
2 Correct 2 ms 2816 KB Output is correct
3 Correct 2 ms 2816 KB Output is correct
4 Correct 2 ms 2816 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2944 KB Output is correct
2 Correct 2 ms 2816 KB Output is correct
3 Correct 2 ms 2816 KB Output is correct
4 Correct 2 ms 2816 KB Output is correct
5 Correct 2 ms 2816 KB Output is correct
6 Correct 2 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 16 ms 4096 KB Output is correct
12 Correct 16 ms 4096 KB Output is correct
13 Correct 16 ms 4096 KB Output is correct
14 Correct 19 ms 4096 KB Output is correct
15 Correct 16 ms 4096 KB Output is correct
16 Correct 17 ms 4096 KB Output is correct
17 Correct 16 ms 4096 KB Output is correct
18 Correct 12 ms 3456 KB Output is correct
19 Correct 6 ms 2944 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 6776 KB Output is correct
2 Correct 36 ms 6788 KB Output is correct
3 Correct 43 ms 6776 KB Output is correct
4 Correct 34 ms 6784 KB Output is correct
5 Correct 35 ms 6776 KB Output is correct
6 Correct 34 ms 6776 KB Output is correct
7 Correct 35 ms 6784 KB Output is correct
8 Correct 28 ms 6776 KB Output is correct
9 Correct 32 ms 6904 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 89 ms 7144 KB Output is correct
12 Correct 93 ms 7032 KB Output is correct
13 Correct 96 ms 7032 KB Output is correct
14 Correct 100 ms 7160 KB Output is correct
15 Correct 88 ms 7032 KB Output is correct
16 Correct 94 ms 7036 KB Output is correct
17 Correct 89 ms 7160 KB Output is correct
18 Correct 45 ms 7032 KB Output is correct
19 Correct 45 ms 7136 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 702 ms 18460 KB Output is correct
22 Correct 665 ms 18424 KB Output is correct
23 Correct 691 ms 18368 KB Output is correct
24 Correct 660 ms 18460 KB Output is correct
25 Correct 620 ms 18552 KB Output is correct
26 Correct 671 ms 18424 KB Output is correct
27 Correct 663 ms 18424 KB Output is correct
28 Correct 229 ms 18428 KB Output is correct
29 Correct 225 ms 18320 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 396 ms 44792 KB Output is correct
3 Correct 420 ms 44664 KB Output is correct
4 Correct 478 ms 44644 KB Output is correct
5 Correct 432 ms 44664 KB Output is correct
6 Correct 432 ms 44660 KB Output is correct
7 Correct 452 ms 44660 KB Output is correct
8 Correct 425 ms 44664 KB Output is correct
9 Correct 338 ms 28792 KB Output is correct
10 Correct 333 ms 28920 KB Output is correct
11 Correct 33 ms 6776 KB Output is correct
12 Correct 36 ms 6788 KB Output is correct
13 Correct 43 ms 6776 KB Output is correct
14 Correct 34 ms 6784 KB Output is correct
15 Correct 35 ms 6776 KB Output is correct
16 Correct 34 ms 6776 KB Output is correct
17 Correct 35 ms 6784 KB Output is correct
18 Correct 28 ms 6776 KB Output is correct
19 Correct 32 ms 6904 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 89 ms 7144 KB Output is correct
22 Correct 93 ms 7032 KB Output is correct
23 Correct 96 ms 7032 KB Output is correct
24 Correct 100 ms 7160 KB Output is correct
25 Correct 88 ms 7032 KB Output is correct
26 Correct 94 ms 7036 KB Output is correct
27 Correct 89 ms 7160 KB Output is correct
28 Correct 45 ms 7032 KB Output is correct
29 Correct 45 ms 7136 KB Output is correct
30 Correct 2 ms 2688 KB Output is correct
31 Correct 2 ms 2944 KB Output is correct
32 Correct 2 ms 2816 KB Output is correct
33 Correct 2 ms 2816 KB Output is correct
34 Correct 2 ms 2816 KB Output is correct
35 Correct 2 ms 2816 KB Output is correct
36 Correct 2 ms 2816 KB Output is correct
37 Correct 2 ms 2816 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
39 Correct 2 ms 2688 KB Output is correct
40 Correct 2 ms 2688 KB Output is correct
41 Correct 16 ms 4096 KB Output is correct
42 Correct 16 ms 4096 KB Output is correct
43 Correct 16 ms 4096 KB Output is correct
44 Correct 19 ms 4096 KB Output is correct
45 Correct 16 ms 4096 KB Output is correct
46 Correct 17 ms 4096 KB Output is correct
47 Correct 16 ms 4096 KB Output is correct
48 Correct 12 ms 3456 KB Output is correct
49 Correct 6 ms 2944 KB Output is correct
50 Correct 2 ms 2688 KB Output is correct
51 Correct 702 ms 18460 KB Output is correct
52 Correct 665 ms 18424 KB Output is correct
53 Correct 691 ms 18368 KB Output is correct
54 Correct 660 ms 18460 KB Output is correct
55 Correct 620 ms 18552 KB Output is correct
56 Correct 671 ms 18424 KB Output is correct
57 Correct 663 ms 18424 KB Output is correct
58 Correct 229 ms 18428 KB Output is correct
59 Correct 225 ms 18320 KB Output is correct
60 Correct 2 ms 2688 KB Output is correct
61 Correct 1324 ms 44664 KB Output is correct
62 Correct 1360 ms 44664 KB Output is correct
63 Correct 1317 ms 44664 KB Output is correct
64 Correct 1300 ms 44664 KB Output is correct
65 Correct 1247 ms 44808 KB Output is correct
66 Correct 1302 ms 44748 KB Output is correct
67 Correct 1297 ms 44664 KB Output is correct
68 Correct 956 ms 28920 KB Output is correct
69 Correct 909 ms 22284 KB Output is correct
70 Correct 2 ms 2688 KB Output is correct