結果
問題 | No.2292 Interval Union Find |
ユーザー | lgswdn |
提出日時 | 2023-05-08 16:04:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 352 ms / 5,000 ms |
コード長 | 2,416 bytes |
コンパイル時間 | 1,811 ms |
コンパイル使用メモリ | 202,848 KB |
実行使用メモリ | 125,152 KB |
最終ジャッジ日時 | 2024-05-04 01:49:51 |
合計ジャッジ時間 | 15,553 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 87 ms
6,948 KB |
testcase_05 | AC | 87 ms
8,216 KB |
testcase_06 | AC | 87 ms
6,944 KB |
testcase_07 | AC | 91 ms
7,992 KB |
testcase_08 | AC | 336 ms
76,792 KB |
testcase_09 | AC | 331 ms
76,772 KB |
testcase_10 | AC | 336 ms
75,080 KB |
testcase_11 | AC | 334 ms
73,412 KB |
testcase_12 | AC | 342 ms
77,572 KB |
testcase_13 | AC | 278 ms
60,208 KB |
testcase_14 | AC | 298 ms
68,184 KB |
testcase_15 | AC | 333 ms
71,096 KB |
testcase_16 | AC | 309 ms
66,728 KB |
testcase_17 | AC | 349 ms
77,144 KB |
testcase_18 | AC | 122 ms
64,868 KB |
testcase_19 | AC | 350 ms
124,004 KB |
testcase_20 | AC | 352 ms
125,152 KB |
testcase_21 | AC | 297 ms
102,756 KB |
testcase_22 | AC | 288 ms
102,824 KB |
testcase_23 | AC | 325 ms
103,252 KB |
testcase_24 | AC | 311 ms
103,076 KB |
testcase_25 | AC | 316 ms
102,920 KB |
testcase_26 | AC | 324 ms
102,676 KB |
testcase_27 | AC | 305 ms
102,292 KB |
testcase_28 | AC | 292 ms
103,284 KB |
testcase_29 | AC | 289 ms
102,772 KB |
testcase_30 | AC | 293 ms
102,484 KB |
testcase_31 | AC | 305 ms
103,496 KB |
testcase_32 | AC | 303 ms
103,076 KB |
testcase_33 | AC | 314 ms
102,180 KB |
testcase_34 | AC | 291 ms
103,848 KB |
testcase_35 | AC | 286 ms
102,292 KB |
testcase_36 | AC | 288 ms
104,052 KB |
testcase_37 | AC | 289 ms
102,344 KB |
testcase_38 | AC | 309 ms
103,108 KB |
testcase_39 | AC | 310 ms
102,416 KB |
testcase_40 | AC | 291 ms
103,924 KB |
testcase_41 | AC | 18 ms
6,940 KB |
testcase_42 | AC | 20 ms
6,944 KB |
testcase_43 | AC | 25 ms
6,940 KB |
testcase_44 | AC | 48 ms
6,944 KB |
testcase_45 | AC | 52 ms
6,940 KB |
testcase_46 | AC | 51 ms
6,940 KB |
testcase_47 | AC | 65 ms
6,944 KB |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define fi first #define se second #define eb emplace_back #define popc __builtin_popcount using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<pii> vp; typedef unsigned long long ull; typedef long double ld; int read() { int x=0,w=1; char c=getchar(); while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();} while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} return x*w; } const int N=4e5+9,lim=1e9; int n,m; namespace SegT { int ls[N<<5],rs[N<<5],tag[N<<5],s[N<<5],tot=1; void set(int p,int l,int r,int t) { if(t==0) s[p]=0, tag[p]=0; else if(t==1) s[p]=r-l+1, tag[p]=1; } void psd(int p,int l,int r) { int mid=l+r>>1; if(!ls[p]) ls[p]=++tot; tag[ls[p]]=tag[p], set(ls[p],l,mid,tag[p]); if(!rs[p]) rs[p]=++tot; tag[rs[p]]=tag[p], set(rs[p],mid+1,r,tag[p]); tag[p]=-1; } void cov(int p,int l,int r,int x,int y,int t) { if(l==x&&r==y) {set(p,l,r,t); return;} int mid=l+r>>1; if(tag[p]!=-1) psd(p,l,r); if(y<=mid) cov(ls[p],l,mid,x,y,t); else if(x>mid) cov(rs[p],mid+1,r,x,y,t); else cov(ls[p],l,mid,x,mid,t), cov(rs[p],mid+1,r,mid+1,y,t); s[p]=s[ls[p]]+s[rs[p]]; } int ql(int p,int l,int r,int x) { //max pos0 <=x if(s[p]==r-l+1) return -1; if(s[p]==0) return x; int mid=l+r>>1; if(tag[p]!=-1) psd(p,l,r); if(x<=mid) return ql(ls[p],l,mid,x); else { int res=ql(rs[p],mid+1,r,x); return res>=0?res:ql(ls[p],l,mid,mid); } } int qr(int p,int l,int r,int x) { //min pos0 >=x if(s[p]==r-l+1) return n+1; if(s[p]==0) return x; int mid=l+r>>1; if(tag[p]!=-1) psd(p,l,r); if(x>mid) return qr(rs[p],mid+1,r,x); else { int res=qr(ls[p],l,mid,x); return res<=n?res:qr(rs[p],mid+1,r,mid+1); } } } signed main() { n=read(), m=read(); while(m--) { int opt=read(); if(opt==1) { int l=read(), r=read(); SegT::cov(1,0,n,l,r-1,1); } else if(opt==2) { int l=read(), r=read(); SegT::cov(1,0,n,l,r-1,0); } else if(opt==3) { int x=read(), y=read(); if(x>y) swap(x,y); int rp=SegT::qr(1,0,n,x); printf("%d\n",rp>=y); } else { int x=read(); int lp=SegT::ql(1,0,n,x-1), rp=SegT::qr(1,0,n,x); printf("%d\n",rp-lp); } } return 0; }