답안 #988463

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988463 2024-05-24T18:06:53 Z 876pol 새 집 (APIO18_new_home) C++17
5 / 100
5000 ms 1048576 KB
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = int;
using pll = pair<ll, ll>;
template <class T>
using vec = vector<T>;
template <class T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, s, e) for (ll i = (ll)s; i < e; i++)
#define CFOR(i, s, e) for (ll i = (ll)s; i <= e; i++)
#define TRAV(e, a) for (const auto &e : a)
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << "ln" << __LINE__ << ": " << #x << " = " << x << endl;

template <class T, class = decay_t<decltype(*begin(declval<T>()))>,
          class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &out, const T &obj) {
    out << "[";
    for (auto it = obj.begin(); it != obj.end(); it++) {
        out << &", "[2 * (it == obj.begin())] << *it;
    }
    return out << "]";
}

template <class K, class V>
ostream &operator<<(ostream &out, const pair<K, V> &obj) {
    return out << "(" << obj.first << ", " << obj.second << ")";
}

struct query {
    ll op, x, t, y, id;
};

ostream &operator<<(ostream &out, const query &obj) {
    return out << vec<ll>{obj.op, obj.x, obj.t, obj.y, obj.id};
}

const ll MXL = 27000000;
const ll SZ = 450, NB = 1;
bitset<SZ> dat[MXL];
ll lc[MXL], rc[MXL], roots[NB];
ll curr = NB;

void push(ll v, ll tl, ll tr) {
    if (tl == tr) return;
    if (lc[v] == -1) lc[v] = curr++;
    if (rc[v] == -1) rc[v] = curr++;
}

void toggle(ll v, ll tl, ll tr, ll ind, ll t) {
    push(v, tl, tr);
    if (tl == tr) {
        dat[v][t] = !dat[v][t];
    } else {
        ll tm = (tl + tr) / 2;
        if (ind <= tm) {
            toggle(lc[v], tl, tm, ind, t);
        } else {
            toggle(rc[v], tm + 1, tr, ind, t);
        }
        dat[v] = dat[lc[v]] | dat[rc[v]];
    }
}

bitset<SZ> qu(ll v, ll tl, ll tr, ll l, ll r) {
    push(v, tl, tr);
    if (r < tl || tr < l) return bitset<SZ>();
    if (l <= tl && tr <= r) return dat[v];
    ll tm = (tl + tr) / 2;
    return qu(lc[v], tl, tm, l, r) | qu(rc[v], tm + 1, tr, l, r);
}

int main() {
    memset(lc, -1, sizeof(lc));
    memset(rc, -1, sizeof(rc));
    FOR(i, 0, NB) roots[i] = i;
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll n, k, q;
    cin >> n >> k >> q;
    vec<query> queries;
    queries.reserve(2 * n + q);
    FOR(i, 0, n) {
        ll x, t, a, b;
        cin >> x >> t >> a >> b;
        queries.push_back({0, x, t, a, i});
        queries.push_back({1, x, t, b + 1, i});
    }
    FOR(i, 0, q) {
        ll l, y;
        cin >> l >> y;
        queries.push_back({2, l, -1, y, i});
    }
    sort(all(queries), [&](const query &o1, const query &o2) {
        return (o1.y == o2.y) ? o1.op < o2.op : o1.y < o2.y;
    });
    map<pll, ll> cnt;
    vec<ll> ans(q);
    TRAV(e, queries) {
        if (e.op == 0) {
            if (cnt[{e.x, e.t}]++ == 0) {
                toggle(0, 1, 1e8, e.x, e.t);
            }
        } else if (e.op == 1) {
            if (--cnt[{e.x, e.t}] == 0) {
                toggle(0, 1, 1e8, e.x, e.t);
            }
        } else if (e.op == 2) {
            ll l = 0, r = 1e8, best = -1;
            while (l <= r) {
                ll m = (l + r) / 2;
                if (qu(0, 1, 1e8, e.x - m, e.x + m).count() == k) {
                    best = m;
                    r = m - 1;
                } else {
                    l = m + 1;
                }
            }
            ans[e.id] = best;
        }
    }
    TRAV(e, ans) cout << e << "\n";
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:121:61: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
  121 |                 if (qu(0, 1, 1e8, e.x - m, e.x + m).count() == k) {
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 211792 KB Output is correct
2 Correct 98 ms 211872 KB Output is correct
3 Correct 104 ms 211792 KB Output is correct
4 Correct 92 ms 212056 KB Output is correct
5 Correct 99 ms 211800 KB Output is correct
6 Correct 99 ms 216428 KB Output is correct
7 Correct 83 ms 214356 KB Output is correct
8 Correct 84 ms 213728 KB Output is correct
9 Correct 81 ms 213592 KB Output is correct
10 Correct 101 ms 215124 KB Output is correct
11 Correct 88 ms 213984 KB Output is correct
12 Correct 91 ms 216916 KB Output is correct
13 Correct 89 ms 214152 KB Output is correct
14 Correct 90 ms 215580 KB Output is correct
15 Correct 89 ms 214608 KB Output is correct
16 Correct 91 ms 214300 KB Output is correct
17 Correct 92 ms 215396 KB Output is correct
18 Correct 88 ms 214432 KB Output is correct
19 Correct 89 ms 213840 KB Output is correct
20 Correct 85 ms 214680 KB Output is correct
21 Correct 87 ms 211908 KB Output is correct
22 Correct 85 ms 213332 KB Output is correct
23 Correct 88 ms 213840 KB Output is correct
24 Correct 93 ms 214104 KB Output is correct
25 Correct 87 ms 214588 KB Output is correct
26 Correct 90 ms 216400 KB Output is correct
27 Correct 86 ms 211796 KB Output is correct
28 Correct 89 ms 215588 KB Output is correct
29 Correct 89 ms 215636 KB Output is correct
30 Correct 90 ms 215684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 211792 KB Output is correct
2 Correct 98 ms 211872 KB Output is correct
3 Correct 104 ms 211792 KB Output is correct
4 Correct 92 ms 212056 KB Output is correct
5 Correct 99 ms 211800 KB Output is correct
6 Correct 99 ms 216428 KB Output is correct
7 Correct 83 ms 214356 KB Output is correct
8 Correct 84 ms 213728 KB Output is correct
9 Correct 81 ms 213592 KB Output is correct
10 Correct 101 ms 215124 KB Output is correct
11 Correct 88 ms 213984 KB Output is correct
12 Correct 91 ms 216916 KB Output is correct
13 Correct 89 ms 214152 KB Output is correct
14 Correct 90 ms 215580 KB Output is correct
15 Correct 89 ms 214608 KB Output is correct
16 Correct 91 ms 214300 KB Output is correct
17 Correct 92 ms 215396 KB Output is correct
18 Correct 88 ms 214432 KB Output is correct
19 Correct 89 ms 213840 KB Output is correct
20 Correct 85 ms 214680 KB Output is correct
21 Correct 87 ms 211908 KB Output is correct
22 Correct 85 ms 213332 KB Output is correct
23 Correct 88 ms 213840 KB Output is correct
24 Correct 93 ms 214104 KB Output is correct
25 Correct 87 ms 214588 KB Output is correct
26 Correct 90 ms 216400 KB Output is correct
27 Correct 86 ms 211796 KB Output is correct
28 Correct 89 ms 215588 KB Output is correct
29 Correct 89 ms 215636 KB Output is correct
30 Correct 90 ms 215684 KB Output is correct
31 Execution timed out 6137 ms 1048576 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3869 ms 574248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3972 ms 580488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 211792 KB Output is correct
2 Correct 98 ms 211872 KB Output is correct
3 Correct 104 ms 211792 KB Output is correct
4 Correct 92 ms 212056 KB Output is correct
5 Correct 99 ms 211800 KB Output is correct
6 Correct 99 ms 216428 KB Output is correct
7 Correct 83 ms 214356 KB Output is correct
8 Correct 84 ms 213728 KB Output is correct
9 Correct 81 ms 213592 KB Output is correct
10 Correct 101 ms 215124 KB Output is correct
11 Correct 88 ms 213984 KB Output is correct
12 Correct 91 ms 216916 KB Output is correct
13 Correct 89 ms 214152 KB Output is correct
14 Correct 90 ms 215580 KB Output is correct
15 Correct 89 ms 214608 KB Output is correct
16 Correct 91 ms 214300 KB Output is correct
17 Correct 92 ms 215396 KB Output is correct
18 Correct 88 ms 214432 KB Output is correct
19 Correct 89 ms 213840 KB Output is correct
20 Correct 85 ms 214680 KB Output is correct
21 Correct 87 ms 211908 KB Output is correct
22 Correct 85 ms 213332 KB Output is correct
23 Correct 88 ms 213840 KB Output is correct
24 Correct 93 ms 214104 KB Output is correct
25 Correct 87 ms 214588 KB Output is correct
26 Correct 90 ms 216400 KB Output is correct
27 Correct 86 ms 211796 KB Output is correct
28 Correct 89 ms 215588 KB Output is correct
29 Correct 89 ms 215636 KB Output is correct
30 Correct 90 ms 215684 KB Output is correct
31 Execution timed out 6137 ms 1048576 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 211792 KB Output is correct
2 Correct 98 ms 211872 KB Output is correct
3 Correct 104 ms 211792 KB Output is correct
4 Correct 92 ms 212056 KB Output is correct
5 Correct 99 ms 211800 KB Output is correct
6 Correct 99 ms 216428 KB Output is correct
7 Correct 83 ms 214356 KB Output is correct
8 Correct 84 ms 213728 KB Output is correct
9 Correct 81 ms 213592 KB Output is correct
10 Correct 101 ms 215124 KB Output is correct
11 Correct 88 ms 213984 KB Output is correct
12 Correct 91 ms 216916 KB Output is correct
13 Correct 89 ms 214152 KB Output is correct
14 Correct 90 ms 215580 KB Output is correct
15 Correct 89 ms 214608 KB Output is correct
16 Correct 91 ms 214300 KB Output is correct
17 Correct 92 ms 215396 KB Output is correct
18 Correct 88 ms 214432 KB Output is correct
19 Correct 89 ms 213840 KB Output is correct
20 Correct 85 ms 214680 KB Output is correct
21 Correct 87 ms 211908 KB Output is correct
22 Correct 85 ms 213332 KB Output is correct
23 Correct 88 ms 213840 KB Output is correct
24 Correct 93 ms 214104 KB Output is correct
25 Correct 87 ms 214588 KB Output is correct
26 Correct 90 ms 216400 KB Output is correct
27 Correct 86 ms 211796 KB Output is correct
28 Correct 89 ms 215588 KB Output is correct
29 Correct 89 ms 215636 KB Output is correct
30 Correct 90 ms 215684 KB Output is correct
31 Execution timed out 6137 ms 1048576 KB Time limit exceeded
32 Halted 0 ms 0 KB -