답안 #219007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219007 2020-04-03T11:19:22 Z VEGAnn 새 집 (APIO18_new_home) C++14
100 / 100
2172 ms 82424 KB
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define ft first
#define sd second
#define sz(x) ((int)x.size())
using namespace std;
const int N = (1 << 19) + 10;
const int oo = int(2e9) + 7;
const int big = int(1e8);
vector<array<int, 4> > qr;
vector<pii> events[N];
vector<int> vc;
int a[N], b[N], x[N], t[N], n, k, q, ans[N], l[N], y[N];
int mrk[N], st[4 * N], nm[N];
map<pii, int> mp;
map<pii, int>::iterator ite, pre, net;

bool cmp(int x, int y){
    return l[x] < l[y];
}

void calc(){
    fill(mrk, mrk + n, 0);
    mp.clear();
    qr.clear();
    mp[MP(x[n], n)] = 0;

    for (int i = 0; i < k; i++){
        mp[MP(x[n + 1], n + 1)] = sz(qr);
        qr.PB({0, 0, sz(vc) - 1, 2 * big});

        for (pii ev : events[i]) {
            int nm = ev.sd, tim = ev.ft;

            if (mrk[nm] == 1){
                ite = mp.find(MP(x[nm], nm));
                net = next(ite);

                qr[ite -> sd][2] = qr[net -> sd][2] = tim;

                mp.erase(ite);
                pre = prev(net);

                net -> sd = sz(qr);

                int i2 = net -> ft.sd;
                int i1 = pre -> ft.sd;
                int len = (x[i2] - x[i1]) / 2;

                qr.PB({x[i2] - len, tim, sz(vc) - 1, len});
            } else {
                mp[MP(x[nm], nm)] = 0;

                ite = mp.find(MP(x[nm], nm));
                pre = prev(ite);
                net = next(ite);

                qr[net -> sd][2] = tim;

                int i1 = pre -> ft.sd;
                int i2 = ite -> ft.sd;
                int i3 = net -> ft.sd;

                net -> sd = sz(qr);
                int len = (x[i3] - x[i2]) / 2;
                qr.PB({x[i3] - len, tim, sz(vc) - 1, len});

                ite -> sd = sz(qr);
                len = (x[i2] - x[i1]) / 2;
                qr.PB({x[i2] - len, tim, sz(vc) - 1, len});
            }

            mrk[nm]++;
        }
    }

    sort(all(qr));

    int siz = 1;

    while (siz < sz(vc)) siz <<= 1;

    fill(st, st + 2 * siz, 0);

    sort(nm, nm + q, cmp);

    int i1 = 0, i2 = 0;

    for (; i1 < q; i1++){
        int i = nm[i1];

        while (i2 < sz(qr) && qr[i2][0] <= l[i]){
            int lf = qr[i2][1] + siz, rt = qr[i2][2] + siz - 1;
            int vl = qr[i2][0] + qr[i2][3];

            while (lf <= rt){
                if (lf & 1)
                    st[lf] = max(st[lf], vl);

                if (!(rt & 1))
                    st[rt] = max(st[rt], vl);

                lf = (lf + 1) >> 1;
                rt = (rt - 1) >> 1;
            }

            i2++;
        }

        int loc = siz + y[i];

        for (; loc > 0; loc >>= 1)
            ans[i] = max(ans[i], st[loc] - l[i]);
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

//    freopen("in.txt","r",stdin);

    cin >> n >> k >> q;

    for (int i = 0; i < n; i++){
        cin >> x[i] >> t[i] >> a[i] >> b[i];
        t[i]--; b[i]++;
        vc.PB(a[i]);
        vc.PB(b[i]);
    }

    vc.PB(0);
    vc.PB(big + 1);
    sort(all(vc));
    vc.resize(unique(all(vc)) - vc.begin());

    for (int i = 0; i < n; i++){
        a[i] = lower_bound(all(vc), a[i]) - vc.begin();
        b[i] = lower_bound(all(vc), b[i]) - vc.begin();

        events[t[i]].PB(MP(a[i], i));
        events[t[i]].PB(MP(b[i], i));
    }

    for (int i = 0; i < k; i++){
        if (!sz(events[i])) {
            for (; q; q--) cout << "-1\n";
            return 0;
        }

        sort(all(events[i]));
    }

    for (int i = 0; i < q; i++){
        cin >> l[i] >> y[i];
        y[i] = upper_bound(all(vc), y[i]) - vc.begin() - 1;
        nm[i] = i;
    }

    x[n] = -2 * big;
    x[n + 1] = +2 * big;

    calc();

    for (int i = 0; i < q; i++)
        l[i] = big - l[i];

    for (int i = 0; i < n; i++)
        x[i] = big - x[i];

    calc();

    for (int i = 0; i < q; i++)
        cout << (ans[i] >= big ? -1 : ans[i]) << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12672 KB Output is correct
2 Correct 12 ms 12672 KB Output is correct
3 Correct 12 ms 12672 KB Output is correct
4 Correct 12 ms 12672 KB Output is correct
5 Correct 13 ms 12800 KB Output is correct
6 Correct 13 ms 12800 KB Output is correct
7 Correct 13 ms 12928 KB Output is correct
8 Correct 13 ms 12800 KB Output is correct
9 Correct 13 ms 12928 KB Output is correct
10 Correct 14 ms 12800 KB Output is correct
11 Correct 13 ms 12928 KB Output is correct
12 Correct 13 ms 12928 KB Output is correct
13 Correct 13 ms 12800 KB Output is correct
14 Correct 14 ms 12800 KB Output is correct
15 Correct 13 ms 12928 KB Output is correct
16 Correct 13 ms 12800 KB Output is correct
17 Correct 16 ms 12928 KB Output is correct
18 Correct 13 ms 12800 KB Output is correct
19 Correct 13 ms 12928 KB Output is correct
20 Correct 13 ms 12928 KB Output is correct
21 Correct 12 ms 12800 KB Output is correct
22 Correct 13 ms 12928 KB Output is correct
23 Correct 13 ms 12800 KB Output is correct
24 Correct 13 ms 12800 KB Output is correct
25 Correct 14 ms 12928 KB Output is correct
26 Correct 13 ms 12928 KB Output is correct
27 Correct 13 ms 12800 KB Output is correct
28 Correct 13 ms 12928 KB Output is correct
29 Correct 13 ms 12928 KB Output is correct
30 Correct 13 ms 12800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12672 KB Output is correct
2 Correct 12 ms 12672 KB Output is correct
3 Correct 12 ms 12672 KB Output is correct
4 Correct 12 ms 12672 KB Output is correct
5 Correct 13 ms 12800 KB Output is correct
6 Correct 13 ms 12800 KB Output is correct
7 Correct 13 ms 12928 KB Output is correct
8 Correct 13 ms 12800 KB Output is correct
9 Correct 13 ms 12928 KB Output is correct
10 Correct 14 ms 12800 KB Output is correct
11 Correct 13 ms 12928 KB Output is correct
12 Correct 13 ms 12928 KB Output is correct
13 Correct 13 ms 12800 KB Output is correct
14 Correct 14 ms 12800 KB Output is correct
15 Correct 13 ms 12928 KB Output is correct
16 Correct 13 ms 12800 KB Output is correct
17 Correct 16 ms 12928 KB Output is correct
18 Correct 13 ms 12800 KB Output is correct
19 Correct 13 ms 12928 KB Output is correct
20 Correct 13 ms 12928 KB Output is correct
21 Correct 12 ms 12800 KB Output is correct
22 Correct 13 ms 12928 KB Output is correct
23 Correct 13 ms 12800 KB Output is correct
24 Correct 13 ms 12800 KB Output is correct
25 Correct 14 ms 12928 KB Output is correct
26 Correct 13 ms 12928 KB Output is correct
27 Correct 13 ms 12800 KB Output is correct
28 Correct 13 ms 12928 KB Output is correct
29 Correct 13 ms 12928 KB Output is correct
30 Correct 13 ms 12800 KB Output is correct
31 Correct 250 ms 23400 KB Output is correct
32 Correct 185 ms 21868 KB Output is correct
33 Correct 281 ms 23140 KB Output is correct
34 Correct 252 ms 23284 KB Output is correct
35 Correct 256 ms 22772 KB Output is correct
36 Correct 279 ms 23268 KB Output is correct
37 Correct 234 ms 23244 KB Output is correct
38 Correct 240 ms 23144 KB Output is correct
39 Correct 205 ms 23140 KB Output is correct
40 Correct 213 ms 23140 KB Output is correct
41 Correct 191 ms 22632 KB Output is correct
42 Correct 197 ms 22884 KB Output is correct
43 Correct 133 ms 22768 KB Output is correct
44 Correct 192 ms 22920 KB Output is correct
45 Correct 189 ms 22896 KB Output is correct
46 Correct 175 ms 22824 KB Output is correct
47 Correct 159 ms 22756 KB Output is correct
48 Correct 161 ms 22792 KB Output is correct
49 Correct 165 ms 23012 KB Output is correct
50 Correct 180 ms 23160 KB Output is correct
51 Correct 162 ms 23012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 785 ms 53860 KB Output is correct
2 Correct 990 ms 53584 KB Output is correct
3 Correct 885 ms 69188 KB Output is correct
4 Correct 790 ms 54332 KB Output is correct
5 Correct 1475 ms 66728 KB Output is correct
6 Correct 1047 ms 54536 KB Output is correct
7 Correct 740 ms 69272 KB Output is correct
8 Correct 703 ms 53304 KB Output is correct
9 Correct 740 ms 52152 KB Output is correct
10 Correct 846 ms 50464 KB Output is correct
11 Correct 763 ms 52896 KB Output is correct
12 Correct 762 ms 50796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1151 ms 55972 KB Output is correct
2 Correct 913 ms 53080 KB Output is correct
3 Correct 1366 ms 57416 KB Output is correct
4 Correct 1185 ms 68676 KB Output is correct
5 Correct 1089 ms 55616 KB Output is correct
6 Correct 1096 ms 55996 KB Output is correct
7 Correct 2172 ms 70524 KB Output is correct
8 Correct 1525 ms 57996 KB Output is correct
9 Correct 1020 ms 68416 KB Output is correct
10 Correct 994 ms 56380 KB Output is correct
11 Correct 1049 ms 55084 KB Output is correct
12 Correct 1160 ms 57284 KB Output is correct
13 Correct 845 ms 56004 KB Output is correct
14 Correct 856 ms 56388 KB Output is correct
15 Correct 939 ms 56260 KB Output is correct
16 Correct 944 ms 53756 KB Output is correct
17 Correct 979 ms 56192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12672 KB Output is correct
2 Correct 12 ms 12672 KB Output is correct
3 Correct 12 ms 12672 KB Output is correct
4 Correct 12 ms 12672 KB Output is correct
5 Correct 13 ms 12800 KB Output is correct
6 Correct 13 ms 12800 KB Output is correct
7 Correct 13 ms 12928 KB Output is correct
8 Correct 13 ms 12800 KB Output is correct
9 Correct 13 ms 12928 KB Output is correct
10 Correct 14 ms 12800 KB Output is correct
11 Correct 13 ms 12928 KB Output is correct
12 Correct 13 ms 12928 KB Output is correct
13 Correct 13 ms 12800 KB Output is correct
14 Correct 14 ms 12800 KB Output is correct
15 Correct 13 ms 12928 KB Output is correct
16 Correct 13 ms 12800 KB Output is correct
17 Correct 16 ms 12928 KB Output is correct
18 Correct 13 ms 12800 KB Output is correct
19 Correct 13 ms 12928 KB Output is correct
20 Correct 13 ms 12928 KB Output is correct
21 Correct 12 ms 12800 KB Output is correct
22 Correct 13 ms 12928 KB Output is correct
23 Correct 13 ms 12800 KB Output is correct
24 Correct 13 ms 12800 KB Output is correct
25 Correct 14 ms 12928 KB Output is correct
26 Correct 13 ms 12928 KB Output is correct
27 Correct 13 ms 12800 KB Output is correct
28 Correct 13 ms 12928 KB Output is correct
29 Correct 13 ms 12928 KB Output is correct
30 Correct 13 ms 12800 KB Output is correct
31 Correct 250 ms 23400 KB Output is correct
32 Correct 185 ms 21868 KB Output is correct
33 Correct 281 ms 23140 KB Output is correct
34 Correct 252 ms 23284 KB Output is correct
35 Correct 256 ms 22772 KB Output is correct
36 Correct 279 ms 23268 KB Output is correct
37 Correct 234 ms 23244 KB Output is correct
38 Correct 240 ms 23144 KB Output is correct
39 Correct 205 ms 23140 KB Output is correct
40 Correct 213 ms 23140 KB Output is correct
41 Correct 191 ms 22632 KB Output is correct
42 Correct 197 ms 22884 KB Output is correct
43 Correct 133 ms 22768 KB Output is correct
44 Correct 192 ms 22920 KB Output is correct
45 Correct 189 ms 22896 KB Output is correct
46 Correct 175 ms 22824 KB Output is correct
47 Correct 159 ms 22756 KB Output is correct
48 Correct 161 ms 22792 KB Output is correct
49 Correct 165 ms 23012 KB Output is correct
50 Correct 180 ms 23160 KB Output is correct
51 Correct 162 ms 23012 KB Output is correct
52 Correct 238 ms 23392 KB Output is correct
53 Correct 238 ms 23396 KB Output is correct
54 Correct 233 ms 22440 KB Output is correct
55 Correct 213 ms 22884 KB Output is correct
56 Correct 213 ms 23140 KB Output is correct
57 Correct 198 ms 22248 KB Output is correct
58 Correct 214 ms 22760 KB Output is correct
59 Correct 214 ms 22884 KB Output is correct
60 Correct 196 ms 22376 KB Output is correct
61 Correct 149 ms 22844 KB Output is correct
62 Correct 231 ms 23524 KB Output is correct
63 Correct 224 ms 22756 KB Output is correct
64 Correct 222 ms 22508 KB Output is correct
65 Correct 209 ms 22368 KB Output is correct
66 Correct 197 ms 22240 KB Output is correct
67 Correct 169 ms 21612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12672 KB Output is correct
2 Correct 12 ms 12672 KB Output is correct
3 Correct 12 ms 12672 KB Output is correct
4 Correct 12 ms 12672 KB Output is correct
5 Correct 13 ms 12800 KB Output is correct
6 Correct 13 ms 12800 KB Output is correct
7 Correct 13 ms 12928 KB Output is correct
8 Correct 13 ms 12800 KB Output is correct
9 Correct 13 ms 12928 KB Output is correct
10 Correct 14 ms 12800 KB Output is correct
11 Correct 13 ms 12928 KB Output is correct
12 Correct 13 ms 12928 KB Output is correct
13 Correct 13 ms 12800 KB Output is correct
14 Correct 14 ms 12800 KB Output is correct
15 Correct 13 ms 12928 KB Output is correct
16 Correct 13 ms 12800 KB Output is correct
17 Correct 16 ms 12928 KB Output is correct
18 Correct 13 ms 12800 KB Output is correct
19 Correct 13 ms 12928 KB Output is correct
20 Correct 13 ms 12928 KB Output is correct
21 Correct 12 ms 12800 KB Output is correct
22 Correct 13 ms 12928 KB Output is correct
23 Correct 13 ms 12800 KB Output is correct
24 Correct 13 ms 12800 KB Output is correct
25 Correct 14 ms 12928 KB Output is correct
26 Correct 13 ms 12928 KB Output is correct
27 Correct 13 ms 12800 KB Output is correct
28 Correct 13 ms 12928 KB Output is correct
29 Correct 13 ms 12928 KB Output is correct
30 Correct 13 ms 12800 KB Output is correct
31 Correct 250 ms 23400 KB Output is correct
32 Correct 185 ms 21868 KB Output is correct
33 Correct 281 ms 23140 KB Output is correct
34 Correct 252 ms 23284 KB Output is correct
35 Correct 256 ms 22772 KB Output is correct
36 Correct 279 ms 23268 KB Output is correct
37 Correct 234 ms 23244 KB Output is correct
38 Correct 240 ms 23144 KB Output is correct
39 Correct 205 ms 23140 KB Output is correct
40 Correct 213 ms 23140 KB Output is correct
41 Correct 191 ms 22632 KB Output is correct
42 Correct 197 ms 22884 KB Output is correct
43 Correct 133 ms 22768 KB Output is correct
44 Correct 192 ms 22920 KB Output is correct
45 Correct 189 ms 22896 KB Output is correct
46 Correct 175 ms 22824 KB Output is correct
47 Correct 159 ms 22756 KB Output is correct
48 Correct 161 ms 22792 KB Output is correct
49 Correct 165 ms 23012 KB Output is correct
50 Correct 180 ms 23160 KB Output is correct
51 Correct 162 ms 23012 KB Output is correct
52 Correct 785 ms 53860 KB Output is correct
53 Correct 990 ms 53584 KB Output is correct
54 Correct 885 ms 69188 KB Output is correct
55 Correct 790 ms 54332 KB Output is correct
56 Correct 1475 ms 66728 KB Output is correct
57 Correct 1047 ms 54536 KB Output is correct
58 Correct 740 ms 69272 KB Output is correct
59 Correct 703 ms 53304 KB Output is correct
60 Correct 740 ms 52152 KB Output is correct
61 Correct 846 ms 50464 KB Output is correct
62 Correct 763 ms 52896 KB Output is correct
63 Correct 762 ms 50796 KB Output is correct
64 Correct 1151 ms 55972 KB Output is correct
65 Correct 913 ms 53080 KB Output is correct
66 Correct 1366 ms 57416 KB Output is correct
67 Correct 1185 ms 68676 KB Output is correct
68 Correct 1089 ms 55616 KB Output is correct
69 Correct 1096 ms 55996 KB Output is correct
70 Correct 2172 ms 70524 KB Output is correct
71 Correct 1525 ms 57996 KB Output is correct
72 Correct 1020 ms 68416 KB Output is correct
73 Correct 994 ms 56380 KB Output is correct
74 Correct 1049 ms 55084 KB Output is correct
75 Correct 1160 ms 57284 KB Output is correct
76 Correct 845 ms 56004 KB Output is correct
77 Correct 856 ms 56388 KB Output is correct
78 Correct 939 ms 56260 KB Output is correct
79 Correct 944 ms 53756 KB Output is correct
80 Correct 979 ms 56192 KB Output is correct
81 Correct 238 ms 23392 KB Output is correct
82 Correct 238 ms 23396 KB Output is correct
83 Correct 233 ms 22440 KB Output is correct
84 Correct 213 ms 22884 KB Output is correct
85 Correct 213 ms 23140 KB Output is correct
86 Correct 198 ms 22248 KB Output is correct
87 Correct 214 ms 22760 KB Output is correct
88 Correct 214 ms 22884 KB Output is correct
89 Correct 196 ms 22376 KB Output is correct
90 Correct 149 ms 22844 KB Output is correct
91 Correct 231 ms 23524 KB Output is correct
92 Correct 224 ms 22756 KB Output is correct
93 Correct 222 ms 22508 KB Output is correct
94 Correct 209 ms 22368 KB Output is correct
95 Correct 197 ms 22240 KB Output is correct
96 Correct 169 ms 21612 KB Output is correct
97 Correct 1453 ms 67336 KB Output is correct
98 Correct 990 ms 55780 KB Output is correct
99 Correct 1602 ms 73448 KB Output is correct
100 Correct 1469 ms 82424 KB Output is correct
101 Correct 1353 ms 73532 KB Output is correct
102 Correct 1663 ms 73924 KB Output is correct
103 Correct 1334 ms 73508 KB Output is correct
104 Correct 1410 ms 74244 KB Output is correct
105 Correct 1117 ms 73416 KB Output is correct
106 Correct 1189 ms 74164 KB Output is correct
107 Correct 1130 ms 74580 KB Output is correct
108 Correct 1177 ms 80580 KB Output is correct
109 Correct 1105 ms 73820 KB Output is correct
110 Correct 1185 ms 74692 KB Output is correct
111 Correct 1220 ms 80984 KB Output is correct
112 Correct 1145 ms 72720 KB Output is correct
113 Correct 705 ms 79316 KB Output is correct
114 Correct 1329 ms 82368 KB Output is correct
115 Correct 1324 ms 80700 KB Output is correct
116 Correct 1291 ms 73812 KB Output is correct
117 Correct 1271 ms 73316 KB Output is correct
118 Correct 1130 ms 72896 KB Output is correct
119 Correct 772 ms 54360 KB Output is correct
120 Correct 726 ms 71388 KB Output is correct
121 Correct 774 ms 72032 KB Output is correct
122 Correct 750 ms 71900 KB Output is correct
123 Correct 815 ms 72676 KB Output is correct
124 Correct 894 ms 70840 KB Output is correct
125 Correct 829 ms 73216 KB Output is correct
126 Correct 976 ms 72840 KB Output is correct