답안 #684923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684923 2023-01-22T20:52:04 Z KiriLL1ca Segments (IZhO18_segments) C++17
16 / 100
551 ms 7056 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
#define pb push_back
#define fr first
#define sc second
#define pw(x) (1ll << x)

using namespace std;
using namespace __gnu_pbds;

#define int long long

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef unsigned long long ull;

template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }

template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

const int N = 2e5 + 100;
const int buben = 1000;
const int nb = N / buben + 2;

struct segment {
    int l, r;
    segment (int l = 0, int r = 0) : l(l), r(r) {}
    inline int len () { return r - l + 1; }

    inline bool operator < (segment &x) {
        if (len() != x.len()) return len() < x.len();
        if (l != x.l) return l < x.l;
        return r < x.r;
    }
};

inline int inter (const segment &a, const segment &b) {
    return max(0ll, min(a.r, b.r) - max(a.l, b.l) + 1);
}

struct sex {
    vector <segment> buf;
    vector <segment> ful;
    vector <int> lb[nb], rb[nb];

    inline void add (int l, int r) {
        segment seg (l, r); buf.pb(seg);

        if (sz(buf) == buben) {
            sort(all(buf));

            vector <segment> mt; mt.reserve(sz(ful) + sz(buf));
            int uk1 = 0, uk2 = 0;
            while (uk1 < sz(ful) || uk2 < sz(buf)) {
                if (uk1 == sz(ful)) mt.pb(buf[uk2++]);
                else if (uk2 == sz(buf)) mt.pb(ful[uk1++]);
                else if (ful[uk1] < buf[uk2]) mt.pb(ful[uk1++]);
                else mt.pb(buf[uk2++]);
            }
            ful.swap(mt); buf.clear();

            for (int i = 0; i < nb; ++i) lb[i].clear(), rb[i].clear();
            for (int i = 0; i < sz(ful); ++i) {
                lb[i / buben].pb(ful[i].l);
                rb[i / buben].pb(ful[i].r);
            }
            for (int i = 0; i < nb; ++i) {
                sort(all(lb[i]));
                sort(all(rb[i]));
            }
        }
    }

    inline int get (int l, int r, int k) {
        int res = 0;
        segment seg (l, r);

        for (segment x : buf) res += inter(x, seg) >= k;

        for (int L = 0, i = 0; L < sz(ful); L += buben, ++i) {
            int R = min(sz(ful), L + buben) - 1;
            if (ful[L].len() >= k) {
                res += R - L + 1;
                res -= sz(lb[i]) - (lower_bound(all(lb[i]), r - k + 2) - lb[i].begin());
                res -= upper_bound(all(rb[i]), l + k - 2) - rb[i].begin();
            }
            else if (ful[R].len() >= k) {
                for (int j = L; j <= R; ++j) res += inter(ful[j], seg);
            }
        }

        return res;
    }
};

inline void solve () {
    int q, T; cin >> q >> T;
    vector <pii> seg (q); int uk = 0;
    int lst = 0;
    sex in, out;
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int l, r; cin >> l >> r;
            l = (l ^ (T * lst)), r = (r ^ (T * lst)); if (l > r) swap(l, r);
            seg[uk++] = {l, r};
            in.add(l, r);
        }
        if (t == 2) {
            int id; cin >> id; --id;
            auto [l, r] = seg[id];
            out.add(l, r);
        }
        if (t == 3) {
            int l, r, k; cin >> l >> r >> k;
            l = (l ^ (T * lst)), r = (r ^ (T * lst)); if (l > r) swap(l, r);
            lst = in.get(l, r, k) - out.get(l, r, k);
            cout << lst << endl;
        }
    }
}

signed main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // LOCAL

    int t = 1; // cin >> t;
    while (t--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 8 ms 508 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 551 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 359 ms 4620 KB Output is correct
2 Correct 340 ms 4564 KB Output is correct
3 Correct 354 ms 4684 KB Output is correct
4 Correct 349 ms 4652 KB Output is correct
5 Correct 533 ms 5260 KB Output is correct
6 Correct 548 ms 4760 KB Output is correct
7 Correct 524 ms 4992 KB Output is correct
8 Correct 528 ms 6388 KB Output is correct
9 Correct 528 ms 6464 KB Output is correct
10 Correct 436 ms 6212 KB Output is correct
11 Correct 351 ms 7056 KB Output is correct
12 Correct 436 ms 6192 KB Output is correct
13 Correct 412 ms 6204 KB Output is correct
14 Correct 343 ms 5876 KB Output is correct
15 Correct 381 ms 6152 KB Output is correct
16 Correct 323 ms 5680 KB Output is correct
17 Correct 469 ms 4220 KB Output is correct
18 Correct 533 ms 4204 KB Output is correct
19 Correct 537 ms 4260 KB Output is correct
20 Correct 487 ms 4276 KB Output is correct
21 Correct 367 ms 6720 KB Output is correct
22 Correct 396 ms 6068 KB Output is correct
23 Correct 416 ms 6264 KB Output is correct
24 Correct 400 ms 6152 KB Output is correct
25 Correct 345 ms 4628 KB Output is correct
26 Correct 358 ms 4676 KB Output is correct
27 Correct 351 ms 4732 KB Output is correct
28 Correct 335 ms 4620 KB Output is correct
29 Correct 439 ms 6024 KB Output is correct
30 Correct 426 ms 6180 KB Output is correct
31 Correct 492 ms 6400 KB Output is correct
32 Correct 441 ms 6164 KB Output is correct
33 Correct 408 ms 6380 KB Output is correct
34 Correct 336 ms 5700 KB Output is correct
35 Correct 377 ms 6372 KB Output is correct
36 Correct 431 ms 6472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 441 ms 4772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 8 ms 508 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 8 ms 508 KB Output isn't correct
4 Halted 0 ms 0 KB -