답안 #219013

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
219013 2020-04-03T11:22:58 Z VEGAnn 새 집 (APIO18_new_home) C++14
100 / 100
2091 ms 69956 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 = 300100;
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 = sz(vc);

    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 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 10 ms 7552 KB Output is correct
6 Correct 10 ms 7552 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 10 ms 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7552 KB Output is correct
12 Correct 9 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 10 ms 7552 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 12 ms 7552 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 12 ms 7600 KB Output is correct
20 Correct 9 ms 7552 KB Output is correct
21 Correct 9 ms 7552 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 10 ms 7552 KB Output is correct
24 Correct 10 ms 7552 KB Output is correct
25 Correct 11 ms 7552 KB Output is correct
26 Correct 9 ms 7552 KB Output is correct
27 Correct 9 ms 7552 KB Output is correct
28 Correct 11 ms 7552 KB Output is correct
29 Correct 10 ms 7552 KB Output is correct
30 Correct 10 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 10 ms 7552 KB Output is correct
6 Correct 10 ms 7552 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 10 ms 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7552 KB Output is correct
12 Correct 9 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 10 ms 7552 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 12 ms 7552 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 12 ms 7600 KB Output is correct
20 Correct 9 ms 7552 KB Output is correct
21 Correct 9 ms 7552 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 10 ms 7552 KB Output is correct
24 Correct 10 ms 7552 KB Output is correct
25 Correct 11 ms 7552 KB Output is correct
26 Correct 9 ms 7552 KB Output is correct
27 Correct 9 ms 7552 KB Output is correct
28 Correct 11 ms 7552 KB Output is correct
29 Correct 10 ms 7552 KB Output is correct
30 Correct 10 ms 7552 KB Output is correct
31 Correct 253 ms 19176 KB Output is correct
32 Correct 182 ms 16492 KB Output is correct
33 Correct 266 ms 18912 KB Output is correct
34 Correct 248 ms 19048 KB Output is correct
35 Correct 264 ms 18540 KB Output is correct
36 Correct 276 ms 18916 KB Output is correct
37 Correct 226 ms 18788 KB Output is correct
38 Correct 249 ms 18784 KB Output is correct
39 Correct 202 ms 18788 KB Output is correct
40 Correct 217 ms 18920 KB Output is correct
41 Correct 189 ms 18408 KB Output is correct
42 Correct 194 ms 18660 KB Output is correct
43 Correct 134 ms 18032 KB Output is correct
44 Correct 193 ms 18792 KB Output is correct
45 Correct 191 ms 18548 KB Output is correct
46 Correct 178 ms 18468 KB Output is correct
47 Correct 153 ms 18284 KB Output is correct
48 Correct 146 ms 18268 KB Output is correct
49 Correct 158 ms 18528 KB Output is correct
50 Correct 181 ms 18804 KB Output is correct
51 Correct 162 ms 18532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 787 ms 55872 KB Output is correct
2 Correct 990 ms 51548 KB Output is correct
3 Correct 896 ms 67000 KB Output is correct
4 Correct 790 ms 52032 KB Output is correct
5 Correct 1521 ms 64704 KB Output is correct
6 Correct 1064 ms 52492 KB Output is correct
7 Correct 754 ms 67176 KB Output is correct
8 Correct 718 ms 51160 KB Output is correct
9 Correct 733 ms 49852 KB Output is correct
10 Correct 835 ms 48288 KB Output is correct
11 Correct 770 ms 50780 KB Output is correct
12 Correct 743 ms 48768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1148 ms 56208 KB Output is correct
2 Correct 932 ms 49624 KB Output is correct
3 Correct 1386 ms 52932 KB Output is correct
4 Correct 1192 ms 65980 KB Output is correct
5 Correct 1088 ms 51388 KB Output is correct
6 Correct 1083 ms 51772 KB Output is correct
7 Correct 2091 ms 66128 KB Output is correct
8 Correct 1536 ms 53824 KB Output is correct
9 Correct 1016 ms 66016 KB Output is correct
10 Correct 1006 ms 52032 KB Output is correct
11 Correct 1078 ms 50748 KB Output is correct
12 Correct 1170 ms 53284 KB Output is correct
13 Correct 832 ms 51524 KB Output is correct
14 Correct 833 ms 51920 KB Output is correct
15 Correct 941 ms 51904 KB Output is correct
16 Correct 973 ms 49408 KB Output is correct
17 Correct 994 ms 51896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 10 ms 7552 KB Output is correct
6 Correct 10 ms 7552 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 10 ms 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7552 KB Output is correct
12 Correct 9 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 10 ms 7552 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 12 ms 7552 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 12 ms 7600 KB Output is correct
20 Correct 9 ms 7552 KB Output is correct
21 Correct 9 ms 7552 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 10 ms 7552 KB Output is correct
24 Correct 10 ms 7552 KB Output is correct
25 Correct 11 ms 7552 KB Output is correct
26 Correct 9 ms 7552 KB Output is correct
27 Correct 9 ms 7552 KB Output is correct
28 Correct 11 ms 7552 KB Output is correct
29 Correct 10 ms 7552 KB Output is correct
30 Correct 10 ms 7552 KB Output is correct
31 Correct 253 ms 19176 KB Output is correct
32 Correct 182 ms 16492 KB Output is correct
33 Correct 266 ms 18912 KB Output is correct
34 Correct 248 ms 19048 KB Output is correct
35 Correct 264 ms 18540 KB Output is correct
36 Correct 276 ms 18916 KB Output is correct
37 Correct 226 ms 18788 KB Output is correct
38 Correct 249 ms 18784 KB Output is correct
39 Correct 202 ms 18788 KB Output is correct
40 Correct 217 ms 18920 KB Output is correct
41 Correct 189 ms 18408 KB Output is correct
42 Correct 194 ms 18660 KB Output is correct
43 Correct 134 ms 18032 KB Output is correct
44 Correct 193 ms 18792 KB Output is correct
45 Correct 191 ms 18548 KB Output is correct
46 Correct 178 ms 18468 KB Output is correct
47 Correct 153 ms 18284 KB Output is correct
48 Correct 146 ms 18268 KB Output is correct
49 Correct 158 ms 18528 KB Output is correct
50 Correct 181 ms 18804 KB Output is correct
51 Correct 162 ms 18532 KB Output is correct
52 Correct 248 ms 20068 KB Output is correct
53 Correct 250 ms 20028 KB Output is correct
54 Correct 235 ms 19044 KB Output is correct
55 Correct 214 ms 19300 KB Output is correct
56 Correct 222 ms 19556 KB Output is correct
57 Correct 205 ms 18708 KB Output is correct
58 Correct 223 ms 19300 KB Output is correct
59 Correct 238 ms 19436 KB Output is correct
60 Correct 205 ms 18920 KB Output is correct
61 Correct 146 ms 18788 KB Output is correct
62 Correct 231 ms 20068 KB Output is correct
63 Correct 229 ms 19296 KB Output is correct
64 Correct 228 ms 19040 KB Output is correct
65 Correct 219 ms 18916 KB Output is correct
66 Correct 200 ms 18788 KB Output is correct
67 Correct 159 ms 16620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 8 ms 7424 KB Output is correct
5 Correct 10 ms 7552 KB Output is correct
6 Correct 10 ms 7552 KB Output is correct
7 Correct 10 ms 7552 KB Output is correct
8 Correct 10 ms 7552 KB Output is correct
9 Correct 10 ms 7552 KB Output is correct
10 Correct 10 ms 7552 KB Output is correct
11 Correct 10 ms 7552 KB Output is correct
12 Correct 9 ms 7552 KB Output is correct
13 Correct 10 ms 7552 KB Output is correct
14 Correct 10 ms 7552 KB Output is correct
15 Correct 10 ms 7552 KB Output is correct
16 Correct 12 ms 7552 KB Output is correct
17 Correct 10 ms 7552 KB Output is correct
18 Correct 10 ms 7552 KB Output is correct
19 Correct 12 ms 7600 KB Output is correct
20 Correct 9 ms 7552 KB Output is correct
21 Correct 9 ms 7552 KB Output is correct
22 Correct 10 ms 7552 KB Output is correct
23 Correct 10 ms 7552 KB Output is correct
24 Correct 10 ms 7552 KB Output is correct
25 Correct 11 ms 7552 KB Output is correct
26 Correct 9 ms 7552 KB Output is correct
27 Correct 9 ms 7552 KB Output is correct
28 Correct 11 ms 7552 KB Output is correct
29 Correct 10 ms 7552 KB Output is correct
30 Correct 10 ms 7552 KB Output is correct
31 Correct 253 ms 19176 KB Output is correct
32 Correct 182 ms 16492 KB Output is correct
33 Correct 266 ms 18912 KB Output is correct
34 Correct 248 ms 19048 KB Output is correct
35 Correct 264 ms 18540 KB Output is correct
36 Correct 276 ms 18916 KB Output is correct
37 Correct 226 ms 18788 KB Output is correct
38 Correct 249 ms 18784 KB Output is correct
39 Correct 202 ms 18788 KB Output is correct
40 Correct 217 ms 18920 KB Output is correct
41 Correct 189 ms 18408 KB Output is correct
42 Correct 194 ms 18660 KB Output is correct
43 Correct 134 ms 18032 KB Output is correct
44 Correct 193 ms 18792 KB Output is correct
45 Correct 191 ms 18548 KB Output is correct
46 Correct 178 ms 18468 KB Output is correct
47 Correct 153 ms 18284 KB Output is correct
48 Correct 146 ms 18268 KB Output is correct
49 Correct 158 ms 18528 KB Output is correct
50 Correct 181 ms 18804 KB Output is correct
51 Correct 162 ms 18532 KB Output is correct
52 Correct 787 ms 55872 KB Output is correct
53 Correct 990 ms 51548 KB Output is correct
54 Correct 896 ms 67000 KB Output is correct
55 Correct 790 ms 52032 KB Output is correct
56 Correct 1521 ms 64704 KB Output is correct
57 Correct 1064 ms 52492 KB Output is correct
58 Correct 754 ms 67176 KB Output is correct
59 Correct 718 ms 51160 KB Output is correct
60 Correct 733 ms 49852 KB Output is correct
61 Correct 835 ms 48288 KB Output is correct
62 Correct 770 ms 50780 KB Output is correct
63 Correct 743 ms 48768 KB Output is correct
64 Correct 1148 ms 56208 KB Output is correct
65 Correct 932 ms 49624 KB Output is correct
66 Correct 1386 ms 52932 KB Output is correct
67 Correct 1192 ms 65980 KB Output is correct
68 Correct 1088 ms 51388 KB Output is correct
69 Correct 1083 ms 51772 KB Output is correct
70 Correct 2091 ms 66128 KB Output is correct
71 Correct 1536 ms 53824 KB Output is correct
72 Correct 1016 ms 66016 KB Output is correct
73 Correct 1006 ms 52032 KB Output is correct
74 Correct 1078 ms 50748 KB Output is correct
75 Correct 1170 ms 53284 KB Output is correct
76 Correct 832 ms 51524 KB Output is correct
77 Correct 833 ms 51920 KB Output is correct
78 Correct 941 ms 51904 KB Output is correct
79 Correct 973 ms 49408 KB Output is correct
80 Correct 994 ms 51896 KB Output is correct
81 Correct 248 ms 20068 KB Output is correct
82 Correct 250 ms 20028 KB Output is correct
83 Correct 235 ms 19044 KB Output is correct
84 Correct 214 ms 19300 KB Output is correct
85 Correct 222 ms 19556 KB Output is correct
86 Correct 205 ms 18708 KB Output is correct
87 Correct 223 ms 19300 KB Output is correct
88 Correct 238 ms 19436 KB Output is correct
89 Correct 205 ms 18920 KB Output is correct
90 Correct 146 ms 18788 KB Output is correct
91 Correct 231 ms 20068 KB Output is correct
92 Correct 229 ms 19296 KB Output is correct
93 Correct 228 ms 19040 KB Output is correct
94 Correct 219 ms 18916 KB Output is correct
95 Correct 200 ms 18788 KB Output is correct
96 Correct 159 ms 16620 KB Output is correct
97 Correct 1447 ms 65980 KB Output is correct
98 Correct 990 ms 50392 KB Output is correct
99 Correct 1601 ms 58804 KB Output is correct
100 Correct 1456 ms 69956 KB Output is correct
101 Correct 1355 ms 57916 KB Output is correct
102 Correct 1664 ms 59012 KB Output is correct
103 Correct 1300 ms 58436 KB Output is correct
104 Correct 1391 ms 59256 KB Output is correct
105 Correct 1144 ms 58304 KB Output is correct
106 Correct 1198 ms 58900 KB Output is correct
107 Correct 1125 ms 57984 KB Output is correct
108 Correct 1144 ms 67664 KB Output is correct
109 Correct 1073 ms 57304 KB Output is correct
110 Correct 1145 ms 57924 KB Output is correct
111 Correct 1197 ms 67632 KB Output is correct
112 Correct 1101 ms 55748 KB Output is correct
113 Correct 695 ms 68684 KB Output is correct
114 Correct 1262 ms 68872 KB Output is correct
115 Correct 1264 ms 67136 KB Output is correct
116 Correct 1215 ms 56836 KB Output is correct
117 Correct 1203 ms 55960 KB Output is correct
118 Correct 1138 ms 55988 KB Output is correct
119 Correct 769 ms 49112 KB Output is correct
120 Correct 708 ms 54724 KB Output is correct
121 Correct 766 ms 55128 KB Output is correct
122 Correct 742 ms 54856 KB Output is correct
123 Correct 824 ms 54856 KB Output is correct
124 Correct 904 ms 52316 KB Output is correct
125 Correct 812 ms 54892 KB Output is correct
126 Correct 964 ms 53548 KB Output is correct