답안 #583508

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583508 2022-06-25T12:52:58 Z Kanaifu Mountains (NOI20_mountains) C++14
100 / 100
103 ms 10072 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define fr first
#define sc second

int tree[300001];
int n;

int sum(int ind)
{
    int zbir = 0;
    while (ind > 0)
    {
        zbir += tree[ind];
        ind = (ind)&(ind-1);
    }
    return zbir;
}

void update(int ind)
{
    while (ind <= n)
    {
        tree[ind]++;
        ind += (ind & (-ind));
    }
}

long long query(int left, int right)
{
    return (sum(right) - sum(left - 1));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long brojac = 0;
    memset(tree, 0, sizeof(tree));
    vector <int> reset;
    vector <pair<long long, int>> order;
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        long long height;
        cin>>height;
        order.pb({height, i});
    }
    sort(order.begin(), order.end());
    long long last = -1;
    for (int i=0; i<order.size(); i++)
    {
        if (order[i].fr != last)
        {
            for (int el : reset)
            {
                update(el);
            }
            reset.clear();
        }
        brojac += (query(1, order[i].sc-1))*(query(order[i].sc+1, n));
        reset.pb(order[i].sc);
        last = order[i].fr;
    }
    cout<<brojac;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for (int i=0; i<order.size(); i++)
      |                   ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 73 ms 9824 KB Output is correct
