답안 #259051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259051 2020-08-07T05:23:42 Z 강태규(#5095) 역사적 조사 (JOI14_historical) C++17
100 / 100
287 ms 8976 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];
vector<int> cp;
llong ans[100001];
vector<int> Q[100001];
int S[100001], E[100001];
llong val[100001];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> q;
    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 >> S[i] >> E[i];
        if (E[i] - S[i] <= B) {
            for (int j = S[i]; j <= E[i]; ++j) {
                ans[i] = max(ans[i], val[X[j]] += cp[X[j]]);
            }
            for (int j = S[i]; j <= E[i]; ++j) {
                val[X[j]] = 0;
            }
            continue;
        }
        Q[S[i] / B].push_back(i);
    }
    for (int i = 0; i <= n; ++i) {
        if (Q[i].empty()) continue;
        sort(Q[i].begin(), Q[i].end(), [&](int a, int b) {
            return E[a] < E[b];
        });
        int x = (i + 1) * B;
        llong mx = 0;
        memset(val, 0, sizeof(val));
        for (int j : Q[i]) {
            while (x <= E[j]) mx = max(mx, val[X[x]] += cp[X[x]]), ++x;
            ans[j] = mx;
            for (int k = S[j]; k < (i + 1) * B; ++k) {
                ans[j] = max(ans[j], val[X[k]] += cp[X[k]]);
            }
            for (int k = S[j]; k < (i + 1) * B; ++k) {
                val[X[k]] -= cp[X[k]];
            }
        }
    }
    for (int i = 1; i <= q; ++i) {
        printf("%lld\n", ans[i]);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 5 ms 3456 KB Output is correct
19 Correct 5 ms 3584 KB Output is correct
20 Correct 8 ms 3584 KB Output is correct
21 Correct 13 ms 3712 KB Output is correct
22 Correct 13 ms 3712 KB Output is correct
23 Correct 13 ms 3712 KB Output is correct
24 Correct 12 ms 3712 KB Output is correct
25 Correct 12 ms 3712 KB Output is correct
26 Correct 13 ms 3712 KB Output is correct
27 Correct 12 ms 3712 KB Output is correct
28 Correct 11 ms 3712 KB Output is correct
29 Correct 13 ms 3712 KB Output is correct
30 Correct 14 ms 3712 KB Output is correct
31 Correct 12 ms 3712 KB Output is correct
32 Correct 15 ms 3712 KB Output is correct
33 Correct 12 ms 3712 KB Output is correct
34 Correct 14 ms 3712 KB Output is correct
35 Correct 15 ms 3712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 2688 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 5 ms 3584 KB Output is correct
8 Correct 6 ms 3712 KB Output is correct
9 Correct 12 ms 3848 KB Output is correct
10 Correct 12 ms 4096 KB Output is correct
11 Correct 103 ms 5496 KB Output is correct
12 Correct 28 ms 4348 KB Output is correct
13 Correct 71 ms 4892 KB Output is correct
14 Correct 118 ms 5748 KB Output is correct
15 Correct 73 ms 6640 KB Output is correct
16 Correct 168 ms 6008 KB Output is correct
17 Correct 91 ms 5108 KB Output is correct
18 Correct 163 ms 6516 KB Output is correct
19 Correct 175 ms 6772 KB Output is correct
20 Correct 71 ms 4852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 5 ms 3456 KB Output is correct
19 Correct 5 ms 3584 KB Output is correct
20 Correct 8 ms 3584 KB Output is correct
21 Correct 13 ms 3712 KB Output is correct
22 Correct 13 ms 3712 KB Output is correct
23 Correct 13 ms 3712 KB Output is correct
24 Correct 12 ms 3712 KB Output is correct
25 Correct 12 ms 3712 KB Output is correct
26 Correct 13 ms 3712 KB Output is correct
27 Correct 12 ms 3712 KB Output is correct
28 Correct 11 ms 3712 KB Output is correct
29 Correct 13 ms 3712 KB Output is correct
30 Correct 14 ms 3712 KB Output is correct
31 Correct 12 ms 3712 KB Output is correct
32 Correct 15 ms 3712 KB Output is correct
33 Correct 12 ms 3712 KB Output is correct
34 Correct 14 ms 3712 KB Output is correct
35 Correct 15 ms 3712 KB Output is correct
36 Correct 2 ms 2688 KB Output is correct
37 Correct 2 ms 2688 KB Output is correct
38 Correct 2 ms 2688 KB Output is correct
39 Correct 2 ms 2688 KB Output is correct
40 Correct 3 ms 2688 KB Output is correct
41 Correct 3 ms 2816 KB Output is correct
42 Correct 5 ms 3584 KB Output is correct
43 Correct 6 ms 3712 KB Output is correct
44 Correct 12 ms 3848 KB Output is correct
45 Correct 12 ms 4096 KB Output is correct
46 Correct 103 ms 5496 KB Output is correct
47 Correct 28 ms 4348 KB Output is correct
48 Correct 71 ms 4892 KB Output is correct
49 Correct 118 ms 5748 KB Output is correct
50 Correct 73 ms 6640 KB Output is correct
51 Correct 168 ms 6008 KB Output is correct
52 Correct 91 ms 5108 KB Output is correct
53 Correct 163 ms 6516 KB Output is correct
54 Correct 175 ms 6772 KB Output is correct
55 Correct 71 ms 4852 KB Output is correct
56 Correct 22 ms 3840 KB Output is correct
57 Correct 44 ms 4268 KB Output is correct
58 Correct 70 ms 4728 KB Output is correct
59 Correct 98 ms 5112 KB Output is correct
60 Correct 122 ms 5496 KB Output is correct
61 Correct 145 ms 5880 KB Output is correct
62 Correct 168 ms 6388 KB Output is correct
63 Correct 189 ms 7028 KB Output is correct
64 Correct 213 ms 7384 KB Output is correct
65 Correct 236 ms 7528 KB Output is correct
66 Correct 242 ms 7536 KB Output is correct
67 Correct 250 ms 7536 KB Output is correct
68 Correct 263 ms 7544 KB Output is correct
69 Correct 273 ms 7540 KB Output is correct
70 Correct 279 ms 7540 KB Output is correct
71 Correct 279 ms 7536 KB Output is correct
72 Correct 281 ms 7640 KB Output is correct
73 Correct 281 ms 7540 KB Output is correct
74 Correct 287 ms 7668 KB Output is correct
75 Correct 281 ms 7668 KB Output is correct
76 Correct 276 ms 8044 KB Output is correct
77 Correct 275 ms 8692 KB Output is correct
78 Correct 276 ms 8716 KB Output is correct
79 Correct 273 ms 8692 KB Output is correct
80 Correct 241 ms 8976 KB Output is correct