답안 #259044

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259044 2020-08-07T05:04:57 Z 강태규(#5095) 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 51324 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long llong;
typedef pair<int, int> pii;

const int B = 400;
int n, q;
int X[100001];
pair<pii, int> Q[100001];
priority_queue<llong> pq1, pq2;
vector<int> cp;
int cnt[100001];

void add(int i) {
    int x = X[i];
    pq1.push(1ll * cp[x] * ++cnt[x]);
}

void sub(int i) {
    int x = X[i];
    pq2.push(1ll * cp[x] * cnt[x]--);
    while (!pq2.empty() && pq1.top() == pq2.top()) {
        pq1.pop();
        pq2.pop();
    }
}

llong ans[100001];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> q;
    pq1.push(0);
    for (int i = 1; i <= n; ++i) {
        cin >> X[i];
        cp.push_back(X[i]);
    }
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    for (int i = 1; i <= n; ++i) {
        X[i] = lower_bound(cp.begin(), cp.end(), X[i]) - cp.begin();
    }
    for (int i = 1; i <= q; ++i) {
        cin >> Q[i].first.first >> Q[i].first.second;
        Q[i].second = i;
    }
    sort(Q + 1, Q + (q + 1), [&](pair<pii, int> a, pair<pii, int> b) {
        int ga = a.first.first / B, gb = b.first.first / B;
        if (ga != gb) return ga < gb;
        return a.first.second < b.first.second;
    });
    int s = 1, e = 0;
    for (int i = 1; i <= q; ++i) {
        auto [x, y] = Q[i].first;
        while (e < y) add(++e);
        while (x < s) add(--s);
        while (y < e) sub(e--);
        while (s < x) sub(s++);
        ans[Q[i].second] = pq1.top();
    }
    for (int i = 1; i <= q; ++i) {
        printf("%lld\n", ans[i]);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 15 ms 1020 KB Output is correct
19 Correct 25 ms 1404 KB Output is correct
20 Correct 60 ms 1516 KB Output is correct
21 Correct 98 ms 1456 KB Output is correct
22 Correct 94 ms 1564 KB Output is correct
23 Correct 101 ms 1456 KB Output is correct
24 Correct 99 ms 1456 KB Output is correct
25 Correct 75 ms 3736 KB Output is correct
26 Correct 86 ms 3732 KB Output is correct
27 Correct 86 ms 2580 KB Output is correct
28 Correct 77 ms 3860 KB Output is correct
29 Correct 86 ms 3732 KB Output is correct
30 Correct 93 ms 2332 KB Output is correct
31 Correct 99 ms 1560 KB Output is correct
32 Correct 88 ms 1456 KB Output is correct
33 Correct 85 ms 3732 KB Output is correct
34 Correct 94 ms 3736 KB Output is correct
35 Correct 68 ms 3784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 640 KB Output is correct
8 Correct 6 ms 896 KB Output is correct
9 Correct 10 ms 1216 KB Output is correct
10 Correct 17 ms 896 KB Output is correct
11 Correct 78 ms 4212 KB Output is correct
12 Correct 42 ms 2288 KB Output is correct
13 Correct 65 ms 3528 KB Output is correct
14 Correct 85 ms 4084 KB Output is correct
15 Correct 88 ms 4468 KB Output is correct
16 Correct 59 ms 4772 KB Output is correct
17 Correct 30 ms 3192 KB Output is correct
18 Correct 57 ms 4776 KB Output is correct
19 Correct 60 ms 5484 KB Output is correct
20 Correct 33 ms 3316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 5 ms 512 KB Output is correct
18 Correct 15 ms 1020 KB Output is correct
19 Correct 25 ms 1404 KB Output is correct
20 Correct 60 ms 1516 KB Output is correct
21 Correct 98 ms 1456 KB Output is correct
22 Correct 94 ms 1564 KB Output is correct
23 Correct 101 ms 1456 KB Output is correct
24 Correct 99 ms 1456 KB Output is correct
25 Correct 75 ms 3736 KB Output is correct
26 Correct 86 ms 3732 KB Output is correct
27 Correct 86 ms 2580 KB Output is correct
28 Correct 77 ms 3860 KB Output is correct
29 Correct 86 ms 3732 KB Output is correct
30 Correct 93 ms 2332 KB Output is correct
31 Correct 99 ms 1560 KB Output is correct
32 Correct 88 ms 1456 KB Output is correct
33 Correct 85 ms 3732 KB Output is correct
34 Correct 94 ms 3736 KB Output is correct
35 Correct 68 ms 3784 KB Output is correct
36 Correct 0 ms 384 KB Output is correct
37 Correct 0 ms 384 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 3 ms 640 KB Output is correct
43 Correct 6 ms 896 KB Output is correct
44 Correct 10 ms 1216 KB Output is correct
45 Correct 17 ms 896 KB Output is correct
46 Correct 78 ms 4212 KB Output is correct
47 Correct 42 ms 2288 KB Output is correct
48 Correct 65 ms 3528 KB Output is correct
49 Correct 85 ms 4084 KB Output is correct
50 Correct 88 ms 4468 KB Output is correct
51 Correct 59 ms 4772 KB Output is correct
52 Correct 30 ms 3192 KB Output is correct
53 Correct 57 ms 4776 KB Output is correct
54 Correct 60 ms 5484 KB Output is correct
55 Correct 33 ms 3316 KB Output is correct
56 Correct 221 ms 1748 KB Output is correct
57 Correct 554 ms 4320 KB Output is correct
58 Correct 848 ms 15512 KB Output is correct
59 Correct 1519 ms 30408 KB Output is correct
60 Correct 1803 ms 51324 KB Output is correct
61 Correct 2585 ms 27908 KB Output is correct
62 Correct 3464 ms 9288 KB Output is correct
63 Correct 3968 ms 5920 KB Output is correct
64 Execution timed out 4085 ms 5616 KB Time limit exceeded
65 Halted 0 ms 0 KB -