Submission #667423

# Submission time Handle Problem Language Result Execution time Memory
667423 2022-12-01T09:51:21 Z Kaztaev_Alisher Segments (IZhO18_segments) C++17
0 / 100
2 ms 980 KB
//#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 = 5e3+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
 
using namespace std;
 
int n , t , BL , blsz , ID = 0;
vector<pair<int , pii>> v;
vector<int> bl[N] , br[N];
vector<pii> kerek;
int mn[N] = {inf};
int mx[N] , pr[N];
bool was[N];
pii p[N];
void build(){
	BL = 400;
	blsz = (v.sz()-1)/BL;
	for(int j = 0 ; j <= blsz ; j++) pr[j] = 0 , mn[j] = inf , mx[j] = 0;
	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}});
		}
	}
	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]++;
	}
	sort(all(v));
	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 , ok = 0;	
	for(int i = 1; i <= n; i++){
		int tp , l , r;
		cin >> tp;
		if(kerek.sz() == 400) 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 if(tp == 1){
			int ras = r-l+1;
			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
*/ 

Compilation message

segments.cpp: In function 'void build()':
segments.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(int i = 0 ; i < v.sz(); i++){
      |                  ~~^~~~~~~~
segments.cpp: In function 'void solve()':
segments.cpp:142:8: warning: unused variable 'ras' [-Wunused-variable]
  142 |    int ras = r-l+1;
      |        ^~~
segments.cpp:120:16: warning: unused variable 'ok' [-Wunused-variable]
  120 |  int lst = 0 , ok = 0;
      |                ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Runtime error 2 ms 972 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 980 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Runtime error 2 ms 972 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 468 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Runtime error 2 ms 972 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -