답안 #684922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684922 2023-01-22T20:50:39 Z KiriLL1ca Segments (IZhO18_segments) C++17
16 / 100
573 ms 6952 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();
        return make_pair(l, r) < make_pair(x.l, 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 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 573 ms 4164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 347 ms 4804 KB Output is correct
2 Correct 343 ms 4740 KB Output is correct
3 Correct 375 ms 4836 KB Output is correct
4 Correct 339 ms 4628 KB Output is correct
5 Correct 532 ms 5236 KB Output is correct
6 Correct 506 ms 4776 KB Output is correct
7 Correct 524 ms 4932 KB Output is correct
8 Correct 505 ms 6316 KB Output is correct
9 Correct 476 ms 6344 KB Output is correct
10 Correct 441 ms 6088 KB Output is correct
11 Correct 344 ms 6952 KB Output is correct
12 Correct 420 ms 6264 KB Output is correct
13 Correct 397 ms 6252 KB Output is correct
14 Correct 352 ms 5932 KB Output is correct
15 Correct 383 ms 6176 KB Output is correct
16 Correct 335 ms 5584 KB Output is correct
17 Correct 448 ms 4272 KB Output is correct
18 Correct 568 ms 4188 KB Output is correct
19 Correct 536 ms 4252 KB Output is correct
20 Correct 453 ms 4260 KB Output is correct
21 Correct 367 ms 6708 KB Output is correct
22 Correct 397 ms 6028 KB Output is correct
23 Correct 404 ms 6348 KB Output is correct
24 Correct 387 ms 6028 KB Output is correct
25 Correct 354 ms 4684 KB Output is correct
26 Correct 326 ms 4708 KB Output is correct
27 Correct 327 ms 4696 KB Output is correct
28 Correct 338 ms 4680 KB Output is correct
29 Correct 418 ms 6116 KB Output is correct
30 Correct 418 ms 6196 KB Output is correct
31 Correct 484 ms 6576 KB Output is correct
32 Correct 445 ms 6152 KB Output is correct
33 Correct 399 ms 6368 KB Output is correct
34 Correct 340 ms 5560 KB Output is correct
35 Correct 370 ms 6220 KB Output is correct
36 Correct 412 ms 6448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 422 ms 4744 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 468 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 468 KB Output isn't correct
4 Halted 0 ms 0 KB -