3 Correct 71 ms 9836 KB Output is correct
4 Correct 70 ms 9916 KB Output is correct
5 Correct 75 ms 9788 KB Output is correct
6 Correct 71 ms 9748 KB Output is correct
7 Correct 68 ms 9760 KB Output is correct
8 Correct 76 ms 9828 KB Output is correct
9 Correct 78 ms 9828 KB Output is correct
10 Correct 75 ms 9824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 9800 KB Output is correct
2 Correct 65 ms 9800 KB Output is correct
3 Correct 61 ms 9752 KB Output is correct
4 Correct 58 ms 9804 KB Output is correct
5 Correct 59 ms 9804 KB Output is correct
6 Correct 56 ms 9804 KB Output is correct
7 Correct 56 ms 9800 KB Output is correct
8 Correct 43 ms 9800 KB Output is correct
9 Correct 52 ms 9828 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 9800 KB Output is correct
2 Correct 65 ms 9800 KB Output is correct
3 Correct 61 ms 9752 KB Output is correct
4 Correct 58 ms 9804 KB Output is correct
5 Correct 59 ms 9804 KB Output is correct
6 Correct 56 ms 9804 KB Output is correct
7 Correct 56 ms 9800 KB Output is correct
8 Correct 43 ms 9800 KB Output is correct
9 Correct 52 ms 9828 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 71 ms 9776 KB Output is correct
12 Correct 74 ms 9800 KB Output is correct
13 Correct 71 ms 9800 KB Output is correct
14 Correct 67 ms 9800 KB Output is correct
15 Correct 71 ms 9788 KB Output is correct
16 Correct 73 ms 9740 KB Output is correct
17 Correct 69 ms 9800 KB Output is correct
18 Correct 45 ms 9800 KB Output is correct
19 Correct 49 ms 9904 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 1 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 4 ms 1876 KB Output is correct
12 Correct 4 ms 1876 KB Output is correct
13 Correct 4 ms 1876 KB Output is correct
14 Correct 4 ms 1876 KB Output is correct
15 Correct 3 ms 1876 KB Output is correct
16 Correct 4 ms 1876 KB Output is correct
17 Correct 4 ms 1876 KB Output is correct
18 Correct 4 ms 1804 KB Output is correct
19 Correct 3 ms 1876 KB Output is correct
20 Correct 1 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 9800 KB Output is correct
2 Correct 65 ms 9800 KB Output is correct
3 Correct 61 ms 9752 KB Output is correct
4 Correct 58 ms 9804 KB Output is correct
5 Correct 59 ms 9804 KB Output is correct
6 Correct 56 ms 9804 KB Output is correct
7 Correct 56 ms 9800 KB Output is correct
8 Correct 43 ms 9800 KB Output is correct
9 Correct 52 ms 9828 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 71 ms 9776 KB Output is correct
12 Correct 74 ms 9800 KB Output is correct
13 Correct 71 ms 9800 KB Output is correct
14 Correct 67 ms 9800 KB Output is correct
15 Correct 71 ms 9788 KB Output is correct
16 Correct 73 ms 9740 KB Output is correct
17 Correct 69 ms 9800 KB Output is correct
18 Correct 45 ms 9800 KB Output is correct
19 Correct 49 ms 9904 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
21 Correct 74 ms 9788 KB Output is correct
22 Correct 80 ms 9848 KB Output is correct
23 Correct 87 ms 9800 KB Output is correct
24 Correct 73 ms 10072 KB Output is correct
25 Correct 72 ms 9804 KB Output is correct
26 Correct 70 ms 9788 KB Output is correct
27 Correct 73 ms 9788 KB Output is correct
28 Correct 48 ms 9808 KB Output is correct
29 Correct 49 ms 9816 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 73 ms 9824 KB Output is correct
3 Correct 71 ms 9836 KB Output is correct
4 Correct 70 ms 9916 KB Output is correct
5 Correct 75 ms 9788 KB Output is correct
6 Correct 71 ms 9748 KB Output is correct
7 Correct 68 ms 9760 KB Output is correct
8 Correct 76 ms 9828 KB Output is correct
9 Correct 78 ms 9828 KB Output is correct
10 Correct 75 ms 9824 KB Output is correct
11 Correct 54 ms 9800 KB Output is correct
12 Correct 65 ms 9800 KB Output is correct
13 Correct 61 ms 9752 KB Output is correct
14 Correct 58 ms 9804 KB Output is correct
15 Correct 59 ms 9804 KB Output is correct
16 Correct 56 ms 9804 KB Output is correct
17 Correct 56 ms 9800 KB Output is correct
18 Correct 43 ms 9800 KB Output is correct
19 Correct 52 ms 9828 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
21 Correct 71 ms 9776 KB Output is correct
22 Correct 74 ms 9800 KB Output is correct
23 Correct 71 ms 9800 KB Output is correct
24 Correct 67 ms 9800 KB Output is correct
25 Correct 71 ms 9788 KB Output is correct
26 Correct 73 ms 9740 KB Output is correct
27 Correct 69 ms 9800 KB Output is correct
28 Correct 45 ms 9800 KB Output is correct
29 Correct 49 ms 9904 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
31 Correct 1 ms 1492 KB Output is correct
32 Correct 1 ms 1492 KB Output is correct
33 Correct 1 ms 1492 KB Output is correct
34 Correct 1 ms 1492 KB Output is correct
35 Correct 1 ms 1492 KB Output is correct
36 Correct 1 ms 1492 KB Output is correct
37 Correct 1 ms 1492 KB Output is correct
38 Correct 1 ms 1492 KB Output is correct
39 Correct 1 ms 1492 KB Output is correct
40 Correct 1 ms 1492 KB Output is correct
41 Correct 4 ms 1876 KB Output is correct
42 Correct 4 ms 1876 KB Output is correct
43 Correct 4 ms 1876 KB Output is correct
44 Correct 4 ms 1876 KB Output is correct
45 Correct 3 ms 1876 KB Output is correct
46 Correct 4 ms 1876 KB Output is correct
47 Correct 4 ms 1876 KB Output is correct
48 Correct 4 ms 1804 KB Output is correct
49 Correct 3 ms 1876 KB Output is correct
50 Correct 1 ms 1364 KB Output is correct
51 Correct 74 ms 9788 KB Output is correct
52 Correct 80 ms 9848 KB Output is correct
53 Correct 87 ms 9800 KB Output is correct
54 Correct 73 ms 10072 KB Output is correct
55 Correct 72 ms 9804 KB Output is correct
56 Correct 70 ms 9788 KB Output is correct
57 Correct 73 ms 9788 KB Output is correct
58 Correct 48 ms 9808 KB Output is correct
59 Correct 49 ms 9816 KB Output is correct
60 Correct 1 ms 1364 KB Output is correct
61 Correct 96 ms 9708 KB Output is correct
62 Correct 94 ms 9784 KB Output is correct
63 Correct 94 ms 9804 KB Output is correct
64 Correct 89 ms 9792 KB Output is correct
65 Correct 93 ms 9788 KB Output is correct
66 Correct 96 ms 9760 KB Output is correct
67 Correct 92 ms 9784 KB Output is correct
68 Correct 103 ms 9756 KB Output is correct
69 Correct 87 ms 9784 KB Output is correct
70 Correct 1 ms 1364 KB Output is correct