Submission #1033441

# Submission time Handle Problem Language Result Execution time Memory
1033441 2024-07-24T20:32:51 Z _8_8_ New Home (APIO18_new_home) C++17
5 / 100
5000 ms 120036 KB
#include <bits/stdc++.h>
 
using namespace std;
    
typedef long long ll;
const int  N = 1e6 + 21, MOD = (int)1e9+7;
 
int n,k,q,x[N],t[N],a[N],b[N];
struct Q{
    int tp,y,x,v,id;
};
multiset<int> st[N];
vector<Q> s;
bool cmp(Q l,Q r){
    if(l.y != r.y)
        return l.y < r.y;
    return l.tp < r.tp;
}
multiset<pair<int,int>> cur;
void add(int i,int x){
    // cerr << (int)st[i].size() << "x\n";
    auto it = st[i].lower_bound(x);
    int R = *it,L;
    --it;
    L =*it;
    cur.insert({L+1,x - 1});
    cur.insert({x + 1,R - 1});
    cur.erase(cur.find({L + 1,R - 1}));
    st[i].insert(x);
    // cerr << (int)st[i].size() << "x\n";
}
void del(int i,int x){
    auto it = st[i].lower_bound(x);
    it++;
    int R = *it,L;
    --it;--it;
    L =*it;
    cur.erase(cur.find({L + 1,x - 1}));
    cur.erase(cur.find({x + 1,R - 1}));
    cur.insert({L + 1,R - 1});
    st[i].erase(st[i].find(x));
}
int res[N];
bool ok(int l,int r){
    for(auto [L,R]:cur){
        if(L <= l && R >= r) return false;
    }
    return true;
}
void test() {
    cin >> n >> k >> q;
    for(int i = 1;i <= n;++i){
        cin >> x[i] >> t[i] >> a[i] >> b[i];
        Q f,_f;
        f.y = a[i];f.tp = 0;f.v = t[i];f.x = x[i];
        s.push_back(f);
        _f.y = b[i];_f.tp = 2;_f.v = t[i];_f.x = x[i];
        s.push_back(_f);
    }
    for(int i = 1;i <= q;i++){
        int l,y;
        cin >> l >> y;
        Q a;
        a.tp = 1;
        a.id = i;
        a.x = l;
        a.y = y;
        s.push_back(a);
    }
    sort(s.begin(),s.end(),cmp);
    const int inf = (int)1e9;
    for(int i = 1;i <= k;i++) {
        st[i].insert(0);
        st[i].insert((int)1e9 + 1);
        cur.insert({1,inf});
    }
    for(Q d:s) {
        if(d.tp == 0) {
            // cout << d.v << ' ' << d.x << '\n';
            add(d.v,d.x);
        }else if(d.tp == 2) {
            del(d.v,d.x);
        }else{
            if(cur.find({1,(int)1e9}) != cur.end()) {
                res[d.id] = -1;
                continue;
            }
            // continue;
            int l = -1,r = (int)1e9;
            while(r - l > 1){
                int mid = (l + r) >> 1;
                if(ok(max(1,d.x - mid),d.x + mid)){
                    r = mid;
                }else{
                    l = mid;
                }
            }
            res[d.id] = r;
        }
    }
    for(int i = 1;i <= q;++i) {
        cout << res[i] << '\n';
    }
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--) {
        test();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47448 KB Output is correct
2 Correct 21 ms 47452 KB Output is correct
3 Correct 20 ms 47448 KB Output is correct
4 Correct 20 ms 47464 KB Output is correct
5 Correct 25 ms 47452 KB Output is correct
6 Correct 24 ms 47560 KB Output is correct
7 Correct 21 ms 47452 KB Output is correct
8 Correct 22 ms 47520 KB Output is correct
9 Correct 23 ms 47448 KB Output is correct
10 Correct 27 ms 47448 KB Output is correct
11 Correct 27 ms 47452 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 21 ms 47448 KB Output is correct
14 Correct 21 ms 47360 KB Output is correct
15 Correct 29 ms 47452 KB Output is correct
16 Correct 32 ms 47452 KB Output is correct
17 Correct 31 ms 47452 KB Output is correct
18 Correct 27 ms 47452 KB Output is correct
19 Correct 30 ms 47536 KB Output is correct
20 Correct 24 ms 47452 KB Output is correct
21 Correct 43 ms 47452 KB Output is correct
22 Correct 32 ms 47452 KB Output is correct
23 Correct 24 ms 47448 KB Output is correct
24 Correct 26 ms 47452 KB Output is correct
25 Correct 26 ms 47532 KB Output is correct
26 Correct 20 ms 47404 KB Output is correct
27 Correct 23 ms 47448 KB Output is correct
28 Correct 20 ms 47448 KB Output is correct
29 Correct 21 ms 47452 KB Output is correct
30 Correct 20 ms 47448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47448 KB Output is correct
2 Correct 21 ms 47452 KB Output is correct
3 Correct 20 ms 47448 KB Output is correct
4 Correct 20 ms 47464 KB Output is correct
5 Correct 25 ms 47452 KB Output is correct
6 Correct 24 ms 47560 KB Output is correct
7 Correct 21 ms 47452 KB Output is correct
8 Correct 22 ms 47520 KB Output is correct
9 Correct 23 ms 47448 KB Output is correct
10 Correct 27 ms 47448 KB Output is correct
11 Correct 27 ms 47452 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 21 ms 47448 KB Output is correct
14 Correct 21 ms 47360 KB Output is correct
15 Correct 29 ms 47452 KB Output is correct
16 Correct 32 ms 47452 KB Output is correct
17 Correct 31 ms 47452 KB Output is correct
18 Correct 27 ms 47452 KB Output is correct
19 Correct 30 ms 47536 KB Output is correct
20 Correct 24 ms 47452 KB Output is correct
21 Correct 43 ms 47452 KB Output is correct
22 Correct 32 ms 47452 KB Output is correct
23 Correct 24 ms 47448 KB Output is correct
24 Correct 26 ms 47452 KB Output is correct
25 Correct 26 ms 47532 KB Output is correct
26 Correct 20 ms 47404 KB Output is correct
27 Correct 23 ms 47448 KB Output is correct
28 Correct 20 ms 47448 KB Output is correct
29 Correct 21 ms 47452 KB Output is correct
30 Correct 20 ms 47448 KB Output is correct
31 Execution timed out 5029 ms 55992 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5042 ms 120036 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5104 ms 113756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47448 KB Output is correct
2 Correct 21 ms 47452 KB Output is correct
3 Correct 20 ms 47448 KB Output is correct
4 Correct 20 ms 47464 KB Output is correct
5 Correct 25 ms 47452 KB Output is correct
6 Correct 24 ms 47560 KB Output is correct
7 Correct 21 ms 47452 KB Output is correct
8 Correct 22 ms 47520 KB Output is correct
9 Correct 23 ms 47448 KB Output is correct
10 Correct 27 ms 47448 KB Output is correct
11 Correct 27 ms 47452 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 21 ms 47448 KB Output is correct
14 Correct 21 ms 47360 KB Output is correct
15 Correct 29 ms 47452 KB Output is correct
16 Correct 32 ms 47452 KB Output is correct
17 Correct 31 ms 47452 KB Output is correct
18 Correct 27 ms 47452 KB Output is correct
19 Correct 30 ms 47536 KB Output is correct
20 Correct 24 ms 47452 KB Output is correct
21 Correct 43 ms 47452 KB Output is correct
22 Correct 32 ms 47452 KB Output is correct
23 Correct 24 ms 47448 KB Output is correct
24 Correct 26 ms 47452 KB Output is correct
25 Correct 26 ms 47532 KB Output is correct
26 Correct 20 ms 47404 KB Output is correct
27 Correct 23 ms 47448 KB Output is correct
28 Correct 20 ms 47448 KB Output is correct
29 Correct 21 ms 47452 KB Output is correct
30 Correct 20 ms 47448 KB Output is correct
31 Execution timed out 5029 ms 55992 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47448 KB Output is correct
2 Correct 21 ms 47452 KB Output is correct
3 Correct 20 ms 47448 KB Output is correct
4 Correct 20 ms 47464 KB Output is correct
5 Correct 25 ms 47452 KB Output is correct
6 Correct 24 ms 47560 KB Output is correct
7 Correct 21 ms 47452 KB Output is correct
8 Correct 22 ms 47520 KB Output is correct
9 Correct 23 ms 47448 KB Output is correct
10 Correct 27 ms 47448 KB Output is correct
11 Correct 27 ms 47452 KB Output is correct
12 Correct 23 ms 47452 KB Output is correct
13 Correct 21 ms 47448 KB Output is correct
14 Correct 21 ms 47360 KB Output is correct
15 Correct 29 ms 47452 KB Output is correct
16 Correct 32 ms 47452 KB Output is correct
17 Correct 31 ms 47452 KB Output is correct
18 Correct 27 ms 47452 KB Output is correct
19 Correct 30 ms 47536 KB Output is correct
20 Correct 24 ms 47452 KB Output is correct
21 Correct 43 ms 47452 KB Output is correct
22 Correct 32 ms 47452 KB Output is correct
23 Correct 24 ms 47448 KB Output is correct
24 Correct 26 ms 47452 KB Output is correct
25 Correct 26 ms 47532 KB Output is correct
26 Correct 20 ms 47404 KB Output is correct
27 Correct 23 ms 47448 KB Output is correct
28 Correct 20 ms 47448 KB Output is correct
29 Correct 21 ms 47452 KB Output is correct
30 Correct 20 ms 47448 KB Output is correct
31 Execution timed out 5029 ms 55992 KB Time limit exceeded
32 Halted 0 ms 0 KB -