結果

問題 No.2292 Interval Union Find
ユーザー 👑 kmjpkmjp
提出日時 2023-05-05 22:06:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 233 ms / 5,000 ms
コード長 2,392 bytes
コンパイル時間 2,673 ms
コンパイル使用メモリ 211,988 KB
実行使用メモリ 12,800 KB
最終ジャッジ日時 2024-05-02 16:26:42
合計ジャッジ時間 14,237 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 194 ms
5,376 KB
testcase_05 AC 223 ms
5,376 KB
testcase_06 AC 177 ms
5,376 KB
testcase_07 AC 233 ms
5,376 KB
testcase_08 AC 208 ms
5,376 KB
testcase_09 AC 213 ms
5,376 KB
testcase_10 AC 194 ms
5,376 KB
testcase_11 AC 189 ms
5,376 KB
testcase_12 AC 212 ms
5,376 KB
testcase_13 AC 189 ms
5,376 KB
testcase_14 AC 185 ms
5,376 KB
testcase_15 AC 193 ms
5,376 KB
testcase_16 AC 185 ms
5,376 KB
testcase_17 AC 198 ms
5,376 KB
testcase_18 AC 146 ms
12,800 KB
testcase_19 AC 177 ms
12,800 KB
testcase_20 AC 189 ms
12,800 KB
testcase_21 AC 219 ms
8,960 KB
testcase_22 AC 215 ms
8,960 KB
testcase_23 AC 215 ms
8,960 KB
testcase_24 AC 209 ms
8,960 KB
testcase_25 AC 217 ms
8,960 KB
testcase_26 AC 211 ms
8,960 KB
testcase_27 AC 224 ms
8,960 KB
testcase_28 AC 213 ms
8,960 KB
testcase_29 AC 227 ms
8,832 KB
testcase_30 AC 221 ms
8,960 KB
testcase_31 AC 217 ms
8,960 KB
testcase_32 AC 218 ms
8,832 KB
testcase_33 AC 213 ms
8,832 KB
testcase_34 AC 219 ms
8,960 KB
testcase_35 AC 218 ms
8,960 KB
testcase_36 AC 210 ms
8,832 KB
testcase_37 AC 213 ms
8,960 KB
testcase_38 AC 216 ms
8,960 KB
testcase_39 AC 215 ms
8,960 KB
testcase_40 AC 225 ms
8,960 KB
testcase_41 AC 159 ms
5,376 KB
testcase_42 AC 156 ms
5,376 KB
testcase_43 AC 163 ms
5,376 KB
testcase_44 AC 165 ms
5,376 KB
testcase_45 AC 176 ms
5,376 KB
testcase_46 AC 172 ms
5,376 KB
testcase_47 AC 173 ms
5,376 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