답안 #952165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952165 2024-03-23T07:48:26 Z Bzslayed Mountains (NOI20_mountains) C++17
100 / 100
517 ms 50768 KB
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pff pair<float, float>
#define coutpair(p) cout << p.first << " " << p.second << "\n"

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n; cin >> n;
    ll h[n];
    for (int i=0; i<n; i++) cin >> h[i];

    ordered_multiset lcnt, rcnt; //to check for bottom values
    ll left[n], right[n]; //for a fixed point i, how many numbers are 
                            //smaller than it on each side
    left[0] = 0, right[n-1] = 0;
    ll ans = 0;

    lcnt.insert(h[0]);
    for (int i=1; i<n; i++){
        left[i] = lcnt.order_of_key(h[i]);
        lcnt.insert(h[i]);
    }

    rcnt.insert(h[n-1]);
    for (int i=n-2; i>=0; i--){
        right[i] = rcnt.order_of_key(h[i]);
        ans += left[i]*right[i];
        rcnt.insert(h[i]);
    }

    cout << ans;    

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 507 ms 50504 KB Output is correct
3 Correct 509 ms 50440 KB Output is correct
4 Correct 507 ms 50616 KB Output is correct
5 Correct 510 ms 50404 KB Output is correct
6 Correct 508 ms 50520 KB Output is correct
7 Correct 510 ms 50500 KB Output is correct
8 Correct 517 ms 50496 KB Output is correct
9 Correct 372 ms 50516 KB Output is correct
10 Correct 368 ms 50592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 45508 KB Output is correct
2 Correct 204 ms 45648 KB Output is correct
3 Correct 210 ms 45396 KB Output is correct
4 Correct 208 ms 45604 KB Output is correct
5 Correct 209 ms 45824 KB Output is correct
6 Correct 209 ms 45632 KB Output is correct
7 Correct 203 ms 45392 KB Output is correct
8 Correct 385 ms 45804 KB Output is correct
9 Correct 386 ms 45392 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 45508 KB Output is correct
2 Correct 204 ms 45648 KB Output is correct
3 Correct 210 ms 45396 KB Output is correct
4 Correct 208 ms 45604 KB Output is correct
5 Correct 209 ms 45824 KB Output is correct
6 Correct 209 ms 45632 KB Output is correct
7 Correct 203 ms 45392 KB Output is correct
8 Correct 385 ms 45804 KB Output is correct
9 Correct 386 ms 45392 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 342 ms 45688 KB Output is correct
12 Correct 341 ms 45820 KB Output is correct
13 Correct 326 ms 45904 KB Output is correct
14 Correct 361 ms 46148 KB Output is correct
15 Correct 327 ms 45688 KB Output is correct
16 Correct 325 ms 45868 KB Output is correct
17 Correct 334 ms 45868 KB Output is correct
18 Correct 343 ms 45716 KB Output is correct
19 Correct 349 ms 46160 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 8 ms 1884 KB Output is correct
12 Correct 7 ms 2004 KB Output is correct
13 Correct 7 ms 1884 KB Output is correct
14 Correct 7 ms 2084 KB Output is correct
15 Correct 7 ms 1884 KB Output is correct
16 Correct 7 ms 1884 KB Output is correct
17 Correct 9 ms 2012 KB Output is correct
18 Correct 8 ms 1884 KB Output is correct
19 Correct 7 ms 1884 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 209 ms 45508 KB Output is correct
2 Correct 204 ms 45648 KB Output is correct
3 Correct 210 ms 45396 KB Output is correct
4 Correct 208 ms 45604 KB Output is correct
5 Correct 209 ms 45824 KB Output is correct
6 Correct 209 ms 45632 KB Output is correct
7 Correct 203 ms 45392 KB Output is correct
8 Correct 385 ms 45804 KB Output is correct
9 Correct 386 ms 45392 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 342 ms 45688 KB Output is correct
12 Correct 341 ms 45820 KB Output is correct
13 Correct 326 ms 45904 KB Output is correct
14 Correct 361 ms 46148 KB Output is correct
15 Correct 327 ms 45688 KB Output is correct
16 Correct 325 ms 45868 KB Output is correct
17 Correct 334 ms 45868 KB Output is correct
18 Correct 343 ms 45716 KB Output is correct
19 Correct 349 ms 46160 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 393 ms 46576 KB Output is correct
22 Correct 390 ms 46772 KB Output is correct
23 Correct 388 ms 46680 KB Output is correct
24 Correct 398 ms 46740 KB Output is correct
25 Correct 372 ms 46672 KB Output is correct
26 Correct 397 ms 46548 KB Output is correct
27 Correct 386 ms 46688 KB Output is correct
28 Correct 354 ms 46672 KB Output is correct
29 Correct 353 ms 46616 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 507 ms 50504 KB Output is correct
3 Correct 509 ms 50440 KB Output is correct
4 Correct 507 ms 50616 KB Output is correct
5 Correct 510 ms 50404 KB Output is correct
6 Correct 508 ms 50520 KB Output is correct
7 Correct 510 ms 50500 KB Output is correct
8 Correct 517 ms 50496 KB Output is correct
9 Correct 372 ms 50516 KB Output is correct
10 Correct 368 ms 50592 KB Output is correct
11 Correct 209 ms 45508 KB Output is correct
12 Correct 204 ms 45648 KB Output is correct
13 Correct 210 ms 45396 KB Output is correct
14 Correct 208 ms 45604 KB Output is correct
15 Correct 209 ms 45824 KB Output is correct
16 Correct 209 ms 45632 KB Output is correct
17 Correct 203 ms 45392 KB Output is correct
18 Correct 385 ms 45804 KB Output is correct
19 Correct 386 ms 45392 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 342 ms 45688 KB Output is correct
22 Correct 341 ms 45820 KB Output is correct
23 Correct 326 ms 45904 KB Output is correct
24 Correct 361 ms 46148 KB Output is correct
25 Correct 327 ms 45688 KB Output is correct
26 Correct 325 ms 45868 KB Output is correct
27 Correct 334 ms 45868 KB Output is correct
28 Correct 343 ms 45716 KB Output is correct
29 Correct 349 ms 46160 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 8 ms 1884 KB Output is correct
42 Correct 7 ms 2004 KB Output is correct
43 Correct 7 ms 1884 KB Output is correct
44 Correct 7 ms 2084 KB Output is correct
45 Correct 7 ms 1884 KB Output is correct
46 Correct 7 ms 1884 KB Output is correct
47 Correct 9 ms 2012 KB Output is correct
48 Correct 8 ms 1884 KB Output is correct
49 Correct 7 ms 1884 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 393 ms 46576 KB Output is correct
52 Correct 390 ms 46772 KB Output is correct
53 Correct 388 ms 46680 KB Output is correct
54 Correct 398 ms 46740 KB Output is correct
55 Correct 372 ms 46672 KB Output is correct
56 Correct 397 ms 46548 KB Output is correct
57 Correct 386 ms 46688 KB Output is correct
58 Correct 354 ms 46672 KB Output is correct
59 Correct 353 ms 46616 KB Output is correct
60 Correct 0 ms 344 KB Output is correct
61 Correct 385 ms 50484 KB Output is correct
62 Correct 384 ms 50768 KB Output is correct
63 Correct 389 ms 50512 KB Output is correct
64 Correct 380 ms 50768 KB Output is correct
65 Correct 372 ms 50516 KB Output is correct
66 Correct 387 ms 50740 KB Output is correct
67 Correct 374 ms 50568 KB Output is correct
68 Correct 386 ms 50512 KB Output is correct
69 Correct 383 ms 46792 KB Output is correct
70 Correct 1 ms 344 KB Output is correct