답안 #332112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332112 2020-12-01T13:39:08 Z Sara Mountains (NOI20_mountains) C++14
100 / 100
474 ms 31200 KB
#include <bits/stdc++.h>
     
using namespace std;
     
#define ll long long int 
#define F first
#define S second
#define pb push_back
#define lc (ind * 2)
#define rc (lc + 1)
#define md ((b + e) / 2)

const ll N = 3e5 + 5;
const ll LOG = 20;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 10;

int n, cnt[4 * N];
ll H[N], ans;
vector <int> all[N];
vector <ll> vc;

void add(int id, int b = 0, int e = n, int ind = 1){
    if (b + 1 == e){
        cnt[ind] ++;
        return;   
    }
    if (id < md) add(id, b, md, lc);
    else add(id, md, e, rc);
    cnt[ind] = cnt[lc] + cnt[rc];
    return;
}
int get(int l, int r, int b = 0, int e = n, int ind = 1){
    if (l <= b && e <= r){
        return cnt[ind];
    }
    int res = 0;
    if (l < md) res += get(l, r, b, md, lc);
    if (md < r) res += get(l, r, md, e, rc);
    return res;
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> H[i];
        vc.pb(H[i]);
    }
    sort(vc.begin(), vc.end());
    vc.resize(unique(vc.begin(), vc.end()) - vc.begin());
    for (int i = 0; i < n; i++){
        int p = lower_bound(vc.begin(), vc.end(), H[i]) - vc.begin();
        all[p].pb(i);
    }
    for (int i = 0; i < (int)vc.size(); i++){
        ll L, R;
        for (int j : all[i]){
            L = 0; R = 0;
            if (j) L = get(0, j);
            R = get(j, n);
            ans += (L * R);
        }
        for (int j : all[i]){
            add(j);
        }
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7404 KB Output is correct
2 Correct 228 ms 25920 KB Output is correct
3 Correct 216 ms 25948 KB Output is correct
4 Correct 227 ms 25876 KB Output is correct
5 Correct 221 ms 25820 KB Output is correct
6 Correct 224 ms 25948 KB Output is correct
7 Correct 217 ms 25972 KB Output is correct
8 Correct 237 ms 25820 KB Output is correct
9 Correct 223 ms 21468 KB Output is correct
10 Correct 223 ms 21340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 19164 KB Output is correct
2 Correct 168 ms 19292 KB Output is correct
3 Correct 166 ms 19292 KB Output is correct
4 Correct 166 ms 19292 KB Output is correct
5 Correct 163 ms 19564 KB Output is correct
6 Correct 171 ms 19420 KB Output is correct
7 Correct 160 ms 19184 KB Output is correct
8 Correct 152 ms 19036 KB Output is correct
9 Correct 151 ms 19164 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 19164 KB Output is correct
2 Correct 168 ms 19292 KB Output is correct
3 Correct 166 ms 19292 KB Output is correct
4 Correct 166 ms 19292 KB Output is correct
5 Correct 163 ms 19564 KB Output is correct
6 Correct 171 ms 19420 KB Output is correct
7 Correct 160 ms 19184 KB Output is correct
8 Correct 152 ms 19036 KB Output is correct
9 Correct 151 ms 19164 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
11 Correct 220 ms 19036 KB Output is correct
12 Correct 215 ms 18908 KB Output is correct
13 Correct 233 ms 18844 KB Output is correct
14 Correct 216 ms 18908 KB Output is correct
15 Correct 212 ms 18908 KB Output is correct
16 Correct 218 ms 18908 KB Output is correct
17 Correct 216 ms 18780 KB Output is correct
18 Correct 158 ms 18652 KB Output is correct
19 Correct 163 ms 18684 KB Output is correct
20 Correct 6 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 6 ms 7404 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 6 ms 7404 KB Output is correct
7 Correct 6 ms 7404 KB Output is correct
8 Correct 6 ms 7404 KB Output is correct
9 Correct 6 ms 7436 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7404 KB Output is correct
2 Correct 5 ms 7404 KB Output is correct
3 Correct 5 ms 7404 KB Output is correct
4 Correct 6 ms 7404 KB Output is correct
5 Correct 6 ms 7404 KB Output is correct
6 Correct 6 ms 7404 KB Output is correct
7 Correct 6 ms 7404 KB Output is correct
8 Correct 6 ms 7404 KB Output is correct
9 Correct 6 ms 7436 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
11 Correct 14 ms 8148 KB Output is correct
12 Correct 13 ms 8172 KB Output is correct
13 Correct 14 ms 8172 KB Output is correct
14 Correct 14 ms 8172 KB Output is correct
15 Correct 14 ms 8172 KB Output is correct
16 Correct 14 ms 8172 KB Output is correct
17 Correct 16 ms 8172 KB Output is correct
18 Correct 16 ms 8044 KB Output is correct
19 Correct 13 ms 7916 KB Output is correct
20 Correct 5 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 19164 KB Output is correct
2 Correct 168 ms 19292 KB Output is correct
3 Correct 166 ms 19292 KB Output is correct
4 Correct 166 ms 19292 KB Output is correct
5 Correct 163 ms 19564 KB Output is correct
6 Correct 171 ms 19420 KB Output is correct
7 Correct 160 ms 19184 KB Output is correct
8 Correct 152 ms 19036 KB Output is correct
9 Correct 151 ms 19164 KB Output is correct
10 Correct 6 ms 7404 KB Output is correct
11 Correct 220 ms 19036 KB Output is correct
12 Correct 215 ms 18908 KB Output is correct
13 Correct 233 ms 18844 KB Output is correct
14 Correct 216 ms 18908 KB Output is correct
15 Correct 212 ms 18908 KB Output is correct
16 Correct 218 ms 18908 KB Output is correct
17 Correct 216 ms 18780 KB Output is correct
18 Correct 158 ms 18652 KB Output is correct
19 Correct 163 ms 18684 KB Output is correct
20 Correct 6 ms 7404 KB Output is correct
21 Correct 364 ms 21340 KB Output is correct
22 Correct 380 ms 21340 KB Output is correct
23 Correct 448 ms 21340 KB Output is correct
24 Correct 376 ms 21340 KB Output is correct
25 Correct 362 ms 21468 KB Output is correct
26 Correct 368 ms 21484 KB Output is correct
27 Correct 359 ms 21484 KB Output is correct
28 Correct 191 ms 21212 KB Output is correct
29 Correct 190 ms 21212 KB Output is correct
30 Correct 5 ms 7404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 7404 KB Output is correct
2 Correct 228 ms 25920 KB Output is correct
3 Correct 216 ms 25948 KB Output is correct
4 Correct 227 ms 25876 KB Output is correct
5 Correct 221 ms 25820 KB Output is correct
6 Correct 224 ms 25948 KB Output is correct
7 Correct 217 ms 25972 KB Output is correct
8 Correct 237 ms 25820 KB Output is correct
9 Correct 223 ms 21468 KB Output is correct
10 Correct 223 ms 21340 KB Output is correct
11 Correct 164 ms 19164 KB Output is correct
12 Correct 168 ms 19292 KB Output is correct
13 Correct 166 ms 19292 KB Output is correct
14 Correct 166 ms 19292 KB Output is correct
15 Correct 163 ms 19564 KB Output is correct
16 Correct 171 ms 19420 KB Output is correct
17 Correct 160 ms 19184 KB Output is correct
18 Correct 152 ms 19036 KB Output is correct
19 Correct 151 ms 19164 KB Output is correct
20 Correct 6 ms 7404 KB Output is correct
21 Correct 220 ms 19036 KB Output is correct
22 Correct 215 ms 18908 KB Output is correct
23 Correct 233 ms 18844 KB Output is correct
24 Correct 216 ms 18908 KB Output is correct
25 Correct 212 ms 18908 KB Output is correct
26 Correct 218 ms 18908 KB Output is correct
27 Correct 216 ms 18780 KB Output is correct
28 Correct 158 ms 18652 KB Output is correct
29 Correct 163 ms 18684 KB Output is correct
30 Correct 6 ms 7404 KB Output is correct
31 Correct 5 ms 7404 KB Output is correct
32 Correct 5 ms 7404 KB Output is correct
33 Correct 5 ms 7404 KB Output is correct
34 Correct 6 ms 7404 KB Output is correct
35 Correct 6 ms 7404 KB Output is correct
36 Correct 6 ms 7404 KB Output is correct
37 Correct 6 ms 7404 KB Output is correct
38 Correct 6 ms 7404 KB Output is correct
39 Correct 6 ms 7436 KB Output is correct
40 Correct 6 ms 7404 KB Output is correct
41 Correct 14 ms 8148 KB Output is correct
42 Correct 13 ms 8172 KB Output is correct
43 Correct 14 ms 8172 KB Output is correct
44 Correct 14 ms 8172 KB Output is correct
45 Correct 14 ms 8172 KB Output is correct
46 Correct 14 ms 8172 KB Output is correct
47 Correct 16 ms 8172 KB Output is correct
48 Correct 16 ms 8044 KB Output is correct
49 Correct 13 ms 7916 KB Output is correct
50 Correct 5 ms 7404 KB Output is correct
51 Correct 364 ms 21340 KB Output is correct
52 Correct 380 ms 21340 KB Output is correct
53 Correct 448 ms 21340 KB Output is correct
54 Correct 376 ms 21340 KB Output is correct
55 Correct 362 ms 21468 KB Output is correct
56 Correct 368 ms 21484 KB Output is correct
57 Correct 359 ms 21484 KB Output is correct
58 Correct 191 ms 21212 KB Output is correct
59 Correct 190 ms 21212 KB Output is correct
60 Correct 5 ms 7404 KB Output is correct
61 Correct 466 ms 31196 KB Output is correct
62 Correct 474 ms 31068 KB Output is correct
63 Correct 461 ms 31068 KB Output is correct
64 Correct 456 ms 31068 KB Output is correct
65 Correct 447 ms 31068 KB Output is correct
66 Correct 467 ms 31200 KB Output is correct
67 Correct 470 ms 31068 KB Output is correct
68 Correct 411 ms 26892 KB Output is correct
69 Correct 401 ms 22496 KB Output is correct
70 Correct 5 ms 7404 KB Output is correct