Submission #516448

# Submission time Handle Problem Language Result Execution time Memory
516448 2022-01-21T10:35:48 Z Jomnoi Mountains (NOI20_mountains) C++17
100 / 100
548 ms 36828 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

const int MX = 3e5 + 10;

long long h[MX];

class Fenwick {
    protected :
        int N;
        vector <int> fenwick;
    public :
        Fenwick(const int &n) : N(n) {
            fenwick.resize(N + 10, 0);
        }

        int lsb(const int &x) const {
            return x & -x;
        }

        void update(const int &i, const int &val) {
            for(int idx = i; idx <= N; idx += lsb(idx)) {
                fenwick[idx] += val;
            }
        }

        int query(const int &i) const {
            int res = 0;
            for(int idx = i; idx > 0; idx -= lsb(idx)) {
                res += fenwick[idx];
            }
            return res;
        }
};

int main() {
    int n;
    scanf(" %d", &n);

    set <long long> s;
    unordered_map <long long, int> mp;
    for(int i = 1; i <= n; i++) {
        scanf(" %lld", &h[i]);
        s.insert(h[i]);
    }

    int cnt = 0;
    for(auto v : s) {
        mp[v] = ++cnt;
    }

    Fenwick fw1(cnt), fw2(cnt);
    for(int i = 2; i <= n; i++) {
        fw2.update(mp[h[i]], 1);
    }

    fw1.update(mp[h[1]], 1);
    long long ans = 0;
    for(int i = 2; i < n; i++) {
        fw2.update(mp[h[i]], -1);
        ans += 1ll * fw1.query(mp[h[i]] - 1) * fw2.query(mp[h[i]] - 1);
        fw1.update(mp[h[i]], 1);
    }
    printf("%lld", ans);
    return 0;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf(" %d", &n);
      |     ~~~~~^~~~~~~~~~~
Mountains.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         scanf(" %lld", &h[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 342 ms 31280 KB Output is correct
3 Correct 353 ms 31356 KB Output is correct
4 Correct 347 ms 31144 KB Output is correct
5 Correct 383 ms 31300 KB Output is correct
6 Correct 326 ms 31288 KB Output is correct
7 Correct 408 ms 31484 KB Output is correct
8 Correct 330 ms 31272 KB Output is correct
9 Correct 192 ms 17372 KB Output is correct
10 Correct 169 ms 17436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2500 KB Output is correct
2 Correct 64 ms 2636 KB Output is correct
3 Correct 44 ms 2636 KB Output is correct
4 Correct 43 ms 2576 KB Output is correct
5 Correct 44 ms 2552 KB Output is correct
6 Correct 47 ms 2568 KB Output is correct
7 Correct 44 ms 2500 KB Output is correct
8 Correct 48 ms 2628 KB Output is correct
9 Correct 38 ms 2528 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2500 KB Output is correct
2 Correct 64 ms 2636 KB Output is correct
3 Correct 44 ms 2636 KB Output is correct
4 Correct 43 ms 2576 KB Output is correct
5 Correct 44 ms 2552 KB Output is correct
6 Correct 47 ms 2568 KB Output is correct
7 Correct 44 ms 2500 KB Output is correct
8 Correct 48 ms 2628 KB Output is correct
9 Correct 38 ms 2528 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 58 ms 2556 KB Output is correct
12 Correct 54 ms 3488 KB Output is correct
13 Correct 60 ms 3604 KB Output is correct
14 Correct 57 ms 3488 KB Output is correct
15 Correct 54 ms 3488 KB Output is correct
16 Correct 55 ms 3484 KB Output is correct
17 Correct 55 ms 3488 KB Output is correct
18 Correct 43 ms 3380 KB Output is correct
19 Correct 52 ms 3420 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 8 ms 1444 KB Output is correct
12 Correct 8 ms 1472 KB Output is correct
13 Correct 9 ms 1472 KB Output is correct
14 Correct 7 ms 1416 KB Output is correct
15 Correct 9 ms 1424 KB Output is correct
16 Correct 10 ms 1472 KB Output is correct
17 Correct 7 ms 1484 KB Output is correct
18 Correct 5 ms 948 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2500 KB Output is correct
2 Correct 64 ms 2636 KB Output is correct
3 Correct 44 ms 2636 KB Output is correct
4 Correct 43 ms 2576 KB Output is correct
5 Correct 44 ms 2552 KB Output is correct
6 Correct 47 ms 2568 KB Output is correct
7 Correct 44 ms 2500 KB Output is correct
8 Correct 48 ms 2628 KB Output is correct
9 Correct 38 ms 2528 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 58 ms 2556 KB Output is correct
12 Correct 54 ms 3488 KB Output is correct
13 Correct 60 ms 3604 KB Output is correct
14 Correct 57 ms 3488 KB Output is correct
15 Correct 54 ms 3488 KB Output is correct
16 Correct 55 ms 3484 KB Output is correct
17 Correct 55 ms 3488 KB Output is correct
18 Correct 43 ms 3380 KB Output is correct
19 Correct 52 ms 3420 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 170 ms 13908 KB Output is correct
22 Correct 177 ms 13888 KB Output is correct
23 Correct 187 ms 13900 KB Output is correct
24 Correct 173 ms 14024 KB Output is correct
25 Correct 172 ms 13880 KB Output is correct
26 Correct 177 ms 13812 KB Output is correct
27 Correct 169 ms 14064 KB Output is correct
28 Correct 113 ms 14008 KB Output is correct
29 Correct 112 ms 13784 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 342 ms 31280 KB Output is correct
3 Correct 353 ms 31356 KB Output is correct
4 Correct 347 ms 31144 KB Output is correct
5 Correct 383 ms 31300 KB Output is correct
6 Correct 326 ms 31288 KB Output is correct
7 Correct 408 ms 31484 KB Output is correct
8 Correct 330 ms 31272 KB Output is correct
9 Correct 192 ms 17372 KB Output is correct
10 Correct 169 ms 17436 KB Output is correct
11 Correct 67 ms 2500 KB Output is correct
12 Correct 64 ms 2636 KB Output is correct
13 Correct 44 ms 2636 KB Output is correct
14 Correct 43 ms 2576 KB Output is correct
15 Correct 44 ms 2552 KB Output is correct
16 Correct 47 ms 2568 KB Output is correct
17 Correct 44 ms 2500 KB Output is correct
18 Correct 48 ms 2628 KB Output is correct
19 Correct 38 ms 2528 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 58 ms 2556 KB Output is correct
22 Correct 54 ms 3488 KB Output is correct
23 Correct 60 ms 3604 KB Output is correct
24 Correct 57 ms 3488 KB Output is correct
25 Correct 54 ms 3488 KB Output is correct
26 Correct 55 ms 3484 KB Output is correct
27 Correct 55 ms 3488 KB Output is correct
28 Correct 43 ms 3380 KB Output is correct
29 Correct 52 ms 3420 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
35 Correct 1 ms 312 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 8 ms 1444 KB Output is correct
42 Correct 8 ms 1472 KB Output is correct
43 Correct 9 ms 1472 KB Output is correct
44 Correct 7 ms 1416 KB Output is correct
45 Correct 9 ms 1424 KB Output is correct
46 Correct 10 ms 1472 KB Output is correct
47 Correct 7 ms 1484 KB Output is correct
48 Correct 5 ms 948 KB Output is correct
49 Correct 2 ms 460 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 170 ms 13908 KB Output is correct
52 Correct 177 ms 13888 KB Output is correct
53 Correct 187 ms 13900 KB Output is correct
54 Correct 173 ms 14024 KB Output is correct
55 Correct 172 ms 13880 KB Output is correct
56 Correct 177 ms 13812 KB Output is correct
57 Correct 169 ms 14064 KB Output is correct
58 Correct 113 ms 14008 KB Output is correct
59 Correct 112 ms 13784 KB Output is correct
60 Correct 0 ms 204 KB Output is correct
61 Correct 519 ms 36828 KB Output is correct
62 Correct 517 ms 36772 KB Output is correct
63 Correct 531 ms 36764 KB Output is correct
64 Correct 517 ms 36740 KB Output is correct
65 Correct 525 ms 36760 KB Output is correct
66 Correct 548 ms 36772 KB Output is correct
67 Correct 541 ms 36792 KB Output is correct
68 Correct 266 ms 22876 KB Output is correct
69 Correct 224 ms 17000 KB Output is correct
70 Correct 1 ms 204 KB Output is correct