結果

問題 No.2292 Interval Union Find
ユーザー 沙耶花沙耶花
提出日時 2023-05-05 21:54:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 661 ms / 5,000 ms
コード長 1,795 bytes
コンパイル時間 4,327 ms
コンパイル使用メモリ 273,876 KB
実行使用メモリ 35,580 KB
最終ジャッジ日時 2024-05-02 16:04:52
合計ジャッジ時間 29,741 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 457 ms
11,772 KB
testcase_05 AC 424 ms
11,700 KB
testcase_06 AC 445 ms
11,776 KB
testcase_07 AC 418 ms
11,388 KB
testcase_08 AC 654 ms
34,432 KB
testcase_09 AC 636 ms
34,428 KB
testcase_10 AC 661 ms
34,424 KB
testcase_11 AC 661 ms
34,172 KB
testcase_12 AC 620 ms
34,428 KB
testcase_13 AC 596 ms
33,664 KB
testcase_14 AC 627 ms
34,044 KB
testcase_15 AC 615 ms
34,176 KB
testcase_16 AC 619 ms
34,044 KB
testcase_17 AC 650 ms
34,300 KB
testcase_18 AC 341 ms
34,172 KB
testcase_19 AC 477 ms
35,576 KB
testcase_20 AC 468 ms
35,580 KB
testcase_21 AC 511 ms
34,936 KB
testcase_22 AC 508 ms
35,064 KB
testcase_23 AC 517 ms
35,068 KB
testcase_24 AC 519 ms
34,944 KB
testcase_25 AC 525 ms
35,068 KB
testcase_26 AC 517 ms
35,052 KB
testcase_27 AC 523 ms
34,940 KB
testcase_28 AC 597 ms
34,936 KB
testcase_29 AC 538 ms
34,940 KB
testcase_30 AC 513 ms
34,940 KB
testcase_31 AC 501 ms
35,068 KB
testcase_32 AC 516 ms
34,944 KB
testcase_33 AC 510 ms
34,944 KB
testcase_34 AC 519 ms
34,940 KB
testcase_35 AC 538 ms
34,940 KB
testcase_36 AC 539 ms
35,068 KB
testcase_37 AC 507 ms
34,936 KB
testcase_38 AC 518 ms
34,940 KB
testcase_39 AC 512 ms
34,936 KB
testcase_40 AC 519 ms
34,940 KB
testcase_41 AC 223 ms
9,852 KB
testcase_42 AC 232 ms
9,812 KB
testcase_43 AC 246 ms
9,852 KB
testcase_44 AC 316 ms
9,984 KB
testcase_45 AC 328 ms
9,848 KB
testcase_46 AC 338 ms
9,976 KB
testcase_47 AC 365 ms
9,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
using P = pair<int,int>;

P op(P a,P b){
	a.first += b.first;
	a.second += b.second;
	return a;
}

P e(){
	return make_pair(0,0);
}

P mapping(int a,P b){
	if(a==-1)return b;
	b.first = a * b.second;
	return b;
}

int composition(int a,int b){
	if(a==-1)return b;
	return a;
}

int id(){
	return -1;
}

bool check(P a){
	return a.first==a.second;
}

int main(){
	
	int n,q;
	cin>>n>>q;
	vector<int> t(q),a(q),b(q);
	vector<int> v;
	rep(i,q){
		cin>>t[i];
		if(t[i]!=4){
			cin>>a[i]>>b[i];
			v.push_back(a[i]);
			v.push_back(a[i]+1);
			v.push_back(b[i]);
			v.push_back(b[i]+1);
		}
		else{
			cin>>a[i];
			v.push_back(a[i]);
			v.push_back(a[i]+1);
		}
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	
	lazy_segtree<P,op,e,int,mapping,composition,id> seg(v.size()-1);
	rep(i,v.size()-1)seg.set(i,make_pair(0,v[i+1] - v[i]));
	
	rep(i,q){
		if(t[i]<=2){
			int l = distance(v.begin(),lower_bound(v.begin(),v.end(),a[i]));
			int r = distance(v.begin(),lower_bound(v.begin(),v.end(),b[i]));
			if(t[i]==1)seg.apply(l,r,1);
			else seg.apply(l,r,0);
		}
		if(t[i]==3){
			if(a[i]>b[i])swap(a[i],b[i]);
			int l = distance(v.begin(),lower_bound(v.begin(),v.end(),a[i]));
			int r = distance(v.begin(),lower_bound(v.begin(),v.end(),b[i]));
			if(seg.prod(l,r).first==b[i]-a[i])cout<<1<<endl;
			else cout<<0<<endl;
		}
		if(t[i]==4){
			int l = distance(v.begin(),lower_bound(v.begin(),v.end(),a[i]));
			int r = seg.max_right<check>(l);
			l = seg.min_left<check>(r);
			cout<<v[r]-v[l]+1<<endl;
		}
	}
	
	return 0;
}
0