Submission #545052

# Submission time Handle Problem Language Result Execution time Memory
545052 2022-04-03T13:01:36 Z pokmui9909 None (JOI16_matryoshka) C++17
100 / 100
538 ms 51404 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct Data{
    ll x, y, n;
    bool operator < (const Data &r) const{
        if(x != r.x) return x > r.x;
        else return y < r.y;
    }
};
Data Query[200005];
ll ans[200005];
const ll S = 400005;
ll len[200005];

struct MaxSeg{
    ll T[4 * S] = {};
    void update(ll k, ll v) { update(1, 1, S, k, v); }
    ll query(ll l, ll r) { return query(1, 1, S, l, r); }

    void update(ll node, ll s, ll e, ll k, ll v){
        if(s == e){
            T[node] = max(T[node], v);
            return;
        }
        ll lch = 2 * node, rch = 2 * node + 1, m = (s + e) / 2;
        if(k <= m) update(lch, s, m, k, v);
        else update(rch, m + 1, e, k, v);
        T[node] = max(T[lch], T[rch]);
    }
    ll query(ll node, ll s, ll e, ll l, ll r){
        if(e < l || s > r) return 0;
        if(l <= s && e <= r) return T[node];
        ll lch = 2 * node, rch = 2 * node + 1, m = (s + e) / 2;
        ll x = query(lch, s, m, l, r);
        ll y = query(rch, m + 1, e, l, r);
        return max(x, y);
    }
};

