답안 #439073

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439073 2021-06-29T07:30:04 Z meatrow Mountains (NOI20_mountains) C++17
100 / 100
1018 ms 31000 KB
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
int t[1200000];
long long g[300000];
int left1[300000], right1[300000];
void update (int v, int tl, int tr, int h) {
    if (tl == tr)
        t[v]++;
    else {
        int tm = (tl + tr) / 2;
        if (h <= tm)
            update (v*2, tl, tm, h);
        else
            update (v*2+1, tm+1, tr, h);
        t[v] = t[v*2] + t[v*2+1];
    }
}
int sum (int v, int tl, int tr, int l, int r) {
    if (l > r)
        return 0;
    if (l == tl && r == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    return sum (v*2, tl, tm, l, min(r,tm))
           + sum (v*2+1, tm+1, tr, max(l,tm+1), r);
}
int main(){
    int n;
    cin >> n;
    vector<long long>b;
    for(int i = 0; i < n; i++){
        cin >> g[i];
        b.push_back(g[i]);
    }
    sort(b.begin(), b.end());
    map<long long,int>c;
    for(int i = 0; i < b.size(); i++){
        c[b[i]] = i;
    }
    for(int i = 0; i < n; i++){
        g[i] = c[g[i]];
    }
    update(1, 0, n, g[0]);
    for(int i = 1; i < n - 1; i++){
        left1[i] = sum(1, 0, n, 0, g[i] - 1);
        update(1, 0, n, g[i]);
    }
    memset(t, 0, sizeof(t[0]) * 1200000);
    update(1, 0, n, g[n - 1]);
    for(int i = n - 2; i >= 1; i--){
        right1[i] = sum(1, 0, n, 0, g[i] - 1);
        update(1, 0, n, g[i]);
    }
    long long int ans = 0;
    for(int i = 1; i < n - 1; i++){
        ans += 1LL * left1[i] * right1[i];
    }
    cout << ans;
    return 0;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:41:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i = 0; i < b.size(); i++){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 512 ms 30748 KB Output is correct
3 Correct 518 ms 30840 KB Output is correct
4 Correct 514 ms 30712 KB Output is correct
5 Correct 598 ms 30760 KB Output is correct
6 Correct 518 ms 30720 KB Output is correct
7 Correct 536 ms 30780 KB Output is correct
8 Correct 532 ms 30736 KB Output is correct
9 Correct 482 ms 21668 KB Output is correct
10 Correct 483 ms 21768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 12072 KB Output is correct
2 Correct 222 ms 12084 KB Output is correct
3 Correct 212 ms 12224 KB Output is correct
4 Correct 216 ms 12032 KB Output is correct
5 Correct 212 ms 12040 KB Output is correct
6 Correct 215 ms 12200 KB Output is correct
7 Correct 218 ms 12120 KB Output is correct
8 Correct 211 ms 12052 KB Output is correct
9 Correct 202 ms 12200 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 12072 KB Output is correct
2 Correct 222 ms 12084 KB Output is correct
3 Correct 212 ms 12224 KB Output is correct
4 Correct 216 ms 12032 KB Output is correct
5 Correct 212 ms 12040 KB Output is correct
6 Correct 215 ms 12200 KB Output is correct
7 Correct 218 ms 12120 KB Output is correct
8 Correct 211 ms 12052 KB Output is correct
9 Correct 202 ms 12200 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 298 ms 12192 KB Output is correct
12 Correct 305 ms 12128 KB Output is correct
13 Correct 304 ms 12096 KB Output is correct
14 Correct 313 ms 12244 KB Output is correct
15 Correct 309 ms 12136 KB Output is correct
16 Correct 306 ms 12128 KB Output is correct
17 Correct 309 ms 12224 KB Output is correct
18 Correct 249 ms 12108 KB Output is correct
19 Correct 219 ms 12092 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5048 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 5032 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 5052 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5048 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 5032 KB Output is correct
4 Correct 4 ms 4940 KB Output is correct
5 Correct 4 ms 5052 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 20 ms 5836 KB Output is correct
12 Correct 21 ms 5848 KB Output is correct
13 Correct 20 ms 5852 KB Output is correct
14 Correct 23 ms 5816 KB Output is correct
15 Correct 20 ms 5844 KB Output is correct
16 Correct 20 ms 5836 KB Output is correct
17 Correct 20 ms 5836 KB Output is correct
18 Correct 22 ms 5516 KB Output is correct
19 Correct 15 ms 5356 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 12072 KB Output is correct
2 Correct 222 ms 12084 KB Output is correct
3 Correct 212 ms 12224 KB Output is correct
4 Correct 216 ms 12032 KB Output is correct
5 Correct 212 ms 12040 KB Output is correct
6 Correct 215 ms 12200 KB Output is correct
7 Correct 218 ms 12120 KB Output is correct
8 Correct 211 ms 12052 KB Output is correct
9 Correct 202 ms 12200 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 298 ms 12192 KB Output is correct
12 Correct 305 ms 12128 KB Output is correct
13 Correct 304 ms 12096 KB Output is correct
14 Correct 313 ms 12244 KB Output is correct
15 Correct 309 ms 12136 KB Output is correct
16 Correct 306 ms 12128 KB Output is correct
17 Correct 309 ms 12224 KB Output is correct
18 Correct 249 ms 12108 KB Output is correct
19 Correct 219 ms 12092 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 580 ms 17980 KB Output is correct
22 Correct 563 ms 17852 KB Output is correct
23 Correct 618 ms 18096 KB Output is correct
24 Correct 573 ms 18008 KB Output is correct
25 Correct 586 ms 17960 KB Output is correct
26 Correct 588 ms 17928 KB Output is correct
27 Correct 717 ms 18052 KB Output is correct
28 Correct 347 ms 17944 KB Output is correct
29 Correct 341 ms 17964 KB Output is correct
30 Correct 3 ms 4940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 512 ms 30748 KB Output is correct
3 Correct 518 ms 30840 KB Output is correct
4 Correct 514 ms 30712 KB Output is correct
5 Correct 598 ms 30760 KB Output is correct
6 Correct 518 ms 30720 KB Output is correct
7 Correct 536 ms 30780 KB Output is correct
8 Correct 532 ms 30736 KB Output is correct
9 Correct 482 ms 21668 KB Output is correct
10 Correct 483 ms 21768 KB Output is correct
11 Correct 217 ms 12072 KB Output is correct
12 Correct 222 ms 12084 KB Output is correct
13 Correct 212 ms 12224 KB Output is correct
14 Correct 216 ms 12032 KB Output is correct
15 Correct 212 ms 12040 KB Output is correct
16 Correct 215 ms 12200 KB Output is correct
17 Correct 218 ms 12120 KB Output is correct
18 Correct 211 ms 12052 KB Output is correct
19 Correct 202 ms 12200 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 298 ms 12192 KB Output is correct
22 Correct 305 ms 12128 KB Output is correct
23 Correct 304 ms 12096 KB Output is correct
24 Correct 313 ms 12244 KB Output is correct
25 Correct 309 ms 12136 KB Output is correct
26 Correct 306 ms 12128 KB Output is correct
27 Correct 309 ms 12224 KB Output is correct
28 Correct 249 ms 12108 KB Output is correct
29 Correct 219 ms 12092 KB Output is correct
30 Correct 3 ms 4940 KB Output is correct
31 Correct 4 ms 5048 KB Output is correct
32 Correct 4 ms 4940 KB Output is correct
33 Correct 4 ms 5032 KB Output is correct
34 Correct 4 ms 4940 KB Output is correct
35 Correct 4 ms 5052 KB Output is correct
36 Correct 3 ms 4940 KB Output is correct
37 Correct 3 ms 4940 KB Output is correct
38 Correct 3 ms 4940 KB Output is correct
39 Correct 3 ms 4940 KB Output is correct
40 Correct 3 ms 4940 KB Output is correct
41 Correct 20 ms 5836 KB Output is correct
42 Correct 21 ms 5848 KB Output is correct
43 Correct 20 ms 5852 KB Output is correct
44 Correct 23 ms 5816 KB Output is correct
45 Correct 20 ms 5844 KB Output is correct
46 Correct 20 ms 5836 KB Output is correct
47 Correct 20 ms 5836 KB Output is correct
48 Correct 22 ms 5516 KB Output is correct
49 Correct 15 ms 5356 KB Output is correct
50 Correct 3 ms 4940 KB Output is correct
51 Correct 580 ms 17980 KB Output is correct
52 Correct 563 ms 17852 KB Output is correct
53 Correct 618 ms 18096 KB Output is correct
54 Correct 573 ms 18008 KB Output is correct
55 Correct 586 ms 17960 KB Output is correct
56 Correct 588 ms 17928 KB Output is correct
57 Correct 717 ms 18052 KB Output is correct
58 Correct 347 ms 17944 KB Output is correct
59 Correct 341 ms 17964 KB Output is correct
60 Correct 3 ms 4940 KB Output is correct
61 Correct 960 ms 30700 KB Output is correct
62 Correct 993 ms 31000 KB Output is correct
63 Correct 964 ms 30804 KB Output is correct
64 Correct 963 ms 30796 KB Output is correct
65 Correct 916 ms 30880 KB Output is correct
66 Correct 962 ms 30696 KB Output is correct
67 Correct 1018 ms 30692 KB Output is correct
68 Correct 864 ms 21756 KB Output is correct
69 Correct 676 ms 20144 KB Output is correct
70 Correct 3 ms 4940 KB Output is correct