結果
| 問題 |
No.2292 Interval Union Find
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-05 22:13:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 299 ms / 5,000 ms |
| コード長 | 4,700 bytes |
| コンパイル時間 | 1,960 ms |
| コンパイル使用メモリ | 180,460 KB |
| 実行使用メモリ | 30,592 KB |
| 最終ジャッジ日時 | 2024-11-23 08:13:24 |
| 合計ジャッジ時間 | 11,623 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 44 |
ソースコード
/*
* Author: $%U%$
* Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define per(i,a,b) for(ll i=(a);i>=(b);i--)
#define re(i,a,b) for(ll i=(a);i<(b);i++)
#define pe(i,a,b) for(ll i=(a);i>(b);i--)
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
template <typename T>
inline void read(T& r) {
r=0;bool w=0; char ch=getchar();
while(ch<'0'||ch>'9') w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9') r=r*10+(ch^48), ch=getchar();
r=w?-r:r;
}
template <typename T>
inline void readupp(T& r){
r=0;
char ch=getchar();
while(ch>'Z'||ch<'A')ch=getchar();
r=ch;
}
template <typename T>
inline void readlow(T& r){
r=0;
char ch=getchar();
while(ch>'z'||ch<'a')ch=getchar();
r=ch;
}
template <typename T>
inline void readdig(T& r){
r=0;
char ch=getchar();
while(ch>'9'||ch<'0')ch=getchar();
r=ch-'0';
}
template <typename T>
inline void readvisi(T& r){
r=0;
char ch=getchar();
while(ch>126||ch<33)ch=getchar();
r=ch;
}
template <typename T>
inline ll readlowstr(T& r){
ll n=0;
char ch=getchar();
while(ch>'z'||ch<'a')ch=getchar();
while(ch<='z'&&ch>='a')r[++n]=ch-'a',ch=getchar();
return n;
}
template <typename T>
inline ll readuppstr(T& r){
ll n=0;
char ch=getchar();
while(ch>'Z'||ch<'A')ch=getchar();
while(ch<='Z'&&ch>='A')r[++n]=ch-'A',ch=getchar();
return n;
}
template <typename T>
inline ll readdigstr(T& r){
ll n=0;
char ch=getchar();
while(ch>'9'||ch<'0')ch=getchar();
while(ch<='9'&&ch>='0')r[++n]=ch-'0',ch=getchar();
return n;
}
template <typename T>
inline ll readvisistr(T& r){
ll n=0;
char ch=getchar();
while(ch>126||ch<33)ch=getchar();
while(ch<=126&&ch>=33)r[++n]=ch,ch=getchar();
return n;
}
const ll MOD=998244353;
ll gcd(ll A,ll B){return B?gcd(B,A%B):A;}
template<typename T>
void chkmax(T&A,T B){if(A<B)A=B;}
template<typename T>
void chkmin(T&A,T B){if(A>B)A=B;}
template<typename T>
T Madd(T A,T B){return A+B>=MOD?A+B-MOD:A+B;}
template<typename T>
T Msub(T A,T B){return A-B<0?A-B+MOD:A-B;}
template<typename T>
void MODed(T &A){A%=MOD;A+=(A<0?MOD:0);}
ll pw(ll A,ll B){
ll res=1;
while(B){
if(B&1)res=res*A%MOD;
A=A*A%MOD;
B>>=1;
}
return res;
}
void _FILE(string s){
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
const ll N=200003,M=3003,INF=2000000000000000007ll;
set<pair<pair<ll,ll>,bool> > s;
typedef set<pair<pair<ll,ll>,bool> >::iterator IT;
ll n,q;
int main(){
read(n),read(q);
s.insert(make_pair(make_pair(1,n-1),0));
rep(i,1,q){
//cout<<"i:"<<i<<endl;
ll in1,in2,in3;
read(in1);
if(in1==1){
read(in2),read(in3);
in3--;
IT it1=s.lower_bound(make_pair(make_pair(in2,n+1),1));
IT it2=s.lower_bound(make_pair(make_pair(in3,n+1),1));
it1--,it2--;
ll o=it1->first.first,p=it2->first.second;
bool o1=it1->second,o2=it2->second;
if(o1==0&&it1->first.first==in2&&in2!=1)it1--,o1=1,o=it1->first.first;
if(o2==0&&it2->first.second==in3&&in3!=n-1)it2++,o2=1,p=it2->first.second;
if(o1==1)in2=o;
if(o2==1)in3=p;
it2++;
s.erase(it1,it2);
s.insert(make_pair(make_pair(in2,in3),1));
if(o<in2)s.insert(make_pair(make_pair(o,in2-1),0));
if(p>in3)s.insert(make_pair(make_pair(in3+1,p),0));
}
if(in1==2){
read(in2),read(in3);
in3--;
IT it1=s.lower_bound(make_pair(make_pair(in2,n+1),1));
IT it2=s.lower_bound(make_pair(make_pair(in3,n+1),1));
it1--,it2--;
ll o=it1->first.first,p=it2->first.second;
bool o1=it1->second,o2=it2->second;
if(o1==1&&it1->first.first==in2&&in2!=1)it1--,o1=0,o=it1->first.first;
if(o2==1&&it2->first.second==in3&&in3!=n-1)it2++,o2=0,p=it2->first.second;
if(o1==0)in2=o;
if(o2==0)in3=p;
it2++;
s.erase(it1,it2);
s.insert(make_pair(make_pair(in2,in3),0));
if(o<in2)s.insert(make_pair(make_pair(o,in2-1),1));
if(p>in3)s.insert(make_pair(make_pair(in3+1,p),1));
}
if(in1==3){
read(in2),read(in3);
if(in2>in3)swap(in2,in3);
if(in2==in3){
puts("1");
continue;
}
IT it=s.lower_bound(make_pair(make_pair(in2,n+1),1));
it--;
if(it->second==1&&it->first.second>=in3-1)puts("1");
else puts("0");
}
if(in1==4){
read(in2);
IT it=s.lower_bound(make_pair(make_pair(in2,n+1),1));
it--;
if(it->second==1)printf("%lld\n",it->first.second-it->first.first+2);
else{
if(in2!=1&&it->first.first==in2){
it--;
printf("%lld\n",it->first.second-it->first.first+2);
}
else puts("1");
}
}
// for(IT it=s.begin();it!=s.end();it++){
// cout<<it->first.first<<' '<<it->first.second<<' '<<it->second<<endl;
// }
}
return 0;
}