結果

問題 No.2292 Interval Union Find
ユーザー Ecrade_Ecrade_
提出日時 2023-05-05 22:24:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 522 ms / 5,000 ms
コード長 2,388 bytes
コンパイル時間 1,918 ms
コンパイル使用メモリ 175,580 KB
実行使用メモリ 28,544 KB
最終ジャッジ日時 2024-05-02 17:04:18
合計ジャッジ時間 15,713 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 62 ms
5,376 KB
testcase_05 AC 152 ms
5,376 KB
testcase_06 AC 58 ms
5,376 KB
testcase_07 AC 148 ms
5,376 KB
testcase_08 AC 129 ms
5,376 KB
testcase_09 AC 123 ms
5,376 KB
testcase_10 AC 99 ms
5,376 KB
testcase_11 AC 88 ms
5,376 KB
testcase_12 AC 134 ms
5,376 KB
testcase_13 AC 66 ms
5,376 KB
testcase_14 AC 77 ms
5,376 KB
testcase_15 AC 88 ms
5,376 KB
testcase_16 AC 75 ms
5,376 KB
testcase_17 AC 109 ms
5,376 KB
testcase_18 AC 522 ms
28,288 KB
testcase_19 AC 429 ms
28,288 KB
testcase_20 AC 472 ms
28,544 KB
testcase_21 AC 330 ms
18,176 KB
testcase_22 AC 342 ms
18,432 KB
testcase_23 AC 334 ms
18,176 KB
testcase_24 AC 336 ms
18,176 KB
testcase_25 AC 331 ms
18,176 KB
testcase_26 AC 334 ms
18,304 KB
testcase_27 AC 344 ms
18,432 KB
testcase_28 AC 339 ms
18,176 KB
testcase_29 AC 343 ms
18,432 KB
testcase_30 AC 337 ms
18,304 KB
testcase_31 AC 335 ms
18,176 KB
testcase_32 AC 346 ms
18,176 KB
testcase_33 AC 329 ms
18,304 KB
testcase_34 AC 348 ms
18,304 KB
testcase_35 AC 352 ms
18,176 KB
testcase_36 AC 340 ms
18,304 KB
testcase_37 AC 345 ms
18,304 KB
testcase_38 AC 345 ms
18,304 KB
testcase_39 AC 355 ms
18,176 KB
testcase_40 AC 338 ms
18,304 KB
testcase_41 AC 20 ms
5,376 KB
testcase_42 AC 28 ms
5,376 KB
testcase_43 AC 41 ms
5,376 KB
testcase_44 AC 54 ms
5,376 KB
testcase_45 AC 54 ms
5,376 KB
testcase_46 AC 67 ms
5,376 KB
testcase_47 AC 80 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,o,l,r,x,y,a[200009];
pair <ll,ll> tmp[200009];
struct st{ll l,r; mutable ll v; bool operator < (const st &a) const{return l < a.l;}};
set <st> s;
inline ll read(){
	ll s = 0,w = 1;
	char ch = getchar();
	while (ch > '9' || ch < '0'){ if (ch == '-') w = -1; ch = getchar();}
	while (ch <= '9' && ch >= '0') s = (s << 1) + (s << 3) + (ch ^ 48),ch = getchar();
	return s * w;
}
ll qp(ll x,ll y,ll mod){
	ll a = 1,b = x % mod;
	while (y){
		if (y & 1) a = a * b % mod;
		b = b * b % mod,y >>= 1;
	}
	return a;
}
set <st> :: iterator split(ll pos){
	set <st> :: iterator it = s.lower_bound((st){pos,pos,0});
	if (it != s.end() && it -> l == pos) return it;
	it --;
	if (it -> r < pos) return s.end();
	st now = *it;
	s.erase(it),s.insert((st){now.l,pos - 1,now.v});
	return s.insert((st){pos,now.r,now.v}).first;
}
void assign(ll l,ll r,ll v){
	set <st> :: iterator itr = split(r + 1),itl = split(l);
	s.erase(itl,itr),s.insert((st){l,r,v});
	set <st> :: iterator it = s.lower_bound((st){l,l,0});
	set <st> :: iterator it2 = s.upper_bound((st){l,l,0});
	if (it2 != s.end()){
		if (it2 -> v == it -> v){
			st qwq = (st){it -> l,it2 -> r,it -> v};
			s.erase(it),s.erase(it2);
			s.insert(qwq);
		}
	}
	it = s.lower_bound((st){l,l,0});
	if (it != s.begin()){
		set <st> :: iterator it2 = (-- s.lower_bound((st){l,l,0}));
		if (it2 -> v == it -> v){
			st qwq = (st){it2 -> l,it -> r,it -> v};
			s.erase(it),s.erase(it2);
			s.insert(qwq);
		}
	}
}
void query(ll x,ll y){
	if (x > y) swap(x,y);
	if (x == y){puts("1"); return;}
	if (!s.size()){puts("0"); return;}
	set <st> :: iterator it = -- s.upper_bound((st){x,x,0});
	if (it -> v == 0 || (it -> v == 1 && it -> r < y - 1)) puts("0");
	else puts("1");
}
void query2(ll x){
	if (!s.size()){puts("1"); return;}
	set <st> :: iterator it = -- s.upper_bound((st){x,x,0});
	ll ans = 1;
	if (it -> v == 1) ans += it -> r - it -> l + 1;
	else if (it != s.begin()){
		it --;
		if (it -> r == x - 1 && it -> v == 1) ans += it -> r - it -> l + 1;
	}
	printf("%lld\n",ans);
}
int main(){
	n = read(),m = read();
	s.insert((st){1,n - 1,0});
	while (m --){
		o = read();
		if (o == 1) l = read(),r = read(),assign(l,r - 1,1);
		if (o == 2) l = read(),r = read(),assign(l,r - 1,0);
		if (o == 3) x = read(),y = read(),query(x,y);
		if (o == 4) x = read(),query2(x);
	}
	return 0;
}
0