int main(){
    cin.tie(0) -> sync_with_stdio(false);

    ll N, Q; cin >> N >> Q;
    vector<pair<ll, ll>> P(N);
    vector<ll> X, Y;
    for(int i = 0; i < N; i++){
        cin >> P[i].first >> P[i].second;
        X.push_back(P[i].first);
        Y.push_back(P[i].second);
    }
    sort(P.begin(), P.end(), [&](pair<ll, ll> a, pair<ll, ll> b) -> bool{
        if(a.first != b.first) return a.first > b.first;
        else return a.second < b.second;
    });
    for(int i = 0; i < Q; i++){
        cin >> Query[i].x >> Query[i].y;
        Query[i].n = i;
        X.push_back(Query[i].x);
        Y.push_back(Query[i].y);
    }
    sort(Query, Query + Q);
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    X.erase(unique(X.begin(), X.end()), X.end());
    Y.erase(unique(Y.begin(), Y.end()), Y.end());
    for(int i = 0; i < N; i++){
        P[i].first = lower_bound(X.begin(), X.end(), P[i].first) - X.begin() + 1;
        P[i].second = lower_bound(Y.begin(), Y.end(), P[i].second) - Y.begin() + 1;
    }
    for(int i = 0; i < Q; i++){
        Query[i].x = lower_bound(X.begin(), X.end(), Query[i].x) - X.begin() + 1;
        Query[i].y = lower_bound(Y.begin(), Y.end(), Query[i].y) - Y.begin() + 1;
    }
    MaxSeg LIS;
    for(int i = 0; i < N; i++){
        len[i] = LIS.query(1, P[i].second) + 1;
        LIS.update(P[i].second, len[i]);
    }
    ll idx = -1;
    MaxSeg ST;
    for(int i = 0; i < Q; i++){
        while(1){
            idx++;
            if(P[idx].first < Query[i].x || idx >= N){
                idx--;
                break;
            }
            ST.update(P[idx].second, len[idx]);
        }
        ans[Query[i].n] = ST.query(1, Query[i].y);
    } 
    for(int i = 0; i < Q; i++){
        cout << ans[i] << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25332 KB Output is correct
2 Correct 13 ms 25372 KB Output is correct
3 Correct 14 ms 25368 KB Output is correct
4 Correct 17 ms 25360 KB Output is correct
5 Correct 13 ms 25376 KB Output is correct
6 Correct 12 ms 25356 KB Output is correct
7 Correct 14 ms 25300 KB Output is correct
8 Correct 12 ms 25300 KB Output is correct
9 Correct 12 ms 25300 KB Output is correct
10 Correct 13 ms 25372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25332 KB Output is correct
2 Correct 13 ms 25372 KB Output is correct
3 Correct 14 ms 25368 KB Output is correct
4 Correct 17 ms 25360 KB Output is correct
5 Correct 13 ms 25376 KB Output is correct
6 Correct 12 ms 25356 KB Output is correct
7 Correct 14 ms 25300 KB Output is correct
8 Correct 12 ms 25300 KB Output is correct
9 Correct 12 ms 25300 KB Output is correct
10 Correct 13 ms 25372 KB Output is correct
11 Correct 12 ms 25372 KB Output is correct
12 Correct 12 ms 25300 KB Output is correct
13 Correct 13 ms 25428 KB Output is correct
14 Correct 13 ms 25300 KB Output is correct
15 Correct 14 ms 25380 KB Output is correct
16 Correct 15 ms 25300 KB Output is correct
17 Correct 14 ms 25368 KB Output is correct
18 Correct 14 ms 25376 KB Output is correct
19 Correct 15 ms 25372 KB Output is correct
20 Correct 15 ms 25324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25332 KB Output is correct
2 Correct 13 ms 25372 KB Output is correct
3 Correct 14 ms 25368 KB Output is correct
4 Correct 17 ms 25360 KB Output is correct
5 Correct 13 ms 25376 KB Output is correct
6 Correct 12 ms 25356 KB Output is correct
7 Correct 14 ms 25300 KB Output is correct
8 Correct 12 ms 25300 KB Output is correct
9 Correct 12 ms 25300 KB Output is correct
10 Correct 13 ms 25372 KB Output is correct
11 Correct 12 ms 25372 KB Output is correct
12 Correct 12 ms 25300 KB Output is correct
13 Correct 13 ms 25428 KB Output is correct
14 Correct 13 ms 25300 KB Output is correct
15 Correct 14 ms 25380 KB Output is correct
16 Correct 15 ms 25300 KB Output is correct
17 Correct 14 ms 25368 KB Output is correct
18 Correct 14 ms 25376 KB Output is correct
19 Correct 15 ms 25372 KB Output is correct
20 Correct 15 ms 25324 KB Output is correct
21 Correct 13 ms 25300 KB Output is correct
22 Correct 14 ms 25512 KB Output is correct
23 Correct 15 ms 25556 KB Output is correct
24 Correct 16 ms 25660 KB Output is correct
25 Correct 18 ms 25568 KB Output is correct
26 Correct 16 ms 25556 KB Output is correct
27 Correct 16 ms 25616 KB Output is correct
28 Correct 16 ms 25556 KB Output is correct
29 Correct 16 ms 25556 KB Output is correct
30 Correct 16 ms 25508 KB Output is correct
31 Correct 16 ms 25636 KB Output is correct
32 Correct 18 ms 25640 KB Output is correct
33 Correct 17 ms 25624 KB Output is correct
34 Correct 17 ms 25656 KB Output is correct
35 Correct 17 ms 25556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 25332 KB Output is correct
2 Correct 13 ms 25372 KB Output is correct
3 Correct 14 ms 25368 KB Output is correct
4 Correct 17 ms 25360 KB Output is correct
5 Correct 13 ms 25376 KB Output is correct
6 Correct 12 ms 25356 KB Output is correct
7 Correct 14 ms 25300 KB Output is correct
8 Correct 12 ms 25300 KB Output is correct
9 Correct 12 ms 25300 KB Output is correct
10 Correct 13 ms 25372 KB Output is correct
11 Correct 12 ms 25372 KB Output is correct
12 Correct 12 ms 25300 KB Output is correct
13 Correct 13 ms 25428 KB Output is correct
14 Correct 13 ms 25300 KB Output is correct
15 Correct 14 ms 25380 KB Output is correct
16 Correct 15 ms 25300 KB Output is correct
17 Correct 14 ms 25368 KB Output is correct
18 Correct 14 ms 25376 KB Output is correct
19 Correct 15 ms 25372 KB Output is correct
20 Correct 15 ms 25324 KB Output is correct
21 Correct 13 ms 25300 KB Output is correct
22 Correct 14 ms 25512 KB Output is correct
23 Correct 15 ms 25556 KB Output is correct
24 Correct 16 ms 25660 KB Output is correct
25 Correct 18 ms 25568 KB Output is correct
26 Correct 16 ms 25556 KB Output is correct
27 Correct 16 ms 25616 KB Output is correct
28 Correct 16 ms 25556 KB Output is correct
29 Correct 16 ms 25556 KB Output is correct
30 Correct 16 ms 25508 KB Output is correct
31 Correct 16 ms 25636 KB Output is correct
32 Correct 18 ms 25640 KB Output is correct
33 Correct 17 ms 25624 KB Output is correct
34 Correct 17 ms 25656 KB Output is correct
35 Correct 17 ms 25556 KB Output is correct
36 Correct 456 ms 48688 KB Output is correct
37 Correct 269 ms 47952 KB Output is correct
38 Correct 140 ms 34028 KB Output is correct
39 Correct 226 ms 46432 KB Output is correct
40 Correct 247 ms 46816 KB Output is correct
41 Correct 311 ms 47968 KB Output is correct
42 Correct 173 ms 45556 KB Output is correct
43 Correct 139 ms 45768 KB Output is correct
44 Correct 511 ms 51268 KB Output is correct
45 Correct 474 ms 51228 KB Output is correct
46 Correct 538 ms 51284 KB Output is correct
47 Correct 415 ms 50892 KB Output is correct
48 Correct 413 ms 51404 KB Output is correct
49 Correct 447 ms 50924 KB Output is correct
50 Correct 422 ms 51404 KB Output is correct