Submission #879314

# Submission time Handle Problem Language Result Execution time Memory
879314 2023-11-27T06:36:36 Z TheSahib Segments (IZhO18_segments) C++17
0 / 100
319 ms 38516 KB
#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()

using namespace std;

const int oo = 1e9 + 9;
const int MAX = 2e5 + 5;
const int BLOCK = 500;

int n;
multiset<pii> st;
int nxt = 0;
pii arr[MAX];
vector<pii> v;

struct DATA{
    vector<int> a;
    vector<int> b;
};

DATA combine(DATA& a, DATA& b){
    DATA c;
    int d = a.a.size() + a.b.size();
    c.a.resize(d);
    c.b.resize(d);
    merge(all(a.a), all(b.a), c.a.begin());
    merge(all(a.b), all(b.b), c.b.begin());
    return c;   
}

DATA tree[MAX * 2];

void build(int node, int l, int r){
    if(l == r){
        tree[node].a = {v[l].second};
        tree[node].b = {v[l].second - v[l].first + 1};
        return;
    }
    int mid = (l + r) / 2;
    build(node + 1, l, mid);
    build(node + (mid - l + 1) * 2, mid + 1, r);
    tree[node] = combine(tree[node + 1], tree[node + (mid - l + 1) * 2]);
}

int ask1(int node, int l, int r, int ql, int qr, int val){
    if(ql > r || qr < l) return 0;
    if(ql <= l && r <= qr){
        auto itr = lower_bound(all(tree[node].a), val);
        return (tree[node].a.end() - itr);
    }
    int mid = (l + r) / 2;
    return ask1(node + 1, l, mid, ql, qr, val) + ask1(node + (mid - l + 1) * 2, mid + 1, r, ql, qr, val);
}
int ask2(int node, int l, int r, int ql, int qr, int val){
    if(ql > r || qr < l) return 0;
    if(ql <= l && r <= qr){
        auto itr = lower_bound(all(tree[node].b), val);
        return (tree[node].b.end() - itr);
    }
    int mid = (l + r) / 2;
    return ask2(node + 1, l, mid, ql, qr, val) + ask2(node + (mid - l + 1) * 2, mid + 1, r, ql, qr, val);
}

vector<pii> b1;
vector<pii> b2;

void update(){
    v.clear();
    for(auto& p:st){
        v.push_back(p);
    }
    b1.clear();
    b2.clear();
    build(1, 0, v.size() - 1);
}

int f(pii a, pii b){
    int ans = min(a.second, b.second) - max(a.first, b.first) + 1;
    if(ans <= 0) return 0;
    return ans;
}

void solve(){
    int o; cin >> n >> o;
    int lastAns = 0;
    while(n--){
        int t; cin >> t;
        if(t == 1){
            int a, b; cin >> a >> b;
            a = a ^ (o * lastAns);
            b = b ^ (o * lastAns);
            if(a > b) swap(a, b);
            arr[nxt++] = {a, b};
            b1.push_back({a, b});
            st.insert({a, b});
        }
        else if(t == 2){
            int id; cin >> id;
            b2.push_back(arr[id]);
            st.erase(st.find(arr[id]));
        }
        else{
            int a, b, c; cin >> a >> b >> c;
            a = a ^ (t * lastAns);
            b = b ^ (t * lastAns);
            if(a > b) swap(a, b);
            if(b - a + 1 < c){
                cout << 0 << '\n';
                continue;
            }
            if(b1.size() + b2.size() > BLOCK){
                update();
            }
            int ans = 0;
            if(v.size() != 0){
                int i = lower_bound(all(v), make_pair(a, -1)) - v.begin();
                if(i > 0){
                    ans += ask1(1, 0, v.size() - 1, 0, i - 1, a + c - 1);
                }
                int j = upper_bound(all(v), make_pair(b - c + 1, oo)) - v.begin();
                if(j > 0 && i <= j - 1){
                    ans += ask2(1, 0, v.size() - 1, i, j - 1, c);
                }
            }
            for(auto p:b1){
                ans += f(p, {a, b}) >= c;
            }
            for(auto p:b2){
                ans -= f(p, {a, b}) >= c;
            }
            lastAns = ans;
            cout << ans << '\n';
        }
    }
}

/*
6 1
1 1 2
3 2 4 2
1 3 5
3 2 3 1
2 1
3 0 3 1
*/
/*
6 0
1 3 10
1 3 5
3 6 10 6
2 1
1 3 10
3 6 4 2
*/

int main()
{
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Runtime error 21 ms 38516 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 319 ms 35836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 38488 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 38488 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Runtime error 21 ms 38516 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Runtime error 21 ms 38516 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -