답안 #735240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
735240 2023-05-03T18:20:31 Z socpite 새 집 (APIO18_new_home) C++14
57 / 100
5000 ms 422480 KB
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

#define f first 
#define s second

typedef long long ll;

const int inf = 1e8+5;
const int maxn = 3e5+5;

vector<int> posq;
int n, K, q;

int X[maxn], T[maxn], A[maxn], B[maxn], L[maxn], Y[maxn], ans[maxn], td[maxn][2];

int etype[maxn];

int tot;

set<pair<int, int>> lmao[maxn];
priority_queue<pair<int, pair<int, int>>> st[4*maxn][2];

void _add(int l, int r, int ql, int qr, pair<int, int> k, int ty, int id){
    //cout << ql << " " << qr << " " << ty << endl;
    if(ql > qr)return;
    if(l > qr || ql > r)return;
    else if(ql <= l && r <= qr){
        //cout << "a " << id << " " << ty << endl;
        if(!ty)st[id][ty].push({-k.f, {k.s, td[k.s][ty]}});
        else st[id][ty].push({k.f, {k.s, td[k.s][ty]}});
    }
    else {
        int mid = (l+r)>>1;
        _add(l, mid, ql, qr, k, ty, id<<1);
        _add(mid+1, r, ql, qr, k, ty, id<<1|1);
    }
}

int _query(int l, int r, int k, int id){
    //cout << l << " " << r << " " << id << endl;
    if(tot != K)return -1;
    int re = 0;
    while(!st[id][0].empty()){
        auto x = st[id][0].top();
        if(td[x.s.f][0] != x.s.s)st[id][0].pop();
        else break;
    }
    while(!st[id][1].empty()){
        auto x = st[id][1].top();
        if(td[x.s.f][1] != x.s.s)st[id][1].pop();
        else break;
    }
    if(!st[id][0].empty())re = max(re, posq[k] + st[id][0].top().f);
    if(!st[id][1].empty())re = max(re, st[id][1].top().f - posq[k]);
    if(l == r)return re;
    int mid = (l+r)>>1;
    if(k <= mid)re = max(re, _query(l, mid, k, id<<1));
    else re = max(re, _query(mid+1, r, k, id<<1|1));
    return re;
}

int query(int id){
    return _query(0, posq.size()-1, lower_bound(posq.begin(), posq.end(), L[id]) - posq.begin(), 1);    
}

void add(int ql, int qr, pair<int, int> k, int ty){
    _add(0, posq.size()-1, lower_bound(posq.begin(), posq.end(), ql) - posq.begin(), upper_bound(posq.begin(), posq.end(), qr) - posq.begin()-1, k, ty, 1);
}


void s_add(set<pair<int, int>>::iterator it, int ty){
    int id = it->s;
    if(ty == 0){
        if(next(it) == lmao[T[id]].end())add(X[id]+1, inf, {X[id], id}, 0);
        else add(X[id]+1, (next(it)->f+X[id])/2, {X[id], id}, 0);
    }
    else{
        if(it == lmao[T[id]].begin())add(0, X[id], {X[id], id}, 1);
        else add((prev(it)->f + X[id])/2+1, X[id], {X[id], id}, 1);
    }
}

