結果

問題 No.2292 Interval Union Find
ユーザー 👑 kmjpkmjp
提出日時 2023-05-05 22:04:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,386 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 211,996 KB
実行使用メモリ 12,928 KB
最終ジャッジ日時 2024-05-02 16:22:07
合計ジャッジ時間 14,628 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 168 ms
5,376 KB
testcase_05 AC 223 ms
5,376 KB
testcase_06 AC 176 ms
5,376 KB
testcase_07 AC 205 ms
5,376 KB
testcase_08 AC 202 ms
5,376 KB
testcase_09 AC 207 ms
5,376 KB
testcase_10 AC 193 ms
5,376 KB
testcase_11 AC 187 ms
5,376 KB
testcase_12 AC 209 ms
5,376 KB
testcase_13 AC 185 ms
5,376 KB
testcase_14 AC 184 ms
5,376 KB
testcase_15 AC 186 ms
5,376 KB
testcase_16 AC 197 ms
5,376 KB
testcase_17 AC 198 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 180 ms
12,672 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

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(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