Submission #667387

# Submission time Handle Problem Language Result Execution time Memory
667387 2022-12-01T08:40:04 Z Kaztaev_Alisher Segments (IZhO18_segments) C++17
15 / 100
2072 ms 9440 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 = 1e5+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;
 
using namespace std;
 
int n , t , BL , blsz;
vector<pair<int , pii>> v;
vector<int> bl[N] , br[N];
int mn[N] = {inf};
int mx[N] , pr[N];
void build(){
	BL = 200;
	sort(all(v));
	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]));
	}
}
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();
		}
	}
	return ans;
}	
void solve(){
	cin >> n >> t;
	int lst = 0 , ok = 0;	
	while(n--){
		int tp , l , r;
		cin >> tp >> l >> r;
		l = (l ^ (t * lst));		
		r = (r ^ (t * lst));
		if(l > r) swap(l , r);
		if(tp == 3){
			if(ok == 0) build();
			ok = 1;
			int k;
			cin >> k;
			lst = get(l,r,k);
			cout << lst <<"\n";
		} else {
			int ras = r-l+1;
			v.pb({ras ,  {l , r}});
		}
	}	 	
}
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:46: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]
   46 |  for(int i = 0 ; i < v.sz(); i++){
      |                  ~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2005 ms 6460 KB Output is correct
2 Correct 2031 ms 9212 KB Output is correct
3 Correct 2072 ms 9064 KB Output is correct
4 Correct 2013 ms 9112 KB Output is correct
5 Correct 467 ms 9440 KB Output is correct
6 Correct 265 ms 9372 KB Output is correct
7 Correct 2071 ms 9044 KB Output is correct
8 Correct 1985 ms 9260 KB Output is correct
9 Correct 2024 ms 9124 KB Output is correct
10 Correct 1292 ms 8844 KB Output is correct
11 Correct 1622 ms 8976 KB Output is correct
12 Correct 1731 ms 9320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 6724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 6772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -