Submission #447355

# Submission time Handle Problem Language Result Execution time Memory
447355 2021-07-26T07:01:30 Z jhwest2 역사적 조사 (JOI14_historical) C++17
40 / 100
4000 ms 9288 KB
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long lint;
typedef pair<int, int> pint;

const int M = 1e5 + 10, SQ = 1000;

int n, q, A[M], Count[M];
lint Ans[M];
pair<pint, int> Qry[M];
vector<lint> V;

struct Set {
    multiset<lint> St;

    void insert(lint x) {
        St.erase(St.find(Count[x] * V[x])); Count[x] += 1;
        St.insert(Count[x] * V[x]);
    }
    void erase(lint x) {
        St.erase(St.find(Count[x] * V[x])); Count[x] -= 1;
        St.insert(Count[x] * V[x]);
    }
    lint query() {
        return *prev(St.end());
    }
} St;

int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> A[i]; V.push_back(A[i]);
    }
    sort(V.begin(), V.end());
    V.erase(unique(V.begin(), V.end()), V.end());

    for (int i = 1; i <= n; i++) {
        A[i] = lower_bound(V.begin(), V.end(), A[i]) - V.begin();
    }
    for (int i = 1; i <= q; i++) {
        cin >> Qry[i].va.va >> Qry[i].va.vb;
        Qry[i].vb = i;
    }
    stable_sort(Qry + 1, Qry + 1 + q, [&](auto a, auto b) {
        if (a.va.va / SQ == b.va.va / SQ) return a.va.vb <= b.va.vb;
        return a.va.va <= b.va.va;
        });

    for (int i = 1; i <= n; i++) St.St.insert(0);
    int l = 1, r = 0;
    for (int i = 1; i <= q; i++) {
        while (Qry[i].va.vb > r) St.insert(A[++r]);
        while (Qry[i].va.vb < r) St.erase(A[r--]);
        while (Qry[i].va.va > l) St.erase(A[l++]);
        while (Qry[i].va.va < l) St.insert(A[--l]);

        Ans[Qry[i].vb] = St.query();
    }
    for (int i = 1; i <= q; i++) {
        cout << Ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 7 ms 372 KB Output is correct
18 Correct 24 ms 404 KB Output is correct
19 Correct 80 ms 460 KB Output is correct
20 Correct 201 ms 588 KB Output is correct
21 Correct 300 ms 732 KB Output is correct
22 Correct 337 ms 716 KB Output is correct
23 Correct 285 ms 728 KB Output is correct
24 Correct 293 ms 836 KB Output is correct
25 Correct 372 ms 732 KB Output is correct
26 Correct 376 ms 732 KB Output is correct
27 Correct 378 ms 720 KB Output is correct
28 Correct 374 ms 836 KB Output is correct
29 Correct 361 ms 728 KB Output is correct
30 Correct 369 ms 716 KB Output is correct
31 Correct 289 ms 716 KB Output is correct
32 Correct 295 ms 732 KB Output is correct
33 Correct 370 ms 732 KB Output is correct
34 Correct 373 ms 716 KB Output is correct
35 Correct 366 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 3 ms 460 KB Output is correct
7 Correct 6 ms 716 KB Output is correct
8 Correct 13 ms 1104 KB Output is correct
9 Correct 27 ms 1816 KB Output is correct
10 Correct 47 ms 3240 KB Output is correct
11 Correct 137 ms 8392 KB Output is correct
12 Correct 115 ms 6112 KB Output is correct
13 Correct 117 ms 6756 KB Output is correct
14 Correct 143 ms 7828 KB Output is correct
15 Correct 169 ms 9288 KB Output is correct
16 Correct 143 ms 8052 KB Output is correct
17 Correct 102 ms 7068 KB Output is correct
18 Correct 131 ms 8316 KB Output is correct
19 Correct 139 ms 8880 KB Output is correct
20 Correct 85 ms 7036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 7 ms 372 KB Output is correct
18 Correct 24 ms 404 KB Output is correct
19 Correct 80 ms 460 KB Output is correct
20 Correct 201 ms 588 KB Output is correct
21 Correct 300 ms 732 KB Output is correct
22 Correct 337 ms 716 KB Output is correct
23 Correct 285 ms 728 KB Output is correct
24 Correct 293 ms 836 KB Output is correct
25 Correct 372 ms 732 KB Output is correct
26 Correct 376 ms 732 KB Output is correct
27 Correct 378 ms 720 KB Output is correct
28 Correct 374 ms 836 KB Output is correct
29 Correct 361 ms 728 KB Output is correct
30 Correct 369 ms 716 KB Output is correct
31 Correct 289 ms 716 KB Output is correct
32 Correct 295 ms 732 KB Output is correct
33 Correct 370 ms 732 KB Output is correct
34 Correct 373 ms 716 KB Output is correct
35 Correct 366 ms 724 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 3 ms 460 KB Output is correct
42 Correct 6 ms 716 KB Output is correct
43 Correct 13 ms 1104 KB Output is correct
44 Correct 27 ms 1816 KB Output is correct
45 Correct 47 ms 3240 KB Output is correct
46 Correct 137 ms 8392 KB Output is correct
47 Correct 115 ms 6112 KB Output is correct
48 Correct 117 ms 6756 KB Output is correct
49 Correct 143 ms 7828 KB Output is correct
50 Correct 169 ms 9288 KB Output is correct
51 Correct 143 ms 8052 KB Output is correct
52 Correct 102 ms 7068 KB Output is correct
53 Correct 131 ms 8316 KB Output is correct
54 Correct 139 ms 8880 KB Output is correct
55 Correct 85 ms 7036 KB Output is correct
56 Correct 655 ms 1104 KB Output is correct
57 Correct 1779 ms 2024 KB Output is correct
58 Correct 3486 ms 2948 KB Output is correct
59 Execution timed out 4072 ms 3448 KB Time limit exceeded
60 Halted 0 ms 0 KB -