結果

問題 No.2292 Interval Union Find
ユーザー 沙耶花沙耶花
提出日時 2023-05-05 21:54:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 726 ms / 5,000 ms
コード長 1,795 bytes
コンパイル時間 5,030 ms
コンパイル使用メモリ 269,520 KB
実行使用メモリ 35,780 KB
最終ジャッジ日時 2023-08-15 03:51:59
合計ジャッジ時間 34,622 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 479 ms
11,424 KB
testcase_05 AC 479 ms
11,956 KB
testcase_06 AC 479 ms
11,460 KB
testcase_07 AC 467 ms
11,436 KB
testcase_08 AC 710 ms
34,408 KB
testcase_09 AC 712 ms
34,244 KB
testcase_10 AC 707 ms
34,408 KB
testcase_11 AC 710 ms
34,708 KB
testcase_12 AC 708 ms
34,220 KB
testcase_13 AC 681 ms
33,500 KB
testcase_14 AC 693 ms
34,024 KB
testcase_15 AC 715 ms
33,952 KB
testcase_16 AC 688 ms
34,304 KB
testcase_17 AC 726 ms
34,320 KB
testcase_18 AC 372 ms
33,876 KB
testcase_19 AC 555 ms
35,616 KB
testcase_20 AC 555 ms
35,780 KB
testcase_21 AC 592 ms
35,340 KB
testcase_22 AC 592 ms
34,828 KB
testcase_23 AC 592 ms
35,220 KB
testcase_24 AC 603 ms
35,024 KB
testcase_25 AC 599 ms
34,808 KB
testcase_26 AC 593 ms
34,856 KB
testcase_27 AC 596 ms
34,928 KB
testcase_28 AC 591 ms
34,652 KB
testcase_29 AC 590 ms
34,872 KB
testcase_30 AC 593 ms
34,908 KB
testcase_31 AC 597 ms
34,908 KB
testcase_32 AC 591 ms
34,920 KB
testcase_33 AC 602 ms
35,088 KB
testcase_34 AC 585 ms
34,908 KB
testcase_35 AC 596 ms
35,720 KB
testcase_36 AC 591 ms
34,888 KB
testcase_37 AC 596 ms
35,236 KB
testcase_38 AC 598 ms
34,956 KB
testcase_39 AC 589 ms
35,032 KB
testcase_40 AC 593 ms
34,820 KB
testcase_41 AC 239 ms
9,916 KB
testcase_42 AC 244 ms
10,512 KB
testcase_43 AC 265 ms
10,688 KB
testcase_44 AC 347 ms
9,640 KB
testcase_45 AC 353 ms
10,704 KB
testcase_46 AC 353 ms
9,764 KB
testcase_47 AC 400 ms
10,360 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