結果

問題 No.2292 Interval Union Find
ユーザー lgswdnlgswdn
提出日時 2023-05-08 16:04:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,416 bytes
コンパイル時間 1,892 ms
コンパイル使用メモリ 201,548 KB
実行使用メモリ 103,404 KB
最終ジャッジ日時 2024-05-04 01:49:20
合計ジャッジ時間 20,216 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 84 ms
6,948 KB
testcase_05 AC 83 ms
6,944 KB
testcase_06 AC 85 ms
6,940 KB
testcase_07 AC 87 ms
8,500 KB
testcase_08 AC 314 ms
76,720 KB
testcase_09 AC 330 ms
76,760 KB
testcase_10 AC 326 ms
75,852 KB
testcase_11 AC 320 ms
73,040 KB
testcase_12 AC 331 ms
76,700 KB
testcase_13 AC 273 ms
60,732 KB
testcase_14 AC 322 ms
69,260 KB
testcase_15 AC 336 ms
71,776 KB
testcase_16 AC 302 ms
66,556 KB
testcase_17 AC 349 ms
75,272 KB
testcase_18 AC 129 ms
64,904 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 312 ms
101,248 KB
testcase_22 AC 305 ms
101,168 KB
testcase_23 AC 318 ms
101,372 KB
testcase_24 AC 313 ms
101,340 KB
testcase_25 AC 293 ms
101,216 KB
testcase_26 AC 295 ms
101,024 KB
testcase_27 AC 300 ms
101,200 KB
testcase_28 AC 297 ms
101,128 KB
testcase_29 AC 298 ms
101,564 KB
testcase_30 AC 287 ms
101,388 KB
testcase_31 AC 285 ms
101,228 KB
testcase_32 AC 293 ms
101,484 KB
testcase_33 AC 284 ms
101,308 KB
testcase_34 AC 317 ms
101,856 KB
testcase_35 AC 308 ms
101,264 KB
testcase_36 AC 305 ms
101,132 KB
testcase_37 AC 311 ms
101,084 KB
testcase_38 AC 309 ms
101,288 KB
testcase_39 AC 286 ms
101,248 KB
testcase_40 AC 303 ms
101,388 KB
testcase_41 AC 19 ms
6,940 KB
testcase_42 AC 19 ms
6,940 KB
testcase_43 AC 25 ms
6,944 KB
testcase_44 AC 53 ms
6,940 KB
testcase_45 AC 52 ms
6,940 KB
testcase_46 AC 53 ms
6,940 KB
testcase_47 AC 67 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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=2e5+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;
}
0