# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
667432 | Kaztaev_Alisher | Segments (IZhO18_segments) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x << " = " << x << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;
const ll N = 2e5+5 , M = 290+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
using namespace std;
int n , t , BL = 700 , blsz , ID = 0;
vector<pair<int , pii>> v;
vector<pii> kerek;
vector<int> bl[M] , br[M];
int mn[M] = {inf};
int mx[M] , pr[M];
bool was[N];
pii p[N];
void build(){
blsz = (v.sz()-1)/BL;
for(int j = 0 ; j <= blsz ; j++) pr[j] = 0 , mn[j] = inf , mx[j] = 0 , bl[i].cl() , br[i].cl();
vector<pair<int , pii > > v1;
for(int i = 1; i <= ID; i++){
if(was[i] == 0) v1.pb({p[i].S-p[i].F+1 , {p[i].F , p[i].S}});
}
sort(all(v1));
swap(v , v1);
blsz = (v.sz()-1)/BL;
for(int i = 0 ; i < v.sz(); i++){
int j = i / BL;
bl[j].pb(v[i].S.S);
br[j].pb(v[i].S.F);
mn[j] = min(mn[j] , v[i].F);
mx[j] = max(mx[j] , v[i].F);
pr[j]++;
}
for(int j = 0 ; j <= blsz ; j++) if(j) pr[j] += pr[j-1];
for(int i = 0; i <= blsz; i++){
sort(all(bl[i]));
sort(all(br[i]));
}
kerek.cl();
}
int get(int l , int r , int k){
int ans = v.sz();
for(int i = 0; i <= blsz; i++){
if(mn[i] < k && mx[i] >= k){
int pref = 0;
if(i > 0) pref = pr[i-1];
for(int j = pref; j < pr[i]; j++){
if(v[j].F < k){
ans--;
continue;
}
int L = v[j].S.F , R = v[j].S.S;
if(L > r-k+1) ans--;
if(R < l+k-1) ans--;
}
} else if(mn[i] >= k){
int res = br[i].sz();
for(int L = 0 , R = br[i].sz()-1; L <= R;){
int md = (L+R) >> 1;
if(br[i][md] > r-k+1) res = md , R = md-1;
else L = md+1;
}
ans -= br[i].sz()-res;
res = -1;
for(int L = 0 , R = bl[i].sz()-1; L <= R;){
int md = (L+R) >> 1;
if(bl[i][md] < l+k-1) res = md , L = md+1;
else R = md-1;
}
ans -= res+1;
} else {
ans -= br[i].sz();
}
}
for(pair<int , int > x : kerek){
int L = p[x.F].F , R = p[x.F].S , res = 0 , ok = 1;
if(l <= L && R <= r) res = R-L+1;
else if(l <= L && L <= r) res = r-L+1;
else if(l <= R && R <= r) res = R-l+1;
else if(L <= l && r <= R) res = r-l+1;
if(x.S == 0) ok *= -1;
if(res >= k) ans += ok;
}
return ans;
}
void solve(){
cin >> n >> t;
int lst = 0 ;
for(int i = 1; i <= n; i++){
int tp , l , r;
cin >> tp;
if(kerek.sz() == 447) build();
if(tp == 2){
int k;
cin >> k;
was[k] = 1;
kerek.pb({k , 0});
continue;
}
cin >> l >> r;
l = (l ^ (t * lst));
r = (r ^ (t * lst));
if(l > r) swap(l , r);
if(tp == 3){
int k;
cin >> k;
lst = get(l,r,k);
cout << lst <<"\n";
} else {
p[++ID] = {l , r};
kerek.pb({ID , 1});
}
}
}
signed main(){
ios;
solve();
return 0;
}
/*
5 0
1 3 10
1 3 5
3 6 4 2
3 11 33 22
3 7 10 3
*/