void s_rmv(set<pair<int, int>>::iterator it, int ty){
    int id = it->s;
    td[id][ty]++;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> K >> q;
    vector<pair<int, pair<int, int>>> ev;
    for(int i = 0; i < n; i++){
        cin >> X[i] >> T[i] >> A[i] >> B[i];
        ev.push_back({A[i], {0, i}});
        ev.push_back({B[i]+1, {1, i}});
    }
    for(int i = 0; i < q; i++){
        cin >> L[i] >> Y[i];
        ev.push_back({Y[i], {2, i}});
        posq.push_back(L[i]);
    }
    sort(posq.begin(), posq.end());
    posq.erase(unique(posq.begin(), posq.end()), posq.end());
    sort(ev.begin(), ev.end());
    for(auto v: ev){
        //cout << v.s.f << " " << v.s.s << endl;
        int id = v.s.s;
        if(v.s.f == 0){
            auto it = lmao[T[id]].lower_bound({X[id], id});
            if(it != lmao[T[id]].end())s_rmv(it, 1);
            if(it != lmao[T[id]].begin())s_rmv(prev(it), 0);
            it = lmao[T[id]].insert({X[id], id}).f;
            s_add(it, 0);
            s_add(it, 1);
            if(it != lmao[T[id]].begin())s_add(prev(it), 0);
            if(next(it) != lmao[T[id]].end())s_add(next(it), 1);
            tot += (etype[T[id]]++)==0;
        }
        else if(v.s.f == 1){
            auto it = lmao[T[id]].find({X[id], id});
            assert(it != lmao[T[id]].end());
            s_rmv(it, 0);
            s_rmv(it, 1);
            if(it != lmao[T[id]].begin())s_rmv(prev(it), 0);
            if(next(it) != lmao[T[id]].end())s_rmv(next(it), 1);
            lmao[T[id]].erase(it);
            it = lmao[T[id]].lower_bound({X[id], id});
            if(it != lmao[T[id]].end())s_add(it, 1);
            if(it != lmao[T[id]].begin())s_add(prev(it), 0);
            tot -= (--etype[T[id]])==0;
        }
        else ans[id] = query(id);
    }
    for(int i = 0; i < q; i++)cout << ans[i] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 89660 KB Output is correct
2 Correct 46 ms 89616 KB Output is correct
3 Correct 48 ms 89564 KB Output is correct
4 Correct 47 ms 89556 KB Output is correct
5 Correct 48 ms 89604 KB Output is correct
6 Correct 50 ms 89784 KB Output is correct
7 Correct 57 ms 89628 KB Output is correct
8 Correct 46 ms 89728 KB Output is correct
9 Correct 45 ms 89724 KB Output is correct
10 Correct 46 ms 89756 KB Output is correct
11 Correct 47 ms 89736 KB Output is correct
12 Correct 45 ms 89668 KB Output is correct
13 Correct 49 ms 89672 KB Output is correct
14 Correct 46 ms 89596 KB Output is correct
15 Correct 46 ms 89700 KB Output is correct
16 Correct 52 ms 89744 KB Output is correct
17 Correct 52 ms 89684 KB Output is correct
18 Correct 50 ms 89764 KB Output is correct
19 Correct 46 ms 89668 KB Output is correct
20 Correct 46 ms 89756 KB Output is correct
21 Correct 45 ms 89676 KB Output is correct
22 Correct 47 ms 89676 KB Output is correct
23 Correct 45 ms 89708 KB Output is correct
24 Correct 46 ms 89676 KB Output is correct
25 Correct 46 ms 89692 KB Output is correct
26 Correct 47 ms 89676 KB Output is correct
27 Correct 46 ms 89704 KB Output is correct
28 Correct 46 ms 89728 KB Output is correct
29 Correct 48 ms 89720 KB Output is correct
30 Correct 54 ms 89696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 89660 KB Output is correct
2 Correct 46 ms 89616 KB Output is correct
3 Correct 48 ms 89564 KB Output is correct
4 Correct 47 ms 89556 KB Output is correct
5 Correct 48 ms 89604 KB Output is correct
6 Correct 50 ms 89784 KB Output is correct
7 Correct 57 ms 89628 KB Output is correct
8 Correct 46 ms 89728 KB Output is correct
9 Correct 45 ms 89724 KB Output is correct
10 Correct 46 ms 89756 KB Output is correct
11 Correct 47 ms 89736 KB Output is correct
12 Correct 45 ms 89668 KB Output is correct
13 Correct 49 ms 89672 KB Output is correct
14 Correct 46 ms 89596 KB Output is correct
15 Correct 46 ms 89700 KB Output is correct
16 Correct 52 ms 89744 KB Output is correct
17 Correct 52 ms 89684 KB Output is correct
18 Correct 50 ms 89764 KB Output is correct
19 Correct 46 ms 89668 KB Output is correct
20 Correct 46 ms 89756 KB Output is correct
21 Correct 45 ms 89676 KB Output is correct
22 Correct 47 ms 89676 KB Output is correct
23 Correct 45 ms 89708 KB Output is correct
24 Correct 46 ms 89676 KB Output is correct
25 Correct 46 ms 89692 KB Output is correct
26 Correct 47 ms 89676 KB Output is correct
27 Correct 46 ms 89704 KB Output is correct
28 Correct 46 ms 89728 KB Output is correct
29 Correct 48 ms 89720 KB Output is correct
30 Correct 54 ms 89696 KB Output is correct
31 Correct 1030 ms 142988 KB Output is correct
32 Correct 162 ms 95908 KB Output is correct
33 Correct 708 ms 117796 KB Output is correct
34 Correct 1108 ms 142676 KB Output is correct
35 Correct 1074 ms 134776 KB Output is correct
36 Correct 713 ms 117320 KB Output is correct
37 Correct 552 ms 120136 KB Output is correct
38 Correct 419 ms 110144 KB Output is correct
39 Correct 364 ms 112120 KB Output is correct
40 Correct 358 ms 109836 KB Output is correct
41 Correct 650 ms 113728 KB Output is correct
42 Correct 637 ms 121276 KB Output is correct
43 Correct 106 ms 97852 KB Output is correct
44 Correct 650 ms 113308 KB Output is correct
45 Correct 631 ms 108868 KB Output is correct
46 Correct 526 ms 107604 KB Output is correct
47 Correct 299 ms 112504 KB Output is correct
48 Correct 258 ms 111516 KB Output is correct
49 Correct 338 ms 115236 KB Output is correct
50 Correct 364 ms 122948 KB Output is correct
51 Correct 373 ms 113336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4621 ms 386032 KB Output is correct
2 Correct 3894 ms 228152 KB Output is correct
3 Correct 1719 ms 225556 KB Output is correct
4 Correct 3779 ms 345484 KB Output is correct
5 Correct 2579 ms 158248 KB Output is correct
6 Correct 3606 ms 203908 KB Output is correct
7 Correct 1835 ms 225280 KB Output is correct
8 Correct 3339 ms 335928 KB Output is correct
9 Correct 4627 ms 422480 KB Output is correct
10 Correct 4746 ms 361172 KB Output is correct
11 Correct 1935 ms 257836 KB Output is correct
12 Correct 2539 ms 346848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5030 ms 397516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 89660 KB Output is correct
2 Correct 46 ms 89616 KB Output is correct
3 Correct 48 ms 89564 KB Output is correct
4 Correct 47 ms 89556 KB Output is correct
5 Correct 48 ms 89604 KB Output is correct
6 Correct 50 ms 89784 KB Output is correct
7 Correct 57 ms 89628 KB Output is correct
8 Correct 46 ms 89728 KB Output is correct
9 Correct 45 ms 89724 KB Output is correct
10 Correct 46 ms 89756 KB Output is correct
11 Correct 47 ms 89736 KB Output is correct
12 Correct 45 ms 89668 KB Output is correct
13 Correct 49 ms 89672 KB Output is correct
14 Correct 46 ms 89596 KB Output is correct
15 Correct 46 ms 89700 KB Output is correct
16 Correct 52 ms 89744 KB Output is correct
17 Correct 52 ms 89684 KB Output is correct
18 Correct 50 ms 89764 KB Output is correct
19 Correct 46 ms 89668 KB Output is correct
20 Correct 46 ms 89756 KB Output is correct
21 Correct 45 ms 89676 KB Output is correct
22 Correct 47 ms 89676 KB Output is correct
23 Correct 45 ms 89708 KB Output is correct
24 Correct 46 ms 89676 KB Output is correct
25 Correct 46 ms 89692 KB Output is correct
26 Correct 47 ms 89676 KB Output is correct
27 Correct 46 ms 89704 KB Output is correct
28 Correct 46 ms 89728 KB Output is correct
29 Correct 48 ms 89720 KB Output is correct
30 Correct 54 ms 89696 KB Output is correct
31 Correct 1030 ms 142988 KB Output is correct
32 Correct 162 ms 95908 KB Output is correct
33 Correct 708 ms 117796 KB Output is correct
34 Correct 1108 ms 142676 KB Output is correct
35 Correct 1074 ms 134776 KB Output is correct
36 Correct 713 ms 117320 KB Output is correct
37 Correct 552 ms 120136 KB Output is correct
38 Correct 419 ms 110144 KB Output is correct
39 Correct 364 ms 112120 KB Output is correct
40 Correct 358 ms 109836 KB Output is correct
41 Correct 650 ms 113728 KB Output is correct
42 Correct 637 ms 121276 KB Output is correct
43 Correct 106 ms 97852 KB Output is correct
44 Correct 650 ms 113308 KB Output is correct
45 Correct 631 ms 108868 KB Output is correct
46 Correct 526 ms 107604 KB Output is correct
47 Correct 299 ms 112504 KB Output is correct
48 Correct 258 ms 111516 KB Output is correct
49 Correct 338 ms 115236 KB Output is correct
50 Correct 364 ms 122948 KB Output is correct
51 Correct 373 ms 113336 KB Output is correct
52 Correct 293 ms 112240 KB Output is correct
53 Correct 270 ms 110368 KB Output is correct
54 Correct 561 ms 135144 KB Output is correct
55 Correct 518 ms 117432 KB Output is correct
56 Correct 493 ms 116844 KB Output is correct
57 Correct 656 ms 118064 KB Output is correct
58 Correct 548 ms 120396 KB Output is correct
59 Correct 474 ms 119508 KB Output is correct
60 Correct 633 ms 122020 KB Output is correct
61 Correct 104 ms 98556 KB Output is correct
62 Correct 316 ms 112464 KB Output is correct
63 Correct 480 ms 125668 KB Output is correct
64 Correct 558 ms 129904 KB Output is correct
65 Correct 657 ms 132352 KB Output is correct
66 Correct 683 ms 118844 KB Output is correct
67 Correct 195 ms 106556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 89660 KB Output is correct
2 Correct 46 ms 89616 KB Output is correct
3 Correct 48 ms 89564 KB Output is correct
4 Correct 47 ms 89556 KB Output is correct
5 Correct 48 ms 89604 KB Output is correct
6 Correct 50 ms 89784 KB Output is correct
7 Correct 57 ms 89628 KB Output is correct
8 Correct 46 ms 89728 KB Output is correct
9 Correct 45 ms 89724 KB Output is correct
10 Correct 46 ms 89756 KB Output is correct
11 Correct 47 ms 89736 KB Output is correct
12 Correct 45 ms 89668 KB Output is correct
13 Correct 49 ms 89672 KB Output is correct
14 Correct 46 ms 89596 KB Output is correct
15 Correct 46 ms 89700 KB Output is correct
16 Correct 52 ms 89744 KB Output is correct
17 Correct 52 ms 89684 KB Output is correct
18 Correct 50 ms 89764 KB Output is correct
19 Correct 46 ms 89668 KB Output is correct
20 Correct 46 ms 89756 KB Output is correct
21 Correct 45 ms 89676 KB Output is correct
22 Correct 47 ms 89676 KB Output is correct
23 Correct 45 ms 89708 KB Output is correct
24 Correct 46 ms 89676 KB Output is correct
25 Correct 46 ms 89692 KB Output is correct
26 Correct 47 ms 89676 KB Output is correct
27 Correct 46 ms 89704 KB Output is correct
28 Correct 46 ms 89728 KB Output is correct
29 Correct 48 ms 89720 KB Output is correct
30 Correct 54 ms 89696 KB Output is correct
31 Correct 1030 ms 142988 KB Output is correct
32 Correct 162 ms 95908 KB Output is correct
33 Correct 708 ms 117796 KB Output is correct
34 Correct 1108 ms 142676 KB Output is correct
35 Correct 1074 ms 134776 KB Output is correct
36 Correct 713 ms 117320 KB Output is correct
37 Correct 552 ms 120136 KB Output is correct
38 Correct 419 ms 110144 KB Output is correct
39 Correct 364 ms 112120 KB Output is correct
40 Correct 358 ms 109836 KB Output is correct
41 Correct 650 ms 113728 KB Output is correct
42 Correct 637 ms 121276 KB Output is correct
43 Correct 106 ms 97852 KB Output is correct
44 Correct 650 ms 113308 KB Output is correct
45 Correct 631 ms 108868 KB Output is correct
46 Correct 526 ms 107604 KB Output is correct
47 Correct 299 ms 112504 KB Output is correct
48 Correct 258 ms 111516 KB Output is correct
49 Correct 338 ms 115236 KB Output is correct
50 Correct 364 ms 122948 KB Output is correct
51 Correct 373 ms 113336 KB Output is correct
52 Correct 4621 ms 386032 KB Output is correct
53 Correct 3894 ms 228152 KB Output is correct
54 Correct 1719 ms 225556 KB Output is correct
55 Correct 3779 ms 345484 KB Output is correct
56 Correct 2579 ms 158248 KB Output is correct
57 Correct 3606 ms 203908 KB Output is correct
58 Correct 1835 ms 225280 KB Output is correct
59 Correct 3339 ms 335928 KB Output is correct
60 Correct 4627 ms 422480 KB Output is correct
61 Correct 4746 ms 361172 KB Output is correct
62 Correct 1935 ms 257836 KB Output is correct
63 Correct 2539 ms 346848 KB Output is correct
64 Execution timed out 5030 ms 397516 KB Time limit exceeded
65 Halted 0 ms 0 KB -