답안 #952312

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952312 2024-03-23T14:10:42 Z Itamar 새 집 (APIO18_new_home) C++17
100 / 100
4668 ms 903500 KB
#include <iostream>
using namespace std;
#include <vector>
#define vi vector<int>
#define ll long long
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <cmath>
#include <math.h>
#define pll pair<ll,ll>
#define vll vector<ll>
#define pi pair<int,int>
#include <map>
#include <queue>
#define pd pair<double,double>

const int siz = 3e5 + 2;
multiset<int> col[siz];
int K;
struct node {
    int l, r, mid, maxi;
    bool p=0;
    multiset<int> s;
    node* sl = NULL;
    node *sr = NULL;
    node(int li, int ri) {
        l = li, r = ri, mid = (l + r) / 2, maxi = 0;
        if (l == 0) {
            maxi = 3e8 + 1;

            if (r == 0) {
                for (int i = 0; i < K; i++)s.insert(3e8 + 1);
            }
            else open();
        }
    }
    void open() {
        
        if (sl == NULL && (l < r)) {
            p = 1;
            sl = new node(l, mid);
            sr = new node(mid + 1, r);
        }
    }
    int query(int x, int&ma) {
        open();
        if (l == r) {
            if (l > 0)return x-l;
            return maxi - x;
        }
        else {
            if (x <= mid)return sl->query(x,ma);
            if (max(ma,sl->maxi) >= 2*x - mid) {
                return sl->query(x,ma);
            }
            else {
                ma = max(ma, sl->maxi);
                return sr->query(x, ma);
            }
        }
    }
    void update(int v, int x, bool f) {
        if (l == r) {
            if (f)s.insert(v);
            else s.erase(s.find(v));
            if (s.size())maxi = *(--s.end());
            else maxi = 0;
        }
        else {
            if (sl == NULL)open();
            if (x <= mid) {
                sl->update(v, x, f);
            }
            else {
                sr->update(v, x, f);
            }
            maxi = max(sl->maxi, sr->maxi);
        }
    }
};
map<pi, int> sum;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k, q;
    cin >> n >> k >> q;
    vector<vi> ev;
    K = k;
    for (int i = 0; i < n; i++) {
        int x, t, a, b;
        cin >> x >> t >> a >> b;
        x++;
        ev.push_back({ a,1,x,t });
        ev.push_back({b+1,0,x,t });
    }
    for (int i = 0; i < siz; i++) {
        col[i].insert(0);
        col[i].insert(3e8 + 1);
    }
    for (int i = 0; i < q; i++) {
        int l, y;
        cin >> l >> y;
        l++;
        ev.push_back({ y,l,i });
    }
    sort(ev.begin(), ev.end());
    node* seg = new node(0, 3e8 + 3);
    vi ans(q);
    for (vi v : ev) {
        if (v.size() == 3) {
            int l = v[1];
            int h = 0;
            ans[v[2]] = seg->query(l,h);
            if (ans[v[2]] > 1e8)ans[v[2]] = -1;
        }
        else {
            int x = v[2], t = v[3];
            if (v[1])sum[{x, t}]++;
            else sum[{x,t}]--;
            if (v[1] == sum[{x,t}]) {
                auto it = col[t].lower_bound(x);
                auto it1 = it, it2 = it;
                it1--; if (v[1] == 0)it2++;
                if (v[1] == 0)col[t].erase(x);
                else col[t].insert(x);

                seg->update(*it2, x, v[1]);
                seg->update(*it2, *it1, !v[1]);
                seg->update(x, *it1, v[1]);
            }
        }
    }
    for (int i = 0; i < q; i++)cout << ans[i] << "\n";
}
/*
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 42584 KB Output is correct
2 Correct 32 ms 42628 KB Output is correct
3 Correct 31 ms 42688 KB Output is correct
4 Correct 32 ms 42656 KB Output is correct
5 Correct 36 ms 42804 KB Output is correct
6 Correct 35 ms 44368 KB Output is correct
7 Correct 34 ms 44124 KB Output is correct
8 Correct 34 ms 44124 KB Output is correct
9 Correct 34 ms 44120 KB Output is correct
10 Correct 35 ms 44520 KB Output is correct
11 Correct 35 ms 44124 KB Output is correct
12 Correct 42 ms 44372 KB Output is correct
13 Correct 34 ms 44124 KB Output is correct
14 Correct 38 ms 44320 KB Output is correct
15 Correct 39 ms 43952 KB Output is correct
16 Correct 39 ms 44556 KB Output is correct
17 Correct 34 ms 44124 KB Output is correct
18 Correct 35 ms 44012 KB Output is correct
19 Correct 34 ms 44124 KB Output is correct
20 Correct 33 ms 44064 KB Output is correct
21 Correct 34 ms 42724 KB Output is correct
22 Correct 35 ms 44048 KB Output is correct
23 Correct 35 ms 44124 KB Output is correct
24 Correct 35 ms 44124 KB Output is correct
25 Correct 36 ms 44092 KB Output is correct
26 Correct 34 ms 44380 KB Output is correct
27 Correct 33 ms 42580 KB Output is correct
28 Correct 34 ms 44372 KB Output is correct
29 Correct 33 ms 44372 KB Output is correct
30 Correct 37 ms 44180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 42584 KB Output is correct
2 Correct 32 ms 42628 KB Output is correct
3 Correct 31 ms 42688 KB Output is correct
4 Correct 32 ms 42656 KB Output is correct
5 Correct 36 ms 42804 KB Output is correct
6 Correct 35 ms 44368 KB Output is correct
7 Correct 34 ms 44124 KB Output is correct
8 Correct 34 ms 44124 KB Output is correct
9 Correct 34 ms 44120 KB Output is correct
10 Correct 35 ms 44520 KB Output is correct
11 Correct 35 ms 44124 KB Output is correct
12 Correct 42 ms 44372 KB Output is correct
13 Correct 34 ms 44124 KB Output is correct
14 Correct 38 ms 44320 KB Output is correct
15 Correct 39 ms 43952 KB Output is correct
16 Correct 39 ms 44556 KB Output is correct
17 Correct 34 ms 44124 KB Output is correct
18 Correct 35 ms 44012 KB Output is correct
19 Correct 34 ms 44124 KB Output is correct
20 Correct 33 ms 44064 KB Output is correct
21 Correct 34 ms 42724 KB Output is correct
22 Correct 35 ms 44048 KB Output is correct
23 Correct 35 ms 44124 KB Output is correct
24 Correct 35 ms 44124 KB Output is correct
25 Correct 36 ms 44092 KB Output is correct
26 Correct 34 ms 44380 KB Output is correct
27 Correct 33 ms 42580 KB Output is correct
28 Correct 34 ms 44372 KB Output is correct
29 Correct 33 ms 44372 KB Output is correct
30 Correct 37 ms 44180 KB Output is correct
31 Correct 687 ms 228340 KB Output is correct
32 Correct 99 ms 54508 KB Output is correct
33 Correct 702 ms 232692 KB Output is correct
34 Correct 701 ms 221240 KB Output is correct
35 Correct 701 ms 233568 KB Output is correct
36 Correct 707 ms 238152 KB Output is correct
37 Correct 510 ms 230352 KB Output is correct
38 Correct 522 ms 231932 KB Output is correct
39 Correct 361 ms 231852 KB Output is correct
40 Correct 380 ms 231156 KB Output is correct
41 Correct 472 ms 181884 KB Output is correct
42 Correct 439 ms 181356 KB Output is correct
43 Correct 100 ms 54580 KB Output is correct
44 Correct 418 ms 182384 KB Output is correct
45 Correct 406 ms 184300 KB Output is correct
46 Correct 391 ms 195876 KB Output is correct
47 Correct 293 ms 204348 KB Output is correct
48 Correct 316 ms 215144 KB Output is correct
49 Correct 347 ms 213516 KB Output is correct
50 Correct 348 ms 203436 KB Output is correct
51 Correct 322 ms 217328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2379 ms 628892 KB Output is correct
2 Correct 2197 ms 816540 KB Output is correct
3 Correct 1944 ms 652852 KB Output is correct
4 Correct 2372 ms 644608 KB Output is correct
5 Correct 2148 ms 827048 KB Output is correct
6 Correct 2074 ms 827624 KB Output is correct
7 Correct 1933 ms 652380 KB Output is correct
8 Correct 2198 ms 645328 KB Output is correct
9 Correct 2370 ms 687244 KB Output is correct
10 Correct 2136 ms 827592 KB Output is correct
11 Correct 1585 ms 818000 KB Output is correct
12 Correct 1819 ms 823216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3704 ms 734512 KB Output is correct
2 Correct 604 ms 99000 KB Output is correct
3 Correct 3471 ms 828132 KB Output is correct
4 Correct 2973 ms 651492 KB Output is correct
5 Correct 3483 ms 639428 KB Output is correct
6 Correct 3327 ms 641552 KB Output is correct
7 Correct 3328 ms 826500 KB Output is correct
8 Correct 3469 ms 828200 KB Output is correct
9 Correct 2981 ms 652488 KB Output is correct
10 Correct 3355 ms 642512 KB Output is correct
11 Correct 3520 ms 680372 KB Output is correct
12 Correct 3592 ms 824864 KB Output is correct
13 Correct 1640 ms 869128 KB Output is correct
14 Correct 1590 ms 835812 KB Output is correct
15 Correct 1743 ms 867428 KB Output is correct
16 Correct 2224 ms 903500 KB Output is correct
17 Correct 1900 ms 852936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 42584 KB Output is correct
2 Correct 32 ms 42628 KB Output is correct
3 Correct 31 ms 42688 KB Output is correct
4 Correct 32 ms 42656 KB Output is correct
5 Correct 36 ms 42804 KB Output is correct
6 Correct 35 ms 44368 KB Output is correct
7 Correct 34 ms 44124 KB Output is correct
8 Correct 34 ms 44124 KB Output is correct
9 Correct 34 ms 44120 KB Output is correct
10 Correct 35 ms 44520 KB Output is correct
11 Correct 35 ms 44124 KB Output is correct
12 Correct 42 ms 44372 KB Output is correct
13 Correct 34 ms 44124 KB Output is correct
14 Correct 38 ms 44320 KB Output is correct
15 Correct 39 ms 43952 KB Output is correct
16 Correct 39 ms 44556 KB Output is correct
17 Correct 34 ms 44124 KB Output is correct
18 Correct 35 ms 44012 KB Output is correct
19 Correct 34 ms 44124 KB Output is correct
20 Correct 33 ms 44064 KB Output is correct
21 Correct 34 ms 42724 KB Output is correct
22 Correct 35 ms 44048 KB Output is correct
23 Correct 35 ms 44124 KB Output is correct
24 Correct 35 ms 44124 KB Output is correct
25 Correct 36 ms 44092 KB Output is correct
26 Correct 34 ms 44380 KB Output is correct
27 Correct 33 ms 42580 KB Output is correct
28 Correct 34 ms 44372 KB Output is correct
29 Correct 33 ms 44372 KB Output is correct
30 Correct 37 ms 44180 KB Output is correct
31 Correct 687 ms 228340 KB Output is correct
32 Correct 99 ms 54508 KB Output is correct
33 Correct 702 ms 232692 KB Output is correct
34 Correct 701 ms 221240 KB Output is correct
35 Correct 701 ms 233568 KB Output is correct
36 Correct 707 ms 238152 KB Output is correct
37 Correct 510 ms 230352 KB Output is correct
38 Correct 522 ms 231932 KB Output is correct
39 Correct 361 ms 231852 KB Output is correct
40 Correct 380 ms 231156 KB Output is correct
41 Correct 472 ms 181884 KB Output is correct
42 Correct 439 ms 181356 KB Output is correct
43 Correct 100 ms 54580 KB Output is correct
44 Correct 418 ms 182384 KB Output is correct
45 Correct 406 ms 184300 KB Output is correct
46 Correct 391 ms 195876 KB Output is correct
47 Correct 293 ms 204348 KB Output is correct
48 Correct 316 ms 215144 KB Output is correct
49 Correct 347 ms 213516 KB Output is correct
50 Correct 348 ms 203436 KB Output is correct
51 Correct 322 ms 217328 KB Output is correct
52 Correct 595 ms 192068 KB Output is correct
53 Correct 597 ms 186976 KB Output is correct
54 Correct 656 ms 190112 KB Output is correct
55 Correct 489 ms 186100 KB Output is correct
56 Correct 529 ms 185076 KB Output is correct
57 Correct 450 ms 185584 KB Output is correct
58 Correct 491 ms 185848 KB Output is correct
59 Correct 495 ms 185076 KB Output is correct
60 Correct 471 ms 184644 KB Output is correct
61 Correct 224 ms 69620 KB Output is correct
62 Correct 610 ms 191088 KB Output is correct
63 Correct 657 ms 189732 KB Output is correct
64 Correct 602 ms 188636 KB Output is correct
65 Correct 623 ms 185340 KB Output is correct
66 Correct 468 ms 184236 KB Output is correct
67 Correct 240 ms 59124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 42584 KB Output is correct
2 Correct 32 ms 42628 KB Output is correct
3 Correct 31 ms 42688 KB Output is correct
4 Correct 32 ms 42656 KB Output is correct
5 Correct 36 ms 42804 KB Output is correct
6 Correct 35 ms 44368 KB Output is correct
7 Correct 34 ms 44124 KB Output is correct
8 Correct 34 ms 44124 KB Output is correct
9 Correct 34 ms 44120 KB Output is correct
10 Correct 35 ms 44520 KB Output is correct
11 Correct 35 ms 44124 KB Output is correct
12 Correct 42 ms 44372 KB Output is correct
13 Correct 34 ms 44124 KB Output is correct
14 Correct 38 ms 44320 KB Output is correct
15 Correct 39 ms 43952 KB Output is correct
16 Correct 39 ms 44556 KB Output is correct
17 Correct 34 ms 44124 KB Output is correct
18 Correct 35 ms 44012 KB Output is correct
19 Correct 34 ms 44124 KB Output is correct
20 Correct 33 ms 44064 KB Output is correct
21 Correct 34 ms 42724 KB Output is correct
22 Correct 35 ms 44048 KB Output is correct
23 Correct 35 ms 44124 KB Output is correct
24 Correct 35 ms 44124 KB Output is correct
25 Correct 36 ms 44092 KB Output is correct
26 Correct 34 ms 44380 KB Output is correct
27 Correct 33 ms 42580 KB Output is correct
28 Correct 34 ms 44372 KB Output is correct
29 Correct 33 ms 44372 KB Output is correct
30 Correct 37 ms 44180 KB Output is correct
31 Correct 687 ms 228340 KB Output is correct
32 Correct 99 ms 54508 KB Output is correct
33 Correct 702 ms 232692 KB Output is correct
34 Correct 701 ms 221240 KB Output is correct
35 Correct 701 ms 233568 KB Output is correct
36 Correct 707 ms 238152 KB Output is correct
37 Correct 510 ms 230352 KB Output is correct
38 Correct 522 ms 231932 KB Output is correct
39 Correct 361 ms 231852 KB Output is correct
40 Correct 380 ms 231156 KB Output is correct
41 Correct 472 ms 181884 KB Output is correct
42 Correct 439 ms 181356 KB Output is correct
43 Correct 100 ms 54580 KB Output is correct
44 Correct 418 ms 182384 KB Output is correct
45 Correct 406 ms 184300 KB Output is correct
46 Correct 391 ms 195876 KB Output is correct
47 Correct 293 ms 204348 KB Output is correct
48 Correct 316 ms 215144 KB Output is correct
49 Correct 347 ms 213516 KB Output is correct
50 Correct 348 ms 203436 KB Output is correct
51 Correct 322 ms 217328 KB Output is correct
52 Correct 2379 ms 628892 KB Output is correct
53 Correct 2197 ms 816540 KB Output is correct
54 Correct 1944 ms 652852 KB Output is correct
55 Correct 2372 ms 644608 KB Output is correct
56 Correct 2148 ms 827048 KB Output is correct
57 Correct 2074 ms 827624 KB Output is correct
58 Correct 1933 ms 652380 KB Output is correct
59 Correct 2198 ms 645328 KB Output is correct
60 Correct 2370 ms 687244 KB Output is correct
61 Correct 2136 ms 827592 KB Output is correct
62 Correct 1585 ms 818000 KB Output is correct
63 Correct 1819 ms 823216 KB Output is correct
64 Correct 3704 ms 734512 KB Output is correct
65 Correct 604 ms 99000 KB Output is correct
66 Correct 3471 ms 828132 KB Output is correct
67 Correct 2973 ms 651492 KB Output is correct
68 Correct 3483 ms 639428 KB Output is correct
69 Correct 3327 ms 641552 KB Output is correct
70 Correct 3328 ms 826500 KB Output is correct
71 Correct 3469 ms 828200 KB Output is correct
72 Correct 2981 ms 652488 KB Output is correct
73 Correct 3355 ms 642512 KB Output is correct
74 Correct 3520 ms 680372 KB Output is correct
75 Correct 3592 ms 824864 KB Output is correct
76 Correct 1640 ms 869128 KB Output is correct
77 Correct 1590 ms 835812 KB Output is correct
78 Correct 1743 ms 867428 KB Output is correct
79 Correct 2224 ms 903500 KB Output is correct
80 Correct 1900 ms 852936 KB Output is correct
81 Correct 595 ms 192068 KB Output is correct
82 Correct 597 ms 186976 KB Output is correct
83 Correct 656 ms 190112 KB Output is correct
84 Correct 489 ms 186100 KB Output is correct
85 Correct 529 ms 185076 KB Output is correct
86 Correct 450 ms 185584 KB Output is correct
87 Correct 491 ms 185848 KB Output is correct
88 Correct 495 ms 185076 KB Output is correct
89 Correct 471 ms 184644 KB Output is correct
90 Correct 224 ms 69620 KB Output is correct
91 Correct 610 ms 191088 KB Output is correct
92 Correct 657 ms 189732 KB Output is correct
93 Correct 602 ms 188636 KB Output is correct
94 Correct 623 ms 185340 KB Output is correct
95 Correct 468 ms 184236 KB Output is correct
96 Correct 240 ms 59124 KB Output is correct
97 Correct 3796 ms 653112 KB Output is correct
98 Correct 577 ms 99460 KB Output is correct
99 Correct 4668 ms 813008 KB Output is correct
100 Correct 3761 ms 632012 KB Output is correct
101 Correct 4011 ms 644904 KB Output is correct
102 Correct 4563 ms 829940 KB Output is correct
103 Correct 3604 ms 803900 KB Output is correct
104 Correct 3493 ms 804424 KB Output is correct
105 Correct 1966 ms 801408 KB Output is correct
106 Correct 2208 ms 800684 KB Output is correct
107 Correct 2948 ms 621008 KB Output is correct
108 Correct 2963 ms 617416 KB Output is correct
109 Correct 2932 ms 618288 KB Output is correct
110 Correct 3229 ms 617316 KB Output is correct
111 Correct 3405 ms 614388 KB Output is correct
112 Correct 2949 ms 616824 KB Output is correct
113 Correct 1109 ms 171364 KB Output is correct
114 Correct 3835 ms 654424 KB Output is correct
115 Correct 4097 ms 642900 KB Output is correct
116 Correct 4089 ms 636120 KB Output is correct
117 Correct 3839 ms 619836 KB Output is correct
118 Correct 3372 ms 613020 KB Output is correct
119 Correct 1836 ms 126688 KB Output is correct
120 Correct 1291 ms 689620 KB Output is correct
121 Correct 1371 ms 743332 KB Output is correct
122 Correct 1337 ms 761652 KB Output is correct
123 Correct 1475 ms 735552 KB Output is correct
124 Correct 1710 ms 704040 KB Output is correct
125 Correct 1663 ms 761956 KB Output is correct
126 Correct 1851 ms 688096 KB Output is correct