제출 #1355704

#제출 시각아이디문제언어결과실행 시간메모리
1355704bakhtiyarnSegments (IZhO18_segments)C++20
0 / 100
45 ms43448 KiB
#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;

template <typename T>
using o_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MX = 2e9;

const int N = 5e3+5;
array<int, 2> id[N];

const int N2 = N*34;
int lef[N2], rig[N2], C = 2;
o_set<int> mst[N2], mst2[N2];

void update(int u, int l, int r, int x, int v, int t){
    if(t == 1) {
        mst[u].insert(v);
        mst2[u].insert(v-x+1);
    }
    else {
        mst[u].erase(mst[u].lower_bound(v-1));
        mst2[u].erase(mst2[u].lower_bound(v-x+1-1));
    }

    if(l == r) return;

    int m = (l+r)/2;
    if(l <= x and m >= x) {
        if(!lef[u]) lef[u] = C++;
        update(lef[u], l, m, x, v, t);
    }
    else {
        if(!rig[u]) rig[u] = C++;
        update(rig[u], m+1, r, x, v, t);
    }
}

bool cross(int l1, int r1, int l2, int r2){
    if(r1 < l2) return false;
    if(r2 < l1) return false;
    return true;
}

int get(int u, int l, int r, int x, int y, int v, int t){
    if(y < l or x > r) return 0;
    if(x <= l and y >= r){
        if(!t){
            auto it = mst[u].lower_bound(v-1);
            if(it == mst[u].end()) return 0;
            
            int idx = mst[u].order_of_key(*it);
            return mst[u].size() - idx;
        } else {
            auto it = mst2[u].lower_bound(v-1);
            if(it == mst2[u].end()) return 0;
            
            int idx = mst2[u].order_of_key(*it);
            return mst2[u].size() - idx;
        }
    }

    int m = (l+r)/2;
    int a1 = 0, a2 = 0;
    if(cross(l, m, x, y)) {
        if(!lef[u]) lef[u] = C++;
        a1 = get(lef[u], l, m, x, y, v, t);
    }
    if(cross(m+1, r, x, y)){
        if(!rig[u]) rig[u] = C++;
        a2 = get(rig[u], m+1, r, x, y, v, t);
    }
    return a1+a2;
}

void add(int l, int r){
    update(1, 1, MX, l, r, 1);
}
void remove(int l, int r){
    update(1, 1, MX, l, r, 0);
}

int cnt(int l, int r){
    return get(1, 1, MX, 1, l, r, 0);
}

int cnt_sz(int l, int r, int k){
    return get(1, 1, MX, l, r, k, 1);
}

// for(int i=1; i<=n; i++)
void solve(){
    int q, t; cin >> q >> t;
    int ID = 1;
    
    int last = 0;
    while(q--){
        int tip, l, r, k; cin >> tip;
        
        if(tip == 1){
            int a, b; cin >> a >> b;
            l = a ^ (t * last);
            r = b ^ (t * last);
            if(l > r) swap(l, r);
            add(l, r);
            id[ID++] = {l, r};
            continue;
        }
        if(tip == 2){
            int rem; cin >> rem;
            l = id[rem][0];
            r = id[rem][1];
            remove(l, r);
            continue;
        }

        int a, b; cin >> a >> b >> k;
        l = a ^ (t * last);
        r = b ^ (t * last);
        if(l > r) swap(l, r);

        if(r-l+1 < k) {
            last = 0;
            cout << last << '\n';
            continue;
        }
        last = 0;

        last = cnt(l-1, l+k-1) + cnt_sz(l, r-k+1, k);
        cout << last << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    solve();
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…