結果

問題 No.2421 entersys?
ユーザー umezoumezo
提出日時 2023-08-12 15:30:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,902 bytes
コンパイル時間 4,891 ms
コンパイル使用メモリ 269,532 KB
実行使用メモリ 122,664 KB
最終ジャッジ日時 2024-04-30 09:37:43
合計ジャッジ時間 35,237 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
26,696 KB
testcase_01 AC 20 ms
26,784 KB
testcase_02 AC 23 ms
27,256 KB
testcase_03 AC 19 ms
26,716 KB
testcase_04 AC 20 ms
26,884 KB
testcase_05 WA -
testcase_06 AC 22 ms
27,024 KB
testcase_07 AC 22 ms
27,016 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 21 ms
27,036 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template <typename X,typename M>
struct SegTreeLazy {
  using FX=function<X(X,X)>;
  using FA=function<X(X,M)>;
  using FM=function<M(M,M)>;
  int n;
  FX fx;
  FA fa;
  FM fm;
  const X ex;
  const M em;
  vector<X> dat;
  vector<M> lazy;
  SegTreeLazy(int n_,FX fx_,FA fa_,FM fm_,X ex_,M em_)
    : n(),fx(fx_),fa(fa_),fm(fm_),ex(ex_),em(em_),dat(n_*4,ex),lazy(n_*4,em) {
    int x=1;
    while (n_ > x) x*=2;
    n=x;
  }
  void set(int i,X x){dat[i+n-1]=x;}
  void build(){
    for(int k=n-2;k>=0;k--) dat[k]=fx(dat[2*k+1],dat[2*k+2]);
  }

  void eval(int k){
    if(lazy[k]==em) return; 
    if(k<n-1){           
      lazy[k*2+1]=fm(lazy[k*2+1],lazy[k]);
      lazy[k*2+2]=fm(lazy[k*2+2],lazy[k]);
    }
    dat[k]=fa(dat[k],lazy[k]);
    lazy[k]=em;
  }
  void update(int a,int b,M x,int k,int l,int r){
    eval(k);
    if(a<=l && r<=b){ 
      lazy[k]=fm(lazy[k],x);
      eval(k);
    }else if(a<r && l<b){
      update(a,b,x,k*2+1,l,(l+r)/2);
      update(a,b,x,k*2+2,(l+r)/2,r);
      dat[k]=fx(dat[k*2+1],dat[k*2+2]);
    }
  }
  void update(int a,int b,M x){update(a,b,x,0,0,n);}
  X query_sub(int a,int b,int k,int l,int r){
    eval(k);
    if(r<=a || b<=l) return ex;
    else if(a<=l && r<=b) return dat[k];
    else{ 
      X vl=query_sub(a,b,k*2+1,l,(l+r)/2);
      X vr=query_sub(a,b,k*2+2,(l+r)/2,r);
      return fx(vl,vr);
    }
  }
  X query(int a,int b){return query_sub(a,b,0,0,n);}
};

Tree<int> A[100100];
set<int> B[100100];
set<int> AA[100100];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n;
  cin>>n;
  vector<string> X(n);
  vector<int> L(n),R(n);
  map<string,int> m;
  int now=0;
  set<int> s;
  rep(i,n){
    cin>>X[i]>>L[i]>>R[i];
    if(!m.count(X[i])){
      m[X[i]]=now;
      now++;
    }
    s.insert(L[i]);
    s.insert(R[i]);
    A[m[X[i]]].insert(L[i]);
    A[m[X[i]]].insert(R[i]);
    B[m[X[i]]].insert(R[i]);
    AA[m[X[i]]].insert(L[i]);
    AA[m[X[i]]].insert(R[i]);
  }
  
  int q;
  cin>>q;
  vector<int> c(q),x(q),t(q,-1),l(q,-1),r(q,-1);
  rep(i,q){
    int d;
    cin>>d;
    c[i]=d;
    if(d==1){
      string e; 
      int f;
      cin>>e>>f;
      if(!m.count(e)){
        m[e]=now;
        now++;
      }
      x[i]=m[e],t[i]=f;
      s.insert(f);
    }
    else if(d==2){
      int e;
      cin>>e;
      t[i]=e;
      s.insert(e);
    }
    else{
      string e;
      int f,g;
      cin>>e>>f>>g;
      if(!m.count(e)){
        m[e]=now;
        now++;
      }
      x[i]=m[e],l[i]=f,r[i]=g;
      s.insert(f);
      s.insert(g);
      A[i].insert(f);
      A[i].insert(g);
      AA[i].insert(f);
      AA[i].insert(g);
    }
  }
  
  map<int,int> m1;
  now=0;
  for(auto p:s){
    m1[p]=now;
    now++;
  }
    
  using XX=int;
  using M=int;
  auto fx=[](XX x1,XX x2) -> XX { return max(x1,x2);};
  auto fa=[](XX x,M m) -> XX { return x+m;};
  auto fm=[](M m1,M m2) -> M { return m1+m2;};
  XX ex=0;
  M em=0;
  SegTreeLazy<XX,M> seg(200200,fx,fa,fm,ex,em);
  
  rep(i,n){
    seg.update(m1[L[i]],m1[R[i]]+1,1);
  }
  
  rep(i,q){
    if(c[i]==1){
      auto d=A[x[i]].order_of_key(t[i]);
      if(d%2==0){
        d++;
        if(AA[x[i]].count(t[i]) && B[x[i]].count(*A[x[i]].find_by_order(d))) cout<<"Yes\n";
        else cout<<"No\n";
      }
      else{
        if(B[x[i]].count(*A[i].find_by_order(d))) cout<<"Yes\n";
        else cout<<"No\n";
      }
    }
    else if(c[i]==2){
      cout<<seg.query(m1[t[i]],m1[t[i]]+1)<<endl;
    }
    else{
      seg.update(m1[l[i]],m1[r[i]]+1,1);
      B[x[i]].insert(r[i]);
    }
  }

  return 0;
}
0