답안 #1033451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033451 2024-07-24T20:52:53 Z _8_8_ 새 집 (APIO18_new_home) C++17
100 / 100
4458 ms 384912 KB
#include <bits/stdc++.h>
 
using namespace std;
    
typedef long long ll;
const int  N = 1e6 + 21, MOD = (int)1e9+7;
 
int n,k,q,x[N],t[N],a[N],b[N];

vector<int> pts;
multiset<int> bf[N * 4];
int m;
int T[N * 4];
void upd(int pos,int val,bool ok,int v = 1,int tl = 0,int tr = m){
    if(tl == tr){
        if(ok) bf[v].insert(val);
        else bf[v].erase(bf[v].find(val));
        T[v] = (bf[v].empty() ? 0 : *bf[v].rbegin()); 
        // cout << tl << ' ' << val << "f\n";
    }else{
        int tm = (tl + tr) >> 1;
        if(pos <= tm) upd(pos,val,ok,v+v,tl,tm);
        else upd(pos,val,ok,v+v+1,tm+1,tr);
        T[v] = max(T[v + v],T[v + v + 1]);
    }
}
int get(int l,int r,int v = 1,int tl = 0,int tr = m){
    if(l > r || tl > r || l > tr) return 0;
    if(tl >= l && tr <= r) return T[v];
    int tm = (tl + tr) >> 1;
    return max(get(l,r,v+v,tl,tm),get(l,r,v+v+1,tm+1,tr));
}
struct Q{
    int tp,y,x,v,id;
};
multiset<int> st[N];
vector<Q> s;
bool cmp(Q l,Q r){
    if(l.y != r.y)
        return l.y < r.y;
    return l.tp < r.tp;
}
multiset<pair<int,int>> cur;
void _add(int l,int r){
    int k = lower_bound(pts.begin(),pts.end(),l) - pts.begin();
    // cout << l << ' ' << r << ' ' << k << '\n';
    upd(k,r,1);
}
void _del(int l,int r){
    int k = lower_bound(pts.begin(),pts.end(),l) - pts.begin();
    upd(k,r,0);
}
void add(int i,int x){
    // cerr << (int)st[i].size() << "x\n";
    auto it = st[i].lower_bound(x);
    int R = *it,L;
    --it;
    L =*it;
    cur.insert({L+1,x - 1});_add(L+1,x-1);
    cur.insert({x + 1,R - 1});_add(x+1,R-1);
    cur.erase(cur.find({L + 1,R - 1}));_del(L+1,R-1);
    st[i].insert(x);
    // cerr << (int)st[i].size() << "x\n";
}
void del(int i,int x){
    auto it = st[i].lower_bound(x);
    it++;
    int R = *it,L;
    --it;--it;
    L =*it;
    cur.erase(cur.find({L + 1,x - 1}));_del(L+1,x-1);
    cur.erase(cur.find({x + 1,R - 1}));_del(x+1,R-1);
    cur.insert({L + 1,R - 1});_add(L+1,R-1);
    st[i].erase(st[i].find(x));
}
int res[N];
bool ok(int l,int r){
    int k = upper_bound(pts.begin(),pts.end(),l) - pts.begin() - 1;
    // cout << l << ' ' << k << ' ' << get(0,k) << ' ' << r << "\n";
    if(get(0,k) >= r) return false;
    return true;
}
void test() {
    cin >> n >> k >> q;
    for(int i = 1;i <= n;++i){
        cin >> x[i] >> t[i] >> a[i] >> b[i];
        pts.push_back(x[i] + 1);
        pts.push_back(x[i] - 1);
        Q f,_f;
        f.y = a[i];f.tp = 0;f.v = t[i];f.x = x[i];
        s.push_back(f);
        _f.y = b[i];_f.tp = 2;_f.v = t[i];_f.x = x[i];
        s.push_back(_f);
    }
    pts.push_back(1);
    pts.push_back((int)1e9);
    sort(pts.begin(),pts.end());
    pts.resize(unique(pts.begin(),pts.end()) - pts.begin());
    m = (int)pts.size() - 1;
    for(int i = 1;i <= q;i++){
        int l,y;
        cin >> l >> y;
        Q a;
        a.tp = 1;
        a.id = i;
        a.x = l;
        a.y = y;
        s.push_back(a);
    }
    sort(s.begin(),s.end(),cmp);
    const int inf = (int)1e9;
    for(int i = 1;i <= k;i++) {
        st[i].insert(0);
        st[i].insert((int)1e9 + 1);
        _add(1,inf);
        cur.insert({1,inf});
    }
    for(Q d:s) {
        if(d.tp == 0) {
            add(d.v,d.x);
        }else if(d.tp == 2) {
            del(d.v,d.x);
        }else{
            if(cur.find({1,(int)1e9}) != cur.end()) {
                res[d.id] = -1;
                continue;
            }
            int l = -1,r = (int)1e9;
            while(r - l > 1){
                int mid = (l + r) >> 1;
                if(ok(max(1,d.x - mid),d.x + mid)){
                    r = mid;
                }else{
                    l = mid;
                }
            }
            res[d.id] = r;
        }
    }
    for(int i = 1;i <= q;++i) {
        cout << res[i] << '\n';
    }
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--) {
        test();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 235092 KB Output is correct
2 Correct 94 ms 235172 KB Output is correct
3 Correct 91 ms 235080 KB Output is correct
4 Correct 92 ms 235260 KB Output is correct
5 Correct 95 ms 235188 KB Output is correct
6 Correct 90 ms 235372 KB Output is correct
7 Correct 92 ms 235348 KB Output is correct
8 Correct 91 ms 235212 KB Output is correct
9 Correct 93 ms 235476 KB Output is correct
10 Correct 91 ms 235344 KB Output is correct
11 Correct 104 ms 235348 KB Output is correct
12 Correct 97 ms 235348 KB Output is correct
13 Correct 93 ms 235344 KB Output is correct
14 Correct 91 ms 235360 KB Output is correct
15 Correct 90 ms 235344 KB Output is correct
16 Correct 97 ms 235348 KB Output is correct
17 Correct 94 ms 235184 KB Output is correct
18 Correct 94 ms 235344 KB Output is correct
19 Correct 92 ms 235348 KB Output is correct
20 Correct 89 ms 235344 KB Output is correct
21 Correct 95 ms 235452 KB Output is correct
22 Correct 93 ms 235348 KB Output is correct
23 Correct 97 ms 235344 KB Output is correct
24 Correct 92 ms 235344 KB Output is correct
25 Correct 93 ms 235344 KB Output is correct
26 Correct 93 ms 235344 KB Output is correct
27 Correct 95 ms 235344 KB Output is correct
28 Correct 93 ms 235184 KB Output is correct
29 Correct 95 ms 235600 KB Output is correct
30 Correct 98 ms 235344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 235092 KB Output is correct
2 Correct 94 ms 235172 KB Output is correct
3 Correct 91 ms 235080 KB Output is correct
4 Correct 92 ms 235260 KB Output is correct
5 Correct 95 ms 235188 KB Output is correct
6 Correct 90 ms 235372 KB Output is correct
7 Correct 92 ms 235348 KB Output is correct
8 Correct 91 ms 235212 KB Output is correct
9 Correct 93 ms 235476 KB Output is correct
10 Correct 91 ms 235344 KB Output is correct
11 Correct 104 ms 235348 KB Output is correct
12 Correct 97 ms 235348 KB Output is correct
13 Correct 93 ms 235344 KB Output is correct
14 Correct 91 ms 235360 KB Output is correct
15 Correct 90 ms 235344 KB Output is correct
16 Correct 97 ms 235348 KB Output is correct
17 Correct 94 ms 235184 KB Output is correct
18 Correct 94 ms 235344 KB Output is correct
19 Correct 92 ms 235348 KB Output is correct
20 Correct 89 ms 235344 KB Output is correct
21 Correct 95 ms 235452 KB Output is correct
22 Correct 93 ms 235348 KB Output is correct
23 Correct 97 ms 235344 KB Output is correct
24 Correct 92 ms 235344 KB Output is correct
25 Correct 93 ms 235344 KB Output is correct
26 Correct 93 ms 235344 KB Output is correct
27 Correct 95 ms 235344 KB Output is correct
28 Correct 93 ms 235184 KB Output is correct
29 Correct 95 ms 235600 KB Output is correct
30 Correct 98 ms 235344 KB Output is correct
31 Correct 605 ms 253352 KB Output is correct
32 Correct 268 ms 244980 KB Output is correct
33 Correct 582 ms 247896 KB Output is correct
34 Correct 523 ms 248044 KB Output is correct
35 Correct 593 ms 253196 KB Output is correct
36 Correct 659 ms 253108 KB Output is correct
37 Correct 513 ms 245328 KB Output is correct
38 Correct 529 ms 245204 KB Output is correct
39 Correct 471 ms 245204 KB Output is correct
40 Correct 494 ms 245432 KB Output is correct
41 Correct 492 ms 245488 KB Output is correct
42 Correct 392 ms 245240 KB Output is correct
43 Correct 225 ms 251892 KB Output is correct
44 Correct 474 ms 245456 KB Output is correct
45 Correct 435 ms 245312 KB Output is correct
46 Correct 440 ms 245332 KB Output is correct
47 Correct 339 ms 244692 KB Output is correct
48 Correct 358 ms 244768 KB Output is correct
49 Correct 391 ms 244976 KB Output is correct
50 Correct 359 ms 245200 KB Output is correct
51 Correct 415 ms 245200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3720 ms 339116 KB Output is correct
2 Correct 3483 ms 325552 KB Output is correct
3 Correct 3085 ms 384496 KB Output is correct
4 Correct 3350 ms 346684 KB Output is correct
5 Correct 3438 ms 325216 KB Output is correct
6 Correct 3620 ms 325552 KB Output is correct
7 Correct 3046 ms 384488 KB Output is correct
8 Correct 2730 ms 346780 KB Output is correct
9 Correct 2605 ms 333600 KB Output is correct
10 Correct 3177 ms 326780 KB Output is correct
11 Correct 2238 ms 324372 KB Output is correct
12 Correct 2404 ms 326116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3413 ms 328108 KB Output is correct
2 Correct 1117 ms 308140 KB Output is correct
3 Correct 3773 ms 325564 KB Output is correct
4 Correct 2462 ms 382468 KB Output is correct
5 Correct 2392 ms 337068 KB Output is correct
6 Correct 2577 ms 344564 KB Output is correct
7 Correct 3748 ms 324960 KB Output is correct
8 Correct 3691 ms 325404 KB Output is correct
9 Correct 2929 ms 383560 KB Output is correct
10 Correct 2981 ms 341228 KB Output is correct
11 Correct 3145 ms 330216 KB Output is correct
12 Correct 3736 ms 326332 KB Output is correct
13 Correct 2103 ms 323244 KB Output is correct
14 Correct 2168 ms 321876 KB Output is correct
15 Correct 2576 ms 324216 KB Output is correct
16 Correct 2629 ms 325652 KB Output is correct
17 Correct 2639 ms 323516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 235092 KB Output is correct
2 Correct 94 ms 235172 KB Output is correct
3 Correct 91 ms 235080 KB Output is correct
4 Correct 92 ms 235260 KB Output is correct
5 Correct 95 ms 235188 KB Output is correct
6 Correct 90 ms 235372 KB Output is correct
7 Correct 92 ms 235348 KB Output is correct
8 Correct 91 ms 235212 KB Output is correct
9 Correct 93 ms 235476 KB Output is correct
10 Correct 91 ms 235344 KB Output is correct
11 Correct 104 ms 235348 KB Output is correct
12 Correct 97 ms 235348 KB Output is correct
13 Correct 93 ms 235344 KB Output is correct
14 Correct 91 ms 235360 KB Output is correct
15 Correct 90 ms 235344 KB Output is correct
16 Correct 97 ms 235348 KB Output is correct
17 Correct 94 ms 235184 KB Output is correct
18 Correct 94 ms 235344 KB Output is correct
19 Correct 92 ms 235348 KB Output is correct
20 Correct 89 ms 235344 KB Output is correct
21 Correct 95 ms 235452 KB Output is correct
22 Correct 93 ms 235348 KB Output is correct
23 Correct 97 ms 235344 KB Output is correct
24 Correct 92 ms 235344 KB Output is correct
25 Correct 93 ms 235344 KB Output is correct
26 Correct 93 ms 235344 KB Output is correct
27 Correct 95 ms 235344 KB Output is correct
28 Correct 93 ms 235184 KB Output is correct
29 Correct 95 ms 235600 KB Output is correct
30 Correct 98 ms 235344 KB Output is correct
31 Correct 605 ms 253352 KB Output is correct
32 Correct 268 ms 244980 KB Output is correct
33 Correct 582 ms 247896 KB Output is correct
34 Correct 523 ms 248044 KB Output is correct
35 Correct 593 ms 253196 KB Output is correct
36 Correct 659 ms 253108 KB Output is correct
37 Correct 513 ms 245328 KB Output is correct
38 Correct 529 ms 245204 KB Output is correct
39 Correct 471 ms 245204 KB Output is correct
40 Correct 494 ms 245432 KB Output is correct
41 Correct 492 ms 245488 KB Output is correct
42 Correct 392 ms 245240 KB Output is correct
43 Correct 225 ms 251892 KB Output is correct
44 Correct 474 ms 245456 KB Output is correct
45 Correct 435 ms 245312 KB Output is correct
46 Correct 440 ms 245332 KB Output is correct
47 Correct 339 ms 244692 KB Output is correct
48 Correct 358 ms 244768 KB Output is correct
49 Correct 391 ms 244976 KB Output is correct
50 Correct 359 ms 245200 KB Output is correct
51 Correct 415 ms 245200 KB Output is correct
52 Correct 411 ms 264336 KB Output is correct
53 Correct 426 ms 259028 KB Output is correct
54 Correct 394 ms 256800 KB Output is correct
55 Correct 515 ms 251604 KB Output is correct
56 Correct 521 ms 254952 KB Output is correct
57 Correct 493 ms 247136 KB Output is correct
58 Correct 463 ms 251600 KB Output is correct
59 Correct 439 ms 254928 KB Output is correct
60 Correct 434 ms 246896 KB Output is correct
61 Correct 277 ms 263124 KB Output is correct
62 Correct 455 ms 264404 KB Output is correct
63 Correct 487 ms 257752 KB Output is correct
64 Correct 461 ms 254164 KB Output is correct
65 Correct 453 ms 247908 KB Output is correct
66 Correct 466 ms 245564 KB Output is correct
67 Correct 324 ms 244948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 235092 KB Output is correct
2 Correct 94 ms 235172 KB Output is correct
3 Correct 91 ms 235080 KB Output is correct
4 Correct 92 ms 235260 KB Output is correct
5 Correct 95 ms 235188 KB Output is correct
6 Correct 90 ms 235372 KB Output is correct
7 Correct 92 ms 235348 KB Output is correct
8 Correct 91 ms 235212 KB Output is correct
9 Correct 93 ms 235476 KB Output is correct
10 Correct 91 ms 235344 KB Output is correct
11 Correct 104 ms 235348 KB Output is correct
12 Correct 97 ms 235348 KB Output is correct
13 Correct 93 ms 235344 KB Output is correct
14 Correct 91 ms 235360 KB Output is correct
15 Correct 90 ms 235344 KB Output is correct
16 Correct 97 ms 235348 KB Output is correct
17 Correct 94 ms 235184 KB Output is correct
18 Correct 94 ms 235344 KB Output is correct
19 Correct 92 ms 235348 KB Output is correct
20 Correct 89 ms 235344 KB Output is correct
21 Correct 95 ms 235452 KB Output is correct
22 Correct 93 ms 235348 KB Output is correct
23 Correct 97 ms 235344 KB Output is correct
24 Correct 92 ms 235344 KB Output is correct
25 Correct 93 ms 235344 KB Output is correct
26 Correct 93 ms 235344 KB Output is correct
27 Correct 95 ms 235344 KB Output is correct
28 Correct 93 ms 235184 KB Output is correct
29 Correct 95 ms 235600 KB Output is correct
30 Correct 98 ms 235344 KB Output is correct
31 Correct 605 ms 253352 KB Output is correct
32 Correct 268 ms 244980 KB Output is correct
33 Correct 582 ms 247896 KB Output is correct
34 Correct 523 ms 248044 KB Output is correct
35 Correct 593 ms 253196 KB Output is correct
36 Correct 659 ms 253108 KB Output is correct
37 Correct 513 ms 245328 KB Output is correct
38 Correct 529 ms 245204 KB Output is correct
39 Correct 471 ms 245204 KB Output is correct
40 Correct 494 ms 245432 KB Output is correct
41 Correct 492 ms 245488 KB Output is correct
42 Correct 392 ms 245240 KB Output is correct
43 Correct 225 ms 251892 KB Output is correct
44 Correct 474 ms 245456 KB Output is correct
45 Correct 435 ms 245312 KB Output is correct
46 Correct 440 ms 245332 KB Output is correct
47 Correct 339 ms 244692 KB Output is correct
48 Correct 358 ms 244768 KB Output is correct
49 Correct 391 ms 244976 KB Output is correct
50 Correct 359 ms 245200 KB Output is correct
51 Correct 415 ms 245200 KB Output is correct
52 Correct 3720 ms 339116 KB Output is correct
53 Correct 3483 ms 325552 KB Output is correct
54 Correct 3085 ms 384496 KB Output is correct
55 Correct 3350 ms 346684 KB Output is correct
56 Correct 3438 ms 325216 KB Output is correct
57 Correct 3620 ms 325552 KB Output is correct
58 Correct 3046 ms 384488 KB Output is correct
59 Correct 2730 ms 346780 KB Output is correct
60 Correct 2605 ms 333600 KB Output is correct
61 Correct 3177 ms 326780 KB Output is correct
62 Correct 2238 ms 324372 KB Output is correct
63 Correct 2404 ms 326116 KB Output is correct
64 Correct 3413 ms 328108 KB Output is correct
65 Correct 1117 ms 308140 KB Output is correct
66 Correct 3773 ms 325564 KB Output is correct
67 Correct 2462 ms 382468 KB Output is correct
68 Correct 2392 ms 337068 KB Output is correct
69 Correct 2577 ms 344564 KB Output is correct
70 Correct 3748 ms 324960 KB Output is correct
71 Correct 3691 ms 325404 KB Output is correct
72 Correct 2929 ms 383560 KB Output is correct
73 Correct 2981 ms 341228 KB Output is correct
74 Correct 3145 ms 330216 KB Output is correct
75 Correct 3736 ms 326332 KB Output is correct
76 Correct 2103 ms 323244 KB Output is correct
77 Correct 2168 ms 321876 KB Output is correct
78 Correct 2576 ms 324216 KB Output is correct
79 Correct 2629 ms 325652 KB Output is correct
80 Correct 2639 ms 323516 KB Output is correct
81 Correct 411 ms 264336 KB Output is correct
82 Correct 426 ms 259028 KB Output is correct
83 Correct 394 ms 256800 KB Output is correct
84 Correct 515 ms 251604 KB Output is correct
85 Correct 521 ms 254952 KB Output is correct
86 Correct 493 ms 247136 KB Output is correct
87 Correct 463 ms 251600 KB Output is correct
88 Correct 439 ms 254928 KB Output is correct
89 Correct 434 ms 246896 KB Output is correct
90 Correct 277 ms 263124 KB Output is correct
91 Correct 455 ms 264404 KB Output is correct
92 Correct 487 ms 257752 KB Output is correct
93 Correct 461 ms 254164 KB Output is correct
94 Correct 453 ms 247908 KB Output is correct
95 Correct 466 ms 245564 KB Output is correct
96 Correct 324 ms 244948 KB Output is correct
97 Correct 2509 ms 384428 KB Output is correct
98 Correct 1098 ms 284076 KB Output is correct
99 Correct 3714 ms 300788 KB Output is correct
100 Correct 2412 ms 357576 KB Output is correct
101 Correct 2623 ms 346696 KB Output is correct
102 Correct 4458 ms 327492 KB Output is correct
103 Correct 3341 ms 289728 KB Output is correct
104 Correct 3010 ms 289196 KB Output is correct
105 Correct 2727 ms 289324 KB Output is correct
106 Correct 2811 ms 289044 KB Output is correct
107 Correct 3011 ms 320432 KB Output is correct
108 Correct 3392 ms 336716 KB Output is correct
109 Correct 2778 ms 297388 KB Output is correct
110 Correct 2771 ms 319952 KB Output is correct
111 Correct 2796 ms 336300 KB Output is correct
112 Correct 2502 ms 296784 KB Output is correct
113 Correct 1352 ms 374900 KB Output is correct
114 Correct 3103 ms 384912 KB Output is correct
115 Correct 3346 ms 349548 KB Output is correct
116 Correct 3420 ms 333388 KB Output is correct
117 Correct 3239 ms 302536 KB Output is correct
118 Correct 2540 ms 291056 KB Output is correct
119 Correct 1802 ms 283640 KB Output is correct
120 Correct 1305 ms 286268 KB Output is correct
121 Correct 1607 ms 288172 KB Output is correct
122 Correct 1733 ms 287916 KB Output is correct
123 Correct 1637 ms 288764 KB Output is correct
124 Correct 1626 ms 289440 KB Output is correct
125 Correct 1927 ms 289128 KB Output is correct
126 Correct 1585 ms 289712 KB Output is correct