Submission #893767

# Submission time Handle Problem Language Result Execution time Memory
893767 2023-12-27T11:16:21 Z vjudge1 Segments (IZhO18_segments) C++17
0 / 100
17 ms 3828 KB
// 以上帝的名义
// 候选硕士
#include <bits/stdc++.h>

#ifdef local
#include "algo/debug.h"
#else
#define dbg(x...) 0
#endif

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std ;
using ll = long long ;
using ld = long double ;

struct Fenwick {
   vector<int> t ;
   int n;
   Fenwick() {}
   Fenwick(int len) {
      n = len ;
      t.assign(n + 1, 0) ;
   }
   void upd(int i, ll x) {
      while (i <= n) {
         t[i] += x;
         i += (i & (-i)) ;
      }
   }
   ll get(int i) {
      ll sum = 0 ;
      while (i) {
         sum += t[i] ;
         i -= (i & (-i)) ;
      }
      return sum ;
   }
   ll get(int l, int r) {
        if (l > r) swap(l, r) ;
        return get(r) - get(l - 1) ;
   }
};

Fenwick _l, _r ;
int n , t, idx = 0, last = 0, sz = 0 ;
vector<pair<int,int>> p ;

void insert(int l ,int r) {
    sz++ ;
    p[++idx] = {l, r} ;
    _l.upd(l, 1) ;
    _r.upd(r, 1) ;
}

void remove(int i) {
    sz-- ;
    auto [l, r] = p[i] ;
    _l.upd(l, -1) ;
    _r.upd(r, -1) ;
}

int query(int lo, int hi, int k) {
    int mn = lo + k - 2 ;
    int mx = hi - k + 2 ;
    int ret = sz ;
    if (mx <= n)
        ret -= _l.get(mx, n) ;
    if (mn >= 1)
        ret -= _r.get(mn) ;
    last = ret ;
//    dbg(lo, hi, k, ret) ;
    return ret ;
}

int32_t main() {
    ios::sync_with_stdio(false) ;
    cin.tie(nullptr) ;
    cin >> n >> t ;
    p.resize(n + 5) ;
    _l = Fenwick(n + 5) ;
    _r = Fenwick(n + 5) ;
    for (int i = 0 ; i < n ; i++) {
        int cmd ; cin >> cmd ;
        if (cmd == 1) {
            int a , b; cin >> a >> b ;
            int l = (a ^ (t * last)) ;
            int r = (b ^ (t * last)) ;
            if (l > r) swap(l, r) ;
            insert(l + 1, r + 1) ;
        } else if (cmd == 2) {
            int ind ; cin >> ind ;
            remove(ind) ;
        } else {
            int a , b, k ; cin >> a >> b >> k ;
            int l = (a ^ (t * last)) ;
            int r = (b ^ (t * last)) ;
            if (l > r) swap(l, r) ;
            cout << query(l + 1, r + 1, k) << "\n" ;
        }
    }
    return 0 ;
}

// 希望白银
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Runtime error 1 ms 600 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 3676 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 3828 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 3672 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Runtime error 1 ms 600 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Runtime error 1 ms 600 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -