Submission #968547

# Submission time Handle Problem Language Result Execution time Memory
968547 2024-04-23T15:15:35 Z socpite New Home (APIO18_new_home) C++14
47 / 100
5000 ms 328700 KB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 3e5+5;
const int INF = 1e9+5;

vector<pair<int, pair<int, int>>> ev;
vector<int> cp;
int n, q, k;

int ans[maxn];
int p[maxn], ty[maxn];
int L[maxn], Y[maxn];

multiset<int> st[4*maxn], pos[maxn];

void add_st(int ql, int qr, int val, int l = 0, int r = cp.size()-1, int id = 1){
    if(ql > qr)return;
    if(cp[l] > qr || cp[r] < ql)return;
    if(ql <= cp[l] && cp[r] <= qr)st[id].insert(val);
    else {
        int mid = (l+r)>>1;
        add_st(ql, qr, val, l, mid, id<<1);
        add_st(ql, qr, val, mid+1, r, id<<1|1);
    }
}

void del_st(int ql, int qr, int val, int l = 0, int r = cp.size()-1, int id = 1){
    if(ql > qr)return;
    if(cp[l] > qr || cp[r] < ql)return;
    if(ql <= cp[l] && cp[r] <= qr)st[id].erase(st[id].find(val));
    else {
        int mid = (l+r)>>1;
        del_st(ql, qr, val, l, mid, id<<1);
        del_st(ql, qr, val, mid+1, r, id<<1|1);
    }
}

pair<int, int> get(int pos, int l = 0, int r = cp.size()-1, int id = 1){
    pair<int, int> re = make_pair(st[id].empty() ? -INF : max(*st[id].rbegin() - pos, pos - *st[id].begin()), st[id].size());
    if(l < r){
        int mid = (l+r)>>1;
        pair<int, int> tmp = pos <= cp[mid] ? get(pos, l, mid, id<<1) : get(pos, mid+1, r, id<<1|1);
        re.first = max(re.first, tmp.first);
        re.second += tmp.second;
    }
    return re;
}

void add_range(int l, int r){
    if(l == -INF)add_st(-INF, r, r);
    else if(r == INF)add_st(l+1, INF, l);
    else {
        int mid = (l+r)/2;
        add_st(l+1, mid, l);
        add_st(mid+1, r, r);
    }
}

void del_range(int l, int r){
    if(l == -INF)del_st(-INF, r, r);
    else if(r == INF)del_st(l+1, INF, l);
    else {
        int mid = (l+r)/2;
        del_st(l+1, mid, l);
        del_st(mid+1, r, r);
    }
}

void add(int x, int col){
    auto it = pos[col].insert(x);
    if(pos[col].size() == 1){
        add_range(-INF, x);
        add_range(x, INF);
    }
    else {
        if(next(it) == pos[col].end()){
            del_range(*prev(it), INF);
            add_range(*prev(it), x);
            add_range(x, INF);
        }
        else if(it == pos[col].begin()){
            del_range(-INF, *next(it));
            add_range(-INF, x);
            add_range(x, *next(it));
        }
        else {
            del_range(*prev(it), *next(it));
            add_range(*prev(it), *it);
            add_range(*it, *next(it));
        }
    }
}

void del(int x, int col){
    auto it = pos[col].erase(pos[col].find(x));
    if(pos[col].size() == 0){
        del_range(-INF, x);
        del_range(x, INF);
    }
    else {
        if(it == pos[col].end()){
            del_range(x, INF);
            del_range(*prev(it), x);
            add_range(*prev(it), INF);
        }
        else if(it == pos[col].begin()){
            del_range(-INF, x);
            del_range(x, *it);
            add_range(-INF, *it);
        }
        else {
            del_range(x, *it);
            del_range(*prev(it), x);
            add_range(*prev(it), *it);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k >> q;
    for(int i = 1; i <= n; i++){
        int a, b;
        cin >> p[i] >> ty[i] >> a >> b;
        ev.push_back({a, {0, i}});
        ev.push_back({b+1, {1, i}});
    }
    for(int i = 1; i <= q; i++){
        cin >> L[i] >> Y[i];
        ev.push_back({Y[i], {2, i}});
        cp.push_back(L[i]);
    }
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    sort(ev.begin(), ev.end());
    for(auto ele: ev){
        pair<int, int> event = ele.second;
        if(event.first == 0)add(p[event.second], ty[event.second]);
        else if(event.first == 1)del(p[event.second], ty[event.second]);
        else {
            pair<int, int> tmp = get(L[event.second]);
            ans[event.second] = tmp.second == k ? tmp.first : -1;
        }
    }
    for(int i = 1; i <= q; i++)cout << ans[i] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 17 ms 76556 KB Output is correct
2 Correct 16 ms 76380 KB Output is correct
3 Correct 15 ms 76380 KB Output is correct
4 Correct 15 ms 76380 KB Output is correct
5 Correct 16 ms 76544 KB Output is correct
6 Correct 17 ms 76632 KB Output is correct
7 Correct 16 ms 76636 KB Output is correct
8 Correct 17 ms 76636 KB Output is correct
9 Correct 17 ms 76760 KB Output is correct
10 Correct 17 ms 76636 KB Output is correct
11 Correct 16 ms 76380 KB Output is correct
12 Correct 16 ms 76376 KB Output is correct
13 Correct 16 ms 76380 KB Output is correct
14 Correct 16 ms 76568 KB Output is correct
15 Correct 18 ms 76664 KB Output is correct
16 Correct 17 ms 76636 KB Output is correct
17 Correct 18 ms 76636 KB Output is correct
18 Correct 17 ms 76636 KB Output is correct
19 Correct 17 ms 76636 KB Output is correct
20 Correct 17 ms 76632 KB Output is correct
21 Correct 16 ms 76644 KB Output is correct
22 Correct 16 ms 76776 KB Output is correct
23 Correct 17 ms 76636 KB Output is correct
24 Correct 20 ms 76636 KB Output is correct
25 Correct 19 ms 76636 KB Output is correct
26 Correct 21 ms 76380 KB Output is correct
27 Correct 16 ms 76376 KB Output is correct
28 Correct 17 ms 76380 KB Output is correct
29 Correct 16 ms 76536 KB Output is correct
30 Correct 16 ms 76380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 76556 KB Output is correct
2 Correct 16 ms 76380 KB Output is correct
3 Correct 15 ms 76380 KB Output is correct
4 Correct 15 ms 76380 KB Output is correct
5 Correct 16 ms 76544 KB Output is correct
6 Correct 17 ms 76632 KB Output is correct
7 Correct 16 ms 76636 KB Output is correct
8 Correct 17 ms 76636 KB Output is correct
9 Correct 17 ms 76760 KB Output is correct
10 Correct 17 ms 76636 KB Output is correct
11 Correct 16 ms 76380 KB Output is correct
12 Correct 16 ms 76376 KB Output is correct
13 Correct 16 ms 76380 KB Output is correct
14 Correct 16 ms 76568 KB Output is correct
15 Correct 18 ms 76664 KB Output is correct
16 Correct 17 ms 76636 KB Output is correct
17 Correct 18 ms 76636 KB Output is correct
18 Correct 17 ms 76636 KB Output is correct
19 Correct 17 ms 76636 KB Output is correct
20 Correct 17 ms 76632 KB Output is correct
21 Correct 16 ms 76644 KB Output is correct
22 Correct 16 ms 76776 KB Output is correct
23 Correct 17 ms 76636 KB Output is correct
24 Correct 20 ms 76636 KB Output is correct
25 Correct 19 ms 76636 KB Output is correct
26 Correct 21 ms 76380 KB Output is correct
27 Correct 16 ms 76376 KB Output is correct
28 Correct 17 ms 76380 KB Output is correct
29 Correct 16 ms 76536 KB Output is correct
30 Correct 16 ms 76380 KB Output is correct
31 Correct 1976 ms 123208 KB Output is correct
32 Correct 95 ms 81456 KB Output is correct
33 Correct 554 ms 90304 KB Output is correct
34 Correct 1608 ms 100196 KB Output is correct
35 Correct 1416 ms 114996 KB Output is correct
36 Correct 647 ms 97216 KB Output is correct
37 Correct 502 ms 84836 KB Output is correct
38 Correct 290 ms 83048 KB Output is correct
39 Correct 282 ms 82388 KB Output is correct
40 Correct 258 ms 82260 KB Output is correct
41 Correct 497 ms 83792 KB Output is correct
42 Correct 545 ms 83564 KB Output is correct
43 Correct 64 ms 84412 KB Output is correct
44 Correct 490 ms 82880 KB Output is correct
45 Correct 429 ms 83128 KB Output is correct
46 Correct 312 ms 82364 KB Output is correct
47 Correct 212 ms 82120 KB Output is correct
48 Correct 200 ms 83400 KB Output is correct
49 Correct 270 ms 82884 KB Output is correct
50 Correct 406 ms 83128 KB Output is correct
51 Correct 268 ms 82604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5095 ms 328700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5057 ms 259360 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 76556 KB Output is correct
2 Correct 16 ms 76380 KB Output is correct
3 Correct 15 ms 76380 KB Output is correct
4 Correct 15 ms 76380 KB Output is correct
5 Correct 16 ms 76544 KB Output is correct
6 Correct 17 ms 76632 KB Output is correct
7 Correct 16 ms 76636 KB Output is correct
8 Correct 17 ms 76636 KB Output is correct
9 Correct 17 ms 76760 KB Output is correct
10 Correct 17 ms 76636 KB Output is correct
11 Correct 16 ms 76380 KB Output is correct
12 Correct 16 ms 76376 KB Output is correct
13 Correct 16 ms 76380 KB Output is correct
14 Correct 16 ms 76568 KB Output is correct
15 Correct 18 ms 76664 KB Output is correct
16 Correct 17 ms 76636 KB Output is correct
17 Correct 18 ms 76636 KB Output is correct
18 Correct 17 ms 76636 KB Output is correct
19 Correct 17 ms 76636 KB Output is correct
20 Correct 17 ms 76632 KB Output is correct
21 Correct 16 ms 76644 KB Output is correct
22 Correct 16 ms 76776 KB Output is correct
23 Correct 17 ms 76636 KB Output is correct
24 Correct 20 ms 76636 KB Output is correct
25 Correct 19 ms 76636 KB Output is correct
26 Correct 21 ms 76380 KB Output is correct
27 Correct 16 ms 76376 KB Output is correct
28 Correct 17 ms 76380 KB Output is correct
29 Correct 16 ms 76536 KB Output is correct
30 Correct 16 ms 76380 KB Output is correct
31 Correct 1976 ms 123208 KB Output is correct
32 Correct 95 ms 81456 KB Output is correct
33 Correct 554 ms 90304 KB Output is correct
34 Correct 1608 ms 100196 KB Output is correct
35 Correct 1416 ms 114996 KB Output is correct
36 Correct 647 ms 97216 KB Output is correct
37 Correct 502 ms 84836 KB Output is correct
38 Correct 290 ms 83048 KB Output is correct
39 Correct 282 ms 82388 KB Output is correct
40 Correct 258 ms 82260 KB Output is correct
41 Correct 497 ms 83792 KB Output is correct
42 Correct 545 ms 83564 KB Output is correct
43 Correct 64 ms 84412 KB Output is correct
44 Correct 490 ms 82880 KB Output is correct
45 Correct 429 ms 83128 KB Output is correct
46 Correct 312 ms 82364 KB Output is correct
47 Correct 212 ms 82120 KB Output is correct
48 Correct 200 ms 83400 KB Output is correct
49 Correct 270 ms 82884 KB Output is correct
50 Correct 406 ms 83128 KB Output is correct
51 Correct 268 ms 82604 KB Output is correct
52 Correct 580 ms 129728 KB Output is correct
53 Correct 490 ms 99652 KB Output is correct
54 Correct 1933 ms 143660 KB Output is correct
55 Correct 626 ms 99004 KB Output is correct
56 Correct 656 ms 107340 KB Output is correct
57 Correct 573 ms 88508 KB Output is correct
58 Correct 667 ms 98716 KB Output is correct
59 Correct 719 ms 107232 KB Output is correct
60 Correct 637 ms 87636 KB Output is correct
61 Correct 71 ms 88060 KB Output is correct
62 Correct 596 ms 130780 KB Output is correct
63 Correct 1342 ms 129792 KB Output is correct
64 Correct 1657 ms 121816 KB Output is correct
65 Correct 1216 ms 95932 KB Output is correct
66 Correct 598 ms 83996 KB Output is correct
67 Correct 352 ms 84476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 76556 KB Output is correct
2 Correct 16 ms 76380 KB Output is correct
3 Correct 15 ms 76380 KB Output is correct
4 Correct 15 ms 76380 KB Output is correct
5 Correct 16 ms 76544 KB Output is correct
6 Correct 17 ms 76632 KB Output is correct
7 Correct 16 ms 76636 KB Output is correct
8 Correct 17 ms 76636 KB Output is correct
9 Correct 17 ms 76760 KB Output is correct
10 Correct 17 ms 76636 KB Output is correct
11 Correct 16 ms 76380 KB Output is correct
12 Correct 16 ms 76376 KB Output is correct
13 Correct 16 ms 76380 KB Output is correct
14 Correct 16 ms 76568 KB Output is correct
15 Correct 18 ms 76664 KB Output is correct
16 Correct 17 ms 76636 KB Output is correct
17 Correct 18 ms 76636 KB Output is correct
18 Correct 17 ms 76636 KB Output is correct
19 Correct 17 ms 76636 KB Output is correct
20 Correct 17 ms 76632 KB Output is correct
21 Correct 16 ms 76644 KB Output is correct
22 Correct 16 ms 76776 KB Output is correct
23 Correct 17 ms 76636 KB Output is correct
24 Correct 20 ms 76636 KB Output is correct
25 Correct 19 ms 76636 KB Output is correct
26 Correct 21 ms 76380 KB Output is correct
27 Correct 16 ms 76376 KB Output is correct
28 Correct 17 ms 76380 KB Output is correct
29 Correct 16 ms 76536 KB Output is correct
30 Correct 16 ms 76380 KB Output is correct
31 Correct 1976 ms 123208 KB Output is correct
32 Correct 95 ms 81456 KB Output is correct
33 Correct 554 ms 90304 KB Output is correct
34 Correct 1608 ms 100196 KB Output is correct
35 Correct 1416 ms 114996 KB Output is correct
36 Correct 647 ms 97216 KB Output is correct
37 Correct 502 ms 84836 KB Output is correct
38 Correct 290 ms 83048 KB Output is correct
39 Correct 282 ms 82388 KB Output is correct
40 Correct 258 ms 82260 KB Output is correct
41 Correct 497 ms 83792 KB Output is correct
42 Correct 545 ms 83564 KB Output is correct
43 Correct 64 ms 84412 KB Output is correct
44 Correct 490 ms 82880 KB Output is correct
45 Correct 429 ms 83128 KB Output is correct
46 Correct 312 ms 82364 KB Output is correct
47 Correct 212 ms 82120 KB Output is correct
48 Correct 200 ms 83400 KB Output is correct
49 Correct 270 ms 82884 KB Output is correct
50 Correct 406 ms 83128 KB Output is correct
51 Correct 268 ms 82604 KB Output is correct
52 Execution timed out 5095 ms 328700 KB Time limit exceeded
53 Halted 0 ms 0 KB -