Submission #996278

# Submission time Handle Problem Language Result Execution time Memory
996278 2024-06-10T10:49:31 Z vladilius 역사적 조사 (JOI14_historical) C++17
100 / 100
1755 ms 22892 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert

struct ST{
    vector<ll> t;
    int n;
    ST(int ns){
        n = ns;
        t.resize(4 * n);
    }
    void upd(int v, int tl, int tr, int& p, int& k){
        if (tl == tr){
            t[v] += k;
            return;
        }
        int tm = (tl + tr) / 2, vv = 2 * v;
        if (p <= tm){
            upd(vv, tl, tm, p, k);
        }
        else {
            upd(vv + 1, tm + 1, tr, p, k);
        }
        t[v] = max(t[vv], t[vv + 1]);
    }
    void upd(int p, int k){
        upd(1, 1, n, p, k);
    }
    ll get(int v, int tl, int tr, int& l, int& r){
        if (l > tr || r < tl) return 0;
        if (l <= tl && tr <= r) return t[v];
        int tm = (tl + tr) / 2, vv = 2 * v;
        return max(get(vv, tl, tm, l, r), get(vv + 1, tm + 1, tr, l, r));
    }
    ll get(int l, int r){
        return get(1, 1, n, l, r);
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, q; cin>>n>>q;
    vector<int> a(n + 1);
    map<int, vector<int>> p;
    for (int i = 1; i <= n; i++){
        cin>>a[i];
        p[a[i]].pb(i);
    }
    const int S = sqrt(n);
    vector<int> x;
    for (auto f: p){
        if (f.ss.size() > S){
            x.pb(f.ff);
        }
    }
    vector<pii> end[n + 1];
    for (int i = 1; i <= q; i++){
        int l, r; cin>>l>>r;
        end[r].pb({l, i});
    }
    
    vector<int> :: iterator it1, it2;
    auto count = [&](int l, int r, int x){
        it1 = lower_bound(p[x].begin(), p[x].end(), l);
        it2 = upper_bound(p[x].begin(), p[x].end(), r);
        return (it2 - it1);
    };
    
    ST T(n);
    vector<ll> out(q + 1);
    for (int i = 1; i <= n; i++){
        if (p[a[i]].size() <= S){
            for (int j: p[a[i]]){
                T.upd(j, a[i]);
                if (j == i) break;
            }
        }
        for (auto [l, j]: end[i]){
            out[j] = T.get(l, i);
            for (int f: x){
                out[j] = max(out[j], 1LL * f * count(l, i, f));
            }
        }
    }
    
    for (int i = 1; i <= q; i++){
        cout<<out[i]<<"\n";
    }
}

Compilation message

historic.cpp: In function 'int main()':
historic.cpp:60:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   60 |         if (f.ss.size() > S){
      |             ~~~~~~~~~~~~^~~
historic.cpp:80:28: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   80 |         if (p[a[i]].size() <= S){
      |             ~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 13 ms 860 KB Output is correct
22 Correct 8 ms 860 KB Output is correct
23 Correct 11 ms 956 KB Output is correct
24 Correct 13 ms 1012 KB Output is correct
25 Correct 5 ms 1116 KB Output is correct
26 Correct 5 ms 1116 KB Output is correct
27 Correct 6 ms 1116 KB Output is correct
28 Correct 7 ms 1116 KB Output is correct
29 Correct 6 ms 1116 KB Output is correct
30 Correct 5 ms 1116 KB Output is correct
31 Correct 13 ms 860 KB Output is correct
32 Correct 4 ms 860 KB Output is correct
33 Correct 5 ms 1116 KB Output is correct
34 Correct 5 ms 1116 KB Output is correct
35 Correct 5 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 5 ms 860 KB Output is correct
8 Correct 9 ms 1628 KB Output is correct
9 Correct 20 ms 2908 KB Output is correct
10 Correct 7 ms 4056 KB Output is correct
11 Correct 89 ms 12116 KB Output is correct
12 Correct 209 ms 7740 KB Output is correct
13 Correct 217 ms 9556 KB Output is correct
14 Correct 109 ms 14720 KB Output is correct
15 Correct 129 ms 19540 KB Output is correct
16 Correct 107 ms 21120 KB Output is correct
17 Correct 171 ms 8792 KB Output is correct
18 Correct 408 ms 11984 KB Output is correct
19 Correct 75 ms 22892 KB Output is correct
20 Correct 56 ms 19240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 2 ms 604 KB Output is correct
20 Correct 4 ms 604 KB Output is correct
21 Correct 13 ms 860 KB Output is correct
22 Correct 8 ms 860 KB Output is correct
23 Correct 11 ms 956 KB Output is correct
24 Correct 13 ms 1012 KB Output is correct
25 Correct 5 ms 1116 KB Output is correct
26 Correct 5 ms 1116 KB Output is correct
27 Correct 6 ms 1116 KB Output is correct
28 Correct 7 ms 1116 KB Output is correct
29 Correct 6 ms 1116 KB Output is correct
30 Correct 5 ms 1116 KB Output is correct
31 Correct 13 ms 860 KB Output is correct
32 Correct 4 ms 860 KB Output is correct
33 Correct 5 ms 1116 KB Output is correct
34 Correct 5 ms 1116 KB Output is correct
35 Correct 5 ms 1116 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 5 ms 860 KB Output is correct
43 Correct 9 ms 1628 KB Output is correct
44 Correct 20 ms 2908 KB Output is correct
45 Correct 7 ms 4056 KB Output is correct
46 Correct 89 ms 12116 KB Output is correct
47 Correct 209 ms 7740 KB Output is correct
48 Correct 217 ms 9556 KB Output is correct
49 Correct 109 ms 14720 KB Output is correct
50 Correct 129 ms 19540 KB Output is correct
51 Correct 107 ms 21120 KB Output is correct
52 Correct 171 ms 8792 KB Output is correct
53 Correct 408 ms 11984 KB Output is correct
54 Correct 75 ms 22892 KB Output is correct
55 Correct 56 ms 19240 KB Output is correct
56 Correct 37 ms 1568 KB Output is correct
57 Correct 60 ms 2652 KB Output is correct
58 Correct 41 ms 4460 KB Output is correct
59 Correct 50 ms 6332 KB Output is correct
60 Correct 63 ms 7764 KB Output is correct
61 Correct 123 ms 8172 KB Output is correct
62 Correct 1088 ms 9172 KB Output is correct
63 Correct 395 ms 10324 KB Output is correct
64 Correct 146 ms 11604 KB Output is correct
65 Correct 72 ms 12132 KB Output is correct
66 Correct 202 ms 12372 KB Output is correct
67 Correct 1755 ms 12668 KB Output is correct
68 Correct 254 ms 13140 KB Output is correct
69 Correct 135 ms 15948 KB Output is correct
70 Correct 143 ms 18516 KB Output is correct
71 Correct 134 ms 17200 KB Output is correct
72 Correct 140 ms 16664 KB Output is correct
73 Correct 131 ms 16212 KB Output is correct
74 Correct 136 ms 15956 KB Output is correct
75 Correct 138 ms 15700 KB Output is correct
76 Correct 141 ms 15444 KB Output is correct
77 Correct 144 ms 15320 KB Output is correct
78 Correct 148 ms 15188 KB Output is correct
79 Correct 140 ms 15188 KB Output is correct
80 Correct 67 ms 12880 KB Output is correct