답안 #337336

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337336 2020-12-19T20:55:20 Z iulia13 Mountains (NOI20_mountains) C++14
100 / 100
895 ms 36588 KB
#include <bits/stdc++.h>

using namespace std;
#define ll long long
ll h[300005];
ll hh[300005];
map <ll, int> mp;
int v[300005];
int seg[12000005];
void update(int nod, int l, int r, int poz, int val)
{
    int mid;
    if (r == l)
    {
        seg[nod] += val;
        return;
    }
    mid = (l + r) / 2;
    if (poz <= mid)
        update (2 * nod, l, mid, poz, val);
    else
        update (2 * nod + 1, mid + 1, r, poz, val);
    seg[nod] = seg[2 * nod] + seg[2 * nod + 1];
}
int query (int nod, int l, int r, int ql, int qr)
{
    int mid;
    if (ql <= l&& r <= qr)
        return seg[nod];
    mid = (l + r) / 2;
    int s = 0;
    if (mid >= ql)
        s += query(2 * nod, l, mid, ql, qr);
    if (mid < qr)
        s += query(2 * nod + 1, mid + 1, r, ql, qr);
    return s;

}
int d[300005];
int main()
{
    int n, i;
    ll ans = 0;
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> h[i];
        hh[i] = h[i];
    }
    sort (hh + 1, hh + n + 1);
    mp[hh[1]] = 1;
    int l = 1;
    for (i = 2; i <= n; i++)
    {
        if (hh[i] != hh[i - 1])
        {
            l++;
            mp[hh[i]] = l;
        }
    }
    for (i = 1; i <= n; i++)
        v[i] = mp[h[i]];
    for (i = 1; i <= n; i++)
    {
        if (v[i] - 1)
        d[i] = query(1, 1, n, 1, v[i] - 1);
        update(1, 1, n, v[i], 1);
    }
    for (i = 1; i <= 4 * n; i++)
        seg[i] = 0;
    for (i = n; i; i--)
    {
        if (v[i] - 1)
        ans += 1LL * query(1, 1, n, 1, v[i] - 1) * d[i];
        update(1, 1, n, v[i], 1);
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 508 ms 36580 KB Output is correct
3 Correct 502 ms 36544 KB Output is correct
4 Correct 499 ms 36460 KB Output is correct
5 Correct 501 ms 36524 KB Output is correct
6 Correct 499 ms 36588 KB Output is correct
7 Correct 503 ms 36460 KB Output is correct
8 Correct 501 ms 36452 KB Output is correct
9 Correct 452 ms 27500 KB Output is correct
10 Correct 449 ms 27372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 12672 KB Output is correct
2 Correct 180 ms 12652 KB Output is correct
3 Correct 180 ms 12856 KB Output is correct
4 Correct 180 ms 12780 KB Output is correct
5 Correct 181 ms 12652 KB Output is correct
6 Correct 181 ms 12652 KB Output is correct
7 Correct 180 ms 12732 KB Output is correct
8 Correct 169 ms 12144 KB Output is correct
9 Correct 168 ms 12140 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 12672 KB Output is correct
2 Correct 180 ms 12652 KB Output is correct
3 Correct 180 ms 12856 KB Output is correct
4 Correct 180 ms 12780 KB Output is correct
5 Correct 181 ms 12652 KB Output is correct
6 Correct 181 ms 12652 KB Output is correct
7 Correct 180 ms 12732 KB Output is correct
8 Correct 169 ms 12144 KB Output is correct
9 Correct 168 ms 12140 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 254 ms 12932 KB Output is correct
12 Correct 251 ms 12928 KB Output is correct
13 Correct 249 ms 12908 KB Output is correct
14 Correct 255 ms 12888 KB Output is correct
15 Correct 253 ms 12908 KB Output is correct
16 Correct 252 ms 12908 KB Output is correct
17 Correct 251 ms 12908 KB Output is correct
18 Correct 199 ms 13036 KB Output is correct
19 Correct 197 ms 13036 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 18 ms 1516 KB Output is correct
12 Correct 17 ms 1516 KB Output is correct
13 Correct 17 ms 1516 KB Output is correct
14 Correct 18 ms 1516 KB Output is correct
15 Correct 18 ms 1536 KB Output is correct
16 Correct 17 ms 1516 KB Output is correct
17 Correct 17 ms 1516 KB Output is correct
18 Correct 16 ms 1132 KB Output is correct
19 Correct 9 ms 748 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 12672 KB Output is correct
2 Correct 180 ms 12652 KB Output is correct
3 Correct 180 ms 12856 KB Output is correct
4 Correct 180 ms 12780 KB Output is correct
5 Correct 181 ms 12652 KB Output is correct
6 Correct 181 ms 12652 KB Output is correct
7 Correct 180 ms 12732 KB Output is correct
8 Correct 169 ms 12144 KB Output is correct
9 Correct 168 ms 12140 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 254 ms 12932 KB Output is correct
12 Correct 251 ms 12928 KB Output is correct
13 Correct 249 ms 12908 KB Output is correct
14 Correct 255 ms 12888 KB Output is correct
15 Correct 253 ms 12908 KB Output is correct
16 Correct 252 ms 12908 KB Output is correct
17 Correct 251 ms 12908 KB Output is correct
18 Correct 199 ms 13036 KB Output is correct
19 Correct 197 ms 13036 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 543 ms 19820 KB Output is correct
22 Correct 511 ms 19720 KB Output is correct
23 Correct 537 ms 19820 KB Output is correct
24 Correct 534 ms 19820 KB Output is correct
25 Correct 522 ms 19820 KB Output is correct
26 Correct 515 ms 19820 KB Output is correct
27 Correct 524 ms 19820 KB Output is correct
28 Correct 303 ms 19712 KB Output is correct
29 Correct 302 ms 20076 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 508 ms 36580 KB Output is correct
3 Correct 502 ms 36544 KB Output is correct
4 Correct 499 ms 36460 KB Output is correct
5 Correct 501 ms 36524 KB Output is correct
6 Correct 499 ms 36588 KB Output is correct
7 Correct 503 ms 36460 KB Output is correct
8 Correct 501 ms 36452 KB Output is correct
9 Correct 452 ms 27500 KB Output is correct
10 Correct 449 ms 27372 KB Output is correct
11 Correct 180 ms 12672 KB Output is correct
12 Correct 180 ms 12652 KB Output is correct
13 Correct 180 ms 12856 KB Output is correct
14 Correct 180 ms 12780 KB Output is correct
15 Correct 181 ms 12652 KB Output is correct
16 Correct 181 ms 12652 KB Output is correct
17 Correct 180 ms 12732 KB Output is correct
18 Correct 169 ms 12144 KB Output is correct
19 Correct 168 ms 12140 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 254 ms 12932 KB Output is correct
22 Correct 251 ms 12928 KB Output is correct
23 Correct 249 ms 12908 KB Output is correct
24 Correct 255 ms 12888 KB Output is correct
25 Correct 253 ms 12908 KB Output is correct
26 Correct 252 ms 12908 KB Output is correct
27 Correct 251 ms 12908 KB Output is correct
28 Correct 199 ms 13036 KB Output is correct
29 Correct 197 ms 13036 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 18 ms 1516 KB Output is correct
42 Correct 17 ms 1516 KB Output is correct
43 Correct 17 ms 1516 KB Output is correct
44 Correct 18 ms 1516 KB Output is correct
45 Correct 18 ms 1536 KB Output is correct
46 Correct 17 ms 1516 KB Output is correct
47 Correct 17 ms 1516 KB Output is correct
48 Correct 16 ms 1132 KB Output is correct
49 Correct 9 ms 748 KB Output is correct
50 Correct 1 ms 364 KB Output is correct
51 Correct 543 ms 19820 KB Output is correct
52 Correct 511 ms 19720 KB Output is correct
53 Correct 537 ms 19820 KB Output is correct
54 Correct 534 ms 19820 KB Output is correct
55 Correct 522 ms 19820 KB Output is correct
56 Correct 515 ms 19820 KB Output is correct
57 Correct 524 ms 19820 KB Output is correct
58 Correct 303 ms 19712 KB Output is correct
59 Correct 302 ms 20076 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 874 ms 36536 KB Output is correct
62 Correct 867 ms 36452 KB Output is correct
63 Correct 891 ms 36588 KB Output is correct
64 Correct 888 ms 36500 KB Output is correct
65 Correct 882 ms 36432 KB Output is correct
66 Correct 895 ms 36408 KB Output is correct
67 Correct 865 ms 36460 KB Output is correct
68 Correct 743 ms 27500 KB Output is correct
69 Correct 592 ms 21996 KB Output is correct
70 Correct 1 ms 364 KB Output is correct