답안 #1100190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100190 2024-10-13T09:21:10 Z vladilius 새 집 (APIO18_new_home) C++17
47 / 100
5000 ms 334204 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
const int inf = 1e8;

struct IT{
    struct node{
        node *l, *r;
        multiset<int> st;
        int m;
        node(){
            l = r = 0;
            m = 0;
        }
    };
    node *rt;
    void init(){
        rt = new node();
    }
    void add(node *v, int tl, int tr, int& p, int& x){
        if (tl == tr){
            (v -> st).insert(x);
            (v -> m) = max(v -> m, x);
            return;
        }
        int tm = (tl + tr) / 2;
        if (p <= tm){
            if (!(v -> l)) v -> l = new node();
            add(v -> l, tl, tm, p, x);
        }
        else {
            if (!(v -> r)) v -> r = new node();
            add(v -> r, tm + 1, tr, p, x);
        }
        v -> m = 0;
        if (v -> l) v -> m = max(v -> m, v -> l -> m);
        if (v -> r) v -> m = max(v -> m, v -> r -> m);
    }
    void add(int l, int r){
        add(rt, 1, inf, l, r);
    }
    void rem(node *v, int tl, int tr, int& p, int& x){
        if (tl == tr){
            (v -> st).erase((v -> st).find(x));
            (v -> m) = ((v -> st).empty()) ? 0 : *prev((v -> st).end());
            return;
        }
        int tm = (tl + tr) / 2;
        if (p <= tm){
            rem(v -> l, tl, tm, p, x);
        }
        else {
            rem(v -> r, tm + 1, tr, p, x);
        }
        v -> m = 0;
        if (v -> l) v -> m = max(v -> m, v -> l -> m);
        if (v -> r) v -> m = max(v -> m, v -> r -> m);
    }
    void rem(int l, int r){
        rem(rt, 1, inf, l, r);
    }
    int get(node *v, int tl, int tr, int l, int r){
        if (l > tr || r < tl) return 0;
        if (l <= tl && tr <= r) return (v -> m);
        int tm = (tl + tr) / 2, out = 0;
        if (v -> l) out = max(out, get(v -> l, tl, tm, l, r));
        if (v -> r) out = max(out, get(v -> r, tm + 1, tr, l, r));
        return out;
    }
    bool get(int l, int r){
        return get(rt, 1, inf, 1, l) >= r;
    }
};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, k, q; cin>>n>>k>>q;
    vector<int> x(n + 1), t(n + 1), a(n + 1), b(n + 1), all;
    for (int i = 1; i <= n; i++){
        cin>>x[i]>>t[i]>>a[i]>>b[i];
    }
    vector<int> xq(q + 1), yq(q + 1);
    for (int i = 1; i <= q; i++){
        cin>>xq[i]>>yq[i];
    }

    map<int, vector<pii>> mp;
    for (int i = 1; i <= n; i++){
        mp[a[i]].pb({1, i});
        mp[b[i] + 1].pb({2, i});
    }
    for (int i = 1; i <= q; i++){
        mp[yq[i]].pb({i + 2, xq[i]});
    }
    
    vector<int> out(q + 1), cnt(k + 1);
    multiset<int> st[k + 1];
    int df = 0, l, r;
    vector<pii> qq;
    IT T; T.init();
    for (auto [X, V]: mp){
        qq.clear();
        for (auto [tt, i]: V){
            if (tt == 1){
                df += !cnt[t[i]];
                cnt[t[i]]++;
                if (st[t[i]].empty()){
                    if (1 < x[i]) T.add(1, x[i] - 1);
                    if (x[i] < inf) T.add(x[i] + 1, inf);
                    st[t[i]].insert(x[i]);
                    continue;
                }
                
                if (st[t[i]].find(x[i]) != st[t[i]].end()){
                    st[t[i]].insert(x[i]);
                    continue;
                }
                
                auto it = st[t[i]].upper_bound(x[i]);
                if (it == st[t[i]].end()) r = inf;
                else r = (*it) - 1;
                if (it == st[t[i]].begin()) l = 1;
                else l = *prev(it) + 1;
                
                if (l <= r) T.rem(l, r);
                if (l < x[i]) T.add(l, x[i] - 1);
                if (x[i] < r) T.add(x[i] + 1, r);
                
                st[t[i]].insert(x[i]);
            }
            else if (tt == 2){
                cnt[t[i]]--;
                df -= !cnt[t[i]];
                
                if (st[t[i]].count(x[i]) > 1){
                    st[t[i]].erase(st[t[i]].find(x[i]));
                    continue;
                }
                
                auto it = st[t[i]].find(x[i]);
                
                if (it == st[t[i]].begin()) l = 1;
                else l = *prev(it) + 1;
                if (it == prev(st[t[i]].end())) r = inf;
                else r = *next(it) - 1;
                
                if (l < x[i]) T.rem(l, x[i] - 1);
                if (x[i] < r) T.rem(x[i] + 1, r);
                
                if (cnt[t[i]]) T.add(l, r);
                st[t[i]].erase(it);
            }
            else {
                qq.pb({tt - 2, i});
            }
        }
        for (auto [ii, x]: qq){
            if (df < k){
                out[ii] = -1;
                continue;
            }
            
            auto check = [&](int d){
                return T.get(max(1, x - d), min(inf, x + d));
            };
            
            int l = 0, r = inf;
            while (l + 1 < r){
                int m = (l + r) / 2;
                if (check(m)){
                    l = m + 1;
                }
                else {
                    r = m;
                }
            }
            if (check(l)) l = r;
            
            out[ii] = l;
        }
    }
    
    for (int i = 1; i <= q; i++){
        cout<<out[i]<<"\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 1104 KB Output is correct
7 Correct 2 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 2 ms 1104 KB Output is correct
10 Correct 3 ms 1104 KB Output is correct
11 Correct 2 ms 1272 KB Output is correct
12 Correct 3 ms 1104 KB Output is correct
13 Correct 2 ms 1104 KB Output is correct
14 Correct 2 ms 1144 KB Output is correct
15 Correct 3 ms 1104 KB Output is correct
16 Correct 3 ms 1104 KB Output is correct
17 Correct 3 ms 1104 KB Output is correct
18 Correct 3 ms 1104 KB Output is correct
19 Correct 3 ms 1104 KB Output is correct
20 Correct 3 ms 1104 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 3 ms 1104 KB Output is correct
23 Correct 3 ms 1104 KB Output is correct
24 Correct 2 ms 1104 KB Output is correct
25 Correct 3 ms 1104 KB Output is correct
26 Correct 3 ms 1104 KB Output is correct
27 Correct 3 ms 336 KB Output is correct
28 Correct 2 ms 1104 KB Output is correct
29 Correct 2 ms 1104 KB Output is correct
30 Correct 2 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 1104 KB Output is correct
7 Correct 2 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 2 ms 1104 KB Output is correct
10 Correct 3 ms 1104 KB Output is correct
11 Correct 2 ms 1272 KB Output is correct
12 Correct 3 ms 1104 KB Output is correct
13 Correct 2 ms 1104 KB Output is correct
14 Correct 2 ms 1144 KB Output is correct
15 Correct 3 ms 1104 KB Output is correct
16 Correct 3 ms 1104 KB Output is correct
17 Correct 3 ms 1104 KB Output is correct
18 Correct 3 ms 1104 KB Output is correct
19 Correct 3 ms 1104 KB Output is correct
20 Correct 3 ms 1104 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 3 ms 1104 KB Output is correct
23 Correct 3 ms 1104 KB Output is correct
24 Correct 2 ms 1104 KB Output is correct
25 Correct 3 ms 1104 KB Output is correct
26 Correct 3 ms 1104 KB Output is correct
27 Correct 3 ms 336 KB Output is correct
28 Correct 2 ms 1104 KB Output is correct
29 Correct 2 ms 1104 KB Output is correct
30 Correct 2 ms 848 KB Output is correct
31 Correct 726 ms 83784 KB Output is correct
32 Correct 322 ms 6356 KB Output is correct
33 Correct 647 ms 81228 KB Output is correct
34 Correct 618 ms 81484 KB Output is correct
35 Correct 659 ms 86604 KB Output is correct
36 Correct 712 ms 86348 KB Output is correct
37 Correct 589 ms 81416 KB Output is correct
38 Correct 581 ms 81088 KB Output is correct
39 Correct 505 ms 81264 KB Output is correct
40 Correct 514 ms 81008 KB Output is correct
41 Correct 526 ms 80840 KB Output is correct
42 Correct 429 ms 80836 KB Output is correct
43 Correct 149 ms 10604 KB Output is correct
44 Correct 517 ms 81140 KB Output is correct
45 Correct 491 ms 80904 KB Output is correct
46 Correct 500 ms 80976 KB Output is correct
47 Correct 350 ms 77900 KB Output is correct
48 Correct 327 ms 77132 KB Output is correct
49 Correct 359 ms 78836 KB Output is correct
50 Correct 354 ms 80364 KB Output is correct
51 Correct 392 ms 78460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3149 ms 313584 KB Output is correct
2 Execution timed out 5091 ms 305028 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4344 ms 334204 KB Output is correct
2 Execution timed out 5061 ms 34480 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 1104 KB Output is correct
7 Correct 2 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 2 ms 1104 KB Output is correct
10 Correct 3 ms 1104 KB Output is correct
11 Correct 2 ms 1272 KB Output is correct
12 Correct 3 ms 1104 KB Output is correct
13 Correct 2 ms 1104 KB Output is correct
14 Correct 2 ms 1144 KB Output is correct
15 Correct 3 ms 1104 KB Output is correct
16 Correct 3 ms 1104 KB Output is correct
17 Correct 3 ms 1104 KB Output is correct
18 Correct 3 ms 1104 KB Output is correct
19 Correct 3 ms 1104 KB Output is correct
20 Correct 3 ms 1104 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 3 ms 1104 KB Output is correct
23 Correct 3 ms 1104 KB Output is correct
24 Correct 2 ms 1104 KB Output is correct
25 Correct 3 ms 1104 KB Output is correct
26 Correct 3 ms 1104 KB Output is correct
27 Correct 3 ms 336 KB Output is correct
28 Correct 2 ms 1104 KB Output is correct
29 Correct 2 ms 1104 KB Output is correct
30 Correct 2 ms 848 KB Output is correct
31 Correct 726 ms 83784 KB Output is correct
32 Correct 322 ms 6356 KB Output is correct
33 Correct 647 ms 81228 KB Output is correct
34 Correct 618 ms 81484 KB Output is correct
35 Correct 659 ms 86604 KB Output is correct
36 Correct 712 ms 86348 KB Output is correct
37 Correct 589 ms 81416 KB Output is correct
38 Correct 581 ms 81088 KB Output is correct
39 Correct 505 ms 81264 KB Output is correct
40 Correct 514 ms 81008 KB Output is correct
41 Correct 526 ms 80840 KB Output is correct
42 Correct 429 ms 80836 KB Output is correct
43 Correct 149 ms 10604 KB Output is correct
44 Correct 517 ms 81140 KB Output is correct
45 Correct 491 ms 80904 KB Output is correct
46 Correct 500 ms 80976 KB Output is correct
47 Correct 350 ms 77900 KB Output is correct
48 Correct 327 ms 77132 KB Output is correct
49 Correct 359 ms 78836 KB Output is correct
50 Correct 354 ms 80364 KB Output is correct
51 Correct 392 ms 78460 KB Output is correct
52 Correct 434 ms 92360 KB Output is correct
53 Correct 386 ms 85260 KB Output is correct
54 Correct 405 ms 88420 KB Output is correct
55 Correct 487 ms 84336 KB Output is correct
56 Correct 469 ms 85068 KB Output is correct
57 Correct 497 ms 81996 KB Output is correct
58 Correct 452 ms 82508 KB Output is correct
59 Correct 413 ms 82768 KB Output is correct
60 Correct 434 ms 81740 KB Output is correct
61 Correct 150 ms 16484 KB Output is correct
62 Correct 429 ms 92492 KB Output is correct
63 Correct 490 ms 88396 KB Output is correct
64 Correct 540 ms 86712 KB Output is correct
65 Correct 539 ms 83000 KB Output is correct
66 Correct 515 ms 81168 KB Output is correct
67 Correct 195 ms 7244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 3 ms 1104 KB Output is correct
7 Correct 2 ms 1104 KB Output is correct
8 Correct 2 ms 1104 KB Output is correct
9 Correct 2 ms 1104 KB Output is correct
10 Correct 3 ms 1104 KB Output is correct
11 Correct 2 ms 1272 KB Output is correct
12 Correct 3 ms 1104 KB Output is correct
13 Correct 2 ms 1104 KB Output is correct
14 Correct 2 ms 1144 KB Output is correct
15 Correct 3 ms 1104 KB Output is correct
16 Correct 3 ms 1104 KB Output is correct
17 Correct 3 ms 1104 KB Output is correct
18 Correct 3 ms 1104 KB Output is correct
19 Correct 3 ms 1104 KB Output is correct
20 Correct 3 ms 1104 KB Output is correct
21 Correct 2 ms 336 KB Output is correct
22 Correct 3 ms 1104 KB Output is correct
23 Correct 3 ms 1104 KB Output is correct
24 Correct 2 ms 1104 KB Output is correct
25 Correct 3 ms 1104 KB Output is correct
26 Correct 3 ms 1104 KB Output is correct
27 Correct 3 ms 336 KB Output is correct
28 Correct 2 ms 1104 KB Output is correct
29 Correct 2 ms 1104 KB Output is correct
30 Correct 2 ms 848 KB Output is correct
31 Correct 726 ms 83784 KB Output is correct
32 Correct 322 ms 6356 KB Output is correct
33 Correct 647 ms 81228 KB Output is correct
34 Correct 618 ms 81484 KB Output is correct
35 Correct 659 ms 86604 KB Output is correct
36 Correct 712 ms 86348 KB Output is correct
37 Correct 589 ms 81416 KB Output is correct
38 Correct 581 ms 81088 KB Output is correct
39 Correct 505 ms 81264 KB Output is correct
40 Correct 514 ms 81008 KB Output is correct
41 Correct 526 ms 80840 KB Output is correct
42 Correct 429 ms 80836 KB Output is correct
43 Correct 149 ms 10604 KB Output is correct
44 Correct 517 ms 81140 KB Output is correct
45 Correct 491 ms 80904 KB Output is correct
46 Correct 500 ms 80976 KB Output is correct
47 Correct 350 ms 77900 KB Output is correct
48 Correct 327 ms 77132 KB Output is correct
49 Correct 359 ms 78836 KB Output is correct
50 Correct 354 ms 80364 KB Output is correct
51 Correct 392 ms 78460 KB Output is correct
52 Correct 3149 ms 313584 KB Output is correct
53 Execution timed out 5091 ms 305028 KB Time limit exceeded
54 Halted 0 ms 0 KB -