結果

問題 No.2292 Interval Union Find
ユーザー 👑 kmjpkmjp
提出日時 2023-05-05 22:06:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 284 ms / 5,000 ms
コード長 2,392 bytes
コンパイル時間 3,955 ms
コンパイル使用メモリ 209,512 KB
実行使用メモリ 12,796 KB
最終ジャッジ日時 2023-08-15 04:14:36
合計ジャッジ時間 17,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 192 ms
4,376 KB
testcase_05 AC 238 ms
4,376 KB
testcase_06 AC 189 ms
4,380 KB
testcase_07 AC 230 ms
4,384 KB
testcase_08 AC 228 ms
4,380 KB
testcase_09 AC 227 ms
4,380 KB
testcase_10 AC 216 ms
4,376 KB
testcase_11 AC 211 ms
4,380 KB
testcase_12 AC 231 ms
4,380 KB
testcase_13 AC 200 ms
4,380 KB
testcase_14 AC 200 ms
4,380 KB
testcase_15 AC 207 ms
4,376 KB
testcase_16 AC 204 ms
4,376 KB
testcase_17 AC 223 ms
4,380 KB
testcase_18 AC 162 ms
12,736 KB
testcase_19 AC 263 ms
12,792 KB
testcase_20 AC 250 ms
12,796 KB
testcase_21 AC 269 ms
8,860 KB
testcase_22 AC 272 ms
8,892 KB
testcase_23 AC 283 ms
9,060 KB
testcase_24 AC 273 ms
8,860 KB
testcase_25 AC 275 ms
8,924 KB
testcase_26 AC 280 ms
8,884 KB
testcase_27 AC 277 ms
8,852 KB
testcase_28 AC 277 ms
8,980 KB
testcase_29 AC 278 ms
9,156 KB
testcase_30 AC 284 ms
8,932 KB
testcase_31 AC 283 ms
9,108 KB
testcase_32 AC 278 ms
8,984 KB
testcase_33 AC 274 ms
8,860 KB
testcase_34 AC 280 ms
9,172 KB
testcase_35 AC 274 ms
8,860 KB
testcase_36 AC 274 ms
8,864 KB
testcase_37 AC 277 ms
8,920 KB
testcase_38 AC 275 ms
9,044 KB
testcase_39 AC 280 ms
9,068 KB
testcase_40 AC 277 ms
8,928 KB
testcase_41 AC 170 ms
4,376 KB
testcase_42 AC 174 ms
4,376 KB
testcase_43 AC 177 ms
4,376 KB
testcase_44 AC 182 ms
4,380 KB
testcase_45 AC 183 ms
4,380 KB
testcase_46 AC 186 ms
4,380 KB
testcase_47 AC 196 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,Q;
set<pair<int,int>> S={{-2,-1},{1<<30,1+(1<<30)}};


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	while(Q--) {
		cin>>i;
		/*
		FORR2(a,b,S) cout<<a<<":"<<b<<" ";
		cout<<endl;
		*/
		if(i==1||i==2) {
			int L,R;
			cin>>L>>R;
			if(i==1) {
				pair<int,int> P={L,R};
				auto it=S.lower_bound({L+1,0});
				it--;
				if(it->second>=L) {
					P.first=it->first;
					P.second=max(it->second,R);
					S.erase(it);
				}
				while(1) {
					it=S.lower_bound({L+1,0});
					if(it->first<=R) {
						P.second=max(P.second,it->second);
						S.erase(it);
					}
					else {
						break;
					}
				}
				S.insert(P);
			}
			else {
				while(1) {
					auto it=S.lower_bound({L,0});
					if(it->first>=R) break;
					if(it->second<=R) {
						S.erase(it);
					}
					else {
						auto p=*it;
						S.erase(it);
						S.insert({R,p.second});
					}
				}
				while(1) {
					auto it=S.lower_bound({R,0});
					it--;
					if(it->second>R) {
						auto p=*it;
						S.erase(it);
						S.insert({p.first,L});
						S.insert({R,p.second});
					}
					else if(it->second>L) {
						auto p=*it;
						S.erase(it);
						S.insert({p.first,L});
					}
					break;
				}
			}
			
		}
		else if(i==3) {
			cin>>x>>y;
			if(x>y) swap(x,y);
			auto it=S.lower_bound({x+1,0});
			it--;
			if(x==y||it->first<=x&&y<=it->second) {
				cout<<1<<endl;
			}
			else {
				cout<<0<<endl;
			}
		}
		else {
			cin>>x;
			auto it=S.lower_bound({x+1,0});
			it--;
			if(it->first<=x&&x<=it->second) {
				cout<<1+it->second-it->first<<endl;
			}
			else {
				cout<<1<<endl;
			}
			
		}
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0