Submission #861207

# Submission time Handle Problem Language Result Execution time Memory
861207 2023-10-15T16:29:41 Z TahirAliyev None (JOI16_matryoshka) C++17
100 / 100
467 ms 35136 KB
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>

using namespace std;

struct DATA{
    int h, id, r;
};

const int MAX = 2e5 + 5, AMAX = 8e5 + 5;

int n, q;
pii arr[MAX];
pii Q[MAX];
vector<DATA> E;
int tree[4 * AMAX];

void update(int node, int l, int r, int pos, int val){
    if(l == r){
        tree[node] = val;
        return;
    }
    int mid = (l + r) / 2;
    if(pos <= mid){
        update(2 * node, l, mid, pos, val);
    }
    else{
        update(2 * node + 1, mid + 1, r, pos, val);
    }
    tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}

int ask(int node, int l, int r, int ql, int qr){
    if(qr < l || r < ql) return 0;
    if(ql <= l && r <= qr) return tree[node];
    int mid = (l + r) / 2;
    return max(ask(2 * node, l, mid, ql, qr), ask(2 * node + 1, mid + 1, r, ql, qr));
}

void INPUT(){
    cin >> n >> q;
    vector<array<int, 3>> v;
    for(int i = 1; i <= n; i++){
        int a, b; cin >> a >> b;
        v.push_back({a, i, 0});
        v.push_back({b, -i, 0});
    }
    for(int i = 1; i <= q; i++){
        int a, b; cin >> a >> b;
        v.push_back({a, i, 1});
        v.push_back({b, -i, 1});
    }
    sort(v.begin(), v.end());
    int t = 0;
    for(int i = 0; i < 2 * n + 2 * q; i++){
        if(i == 0 || v[i][0] != v[i - 1][0]){
            t++;
        }
        if(v[i][2]){
            if(v[i][1] > 0){
                Q[v[i][1]].first = t;
            }
            else{
                Q[-v[i][1]].second = t;
            }
        }
        else{
            if(v[i][1] > 0){
                arr[v[i][1]].first = t;
            }
            else{
                arr[-v[i][1]].second = t;
            }
        }
    }
}

bool cmp(DATA a, DATA b){
    if(a.h == b.h){
        if(a.id == b.id){
            return a.r > b.r;
        }
        else{
            return a.id < b.id;
        }
    }
    return a.h < b.h;
}

int ans[MAX];

int main(){
    INPUT();
    for(int i = 1; i <= n; i++){
        E.push_back({arr[i].second, 0, arr[i].first});
    }
    for(int i = 1; i <= n; i++){
        E.push_back({Q[i].second, i, Q[i].first});
    }
    sort(E.begin(), E.end(), cmp);
    for(DATA e : E){
        if(e.id){
            ans[e.id] = ask(1, 1, AMAX, e.r, AMAX);
        }
        else{
            update(1, 1, AMAX, e.r, ask(1, 1, AMAX, e.r, AMAX) + 1);
        }
    }
    for(int i = 1; i <= q; i++){
        cout << ans[i] << '\n';
    }
}   
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 6592 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 6592 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 2496 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 6592 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 2496 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 2 ms 2508 KB Output is correct
23 Correct 5 ms 2844 KB Output is correct
24 Correct 5 ms 6684 KB Output is correct
25 Correct 5 ms 4728 KB Output is correct
26 Correct 5 ms 6684 KB Output is correct
27 Correct 5 ms 6684 KB Output is correct
28 Correct 5 ms 2652 KB Output is correct
29 Correct 4 ms 4636 KB Output is correct
30 Correct 4 ms 2652 KB Output is correct
31 Correct 5 ms 2844 KB Output is correct
32 Correct 5 ms 6684 KB Output is correct
33 Correct 5 ms 2844 KB Output is correct
34 Correct 5 ms 2844 KB Output is correct
35 Correct 5 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 6592 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 2496 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 2 ms 2508 KB Output is correct
23 Correct 5 ms 2844 KB Output is correct
24 Correct 5 ms 6684 KB Output is correct
25 Correct 5 ms 4728 KB Output is correct
26 Correct 5 ms 6684 KB Output is correct
27 Correct 5 ms 6684 KB Output is correct
28 Correct 5 ms 2652 KB Output is correct
29 Correct 4 ms 4636 KB Output is correct
30 Correct 4 ms 2652 KB Output is correct
31 Correct 5 ms 2844 KB Output is correct
32 Correct 5 ms 6684 KB Output is correct
33 Correct 5 ms 2844 KB Output is correct
34 Correct 5 ms 2844 KB Output is correct
35 Correct 5 ms 2764 KB Output is correct
36 Correct 427 ms 28364 KB Output is correct
37 Correct 405 ms 26696 KB Output is correct
38 Correct 160 ms 13116 KB Output is correct
39 Correct 353 ms 23956 KB Output is correct
40 Correct 353 ms 20132 KB Output is correct
41 Correct 406 ms 24968 KB Output is correct
42 Correct 311 ms 19452 KB Output is correct
43 Correct 293 ms 24336 KB Output is correct
44 Correct 465 ms 35136 KB Output is correct
45 Correct 467 ms 33264 KB Output is correct
46 Correct 463 ms 34104 KB Output is correct
47 Correct 467 ms 33288 KB Output is correct
48 Correct 467 ms 33680 KB Output is correct
49 Correct 454 ms 32932 KB Output is correct
50 Correct 462 ms 33768 KB Output is correct