結果

問題 No.2421 entersys?
ユーザー Nzt3Nzt3
提出日時 2023-08-14 23:59:20
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 674 ms / 3,000 ms
コード長 3,586 bytes
コンパイル時間 3,086 ms
コンパイル使用メモリ 237,968 KB
実行使用メモリ 36,544 KB
最終ジャッジ日時 2024-11-23 01:41:37
合計ジャッジ時間 15,761 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/lazysegtree>
using namespace std;
using ll=long long;

struct query{
  int t=-2;
  string name="";
  int l=-1,r=-1,q_time=-1;
};

int segtree_op(int a,int b){
  return a+b;
}
int segtree_e(){
  return 0;
}
int segtree_add(int a,int b){
  return a+b;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector<pair<string,array<int,2>>> base_info(N);
  vector<int>time_comp;
  for(auto &i:base_info){
    cin>>i.first>>i.second[0]>>i.second[1];
    time_comp.push_back(i.second[0]);
    time_comp.push_back(i.second[1]);
  }
  int Q;
  cin>>Q;
  vector<query>Query_list;
  
  for(int i=0;i<Q;i++){
    int T;
    cin>>T;
    query a;
    a.t=T;
    if(T==1){
      cin>>a.name;
      cin>>a.q_time;
      time_comp.push_back(a.q_time);
    }else if(T==2){
      cin>>a.q_time;
      time_comp.push_back(a.q_time);
    }else{
      cin>>a.name;
      cin>>a.l>>a.r;
      time_comp.push_back(a.l);
      time_comp.push_back(a.r);
    }
    Query_list.push_back(a);
  }


  map<string,int>name2idx;
  for(int i=0;i<N;i++){
    string name=base_info[i].first;
    if(name2idx.find(name)==name2idx.end()){
      int x=name2idx.size();
      name2idx[name]=x;
    }
  }
  for(int i=0;i<Q;i++){
    string name=Query_list[i].name;
    if(name=="")continue;
    if(name2idx.find(name)==name2idx.end()){
      int x=name2idx.size();
      name2idx[name]=x;
    }
  }
  sort(time_comp.begin(),time_comp.end());
  time_comp.erase(unique(time_comp.begin(),time_comp.end()),time_comp.end());

  auto time2idx =[&](int n){
    return (int)(lower_bound(time_comp.begin(),time_comp.end(),n)-time_comp.begin());
  };

  // time / (0:i|1:check|2:out) / info_time(query index)
  vector<vector<array<int,3>>>human_timelist(name2idx.size());
  for(int i=0;i<N;i++){
    human_timelist[name2idx[base_info[i].first]].push_back({time2idx(base_info[i].second[0]),0,-1});
    human_timelist[name2idx[base_info[i].first]].push_back({time2idx(base_info[i].second[1]),2,-1});
  }
  for(int i=0;i<Q;i++){
    if(Query_list[i].t==1){
      human_timelist[name2idx[Query_list[i].name]].push_back({time2idx(Query_list[i].q_time),1,i});
    }else if(Query_list[i].t==3){
      human_timelist[name2idx[Query_list[i].name]].push_back({time2idx(Query_list[i].l),0,i});
      human_timelist[name2idx[Query_list[i].name]].push_back({time2idx(Query_list[i].r),2,i});
    }
  }

  vector<int>ans(Q);
  for(int i=0;i<name2idx.size();i++){
    int time_n=-2;
    sort(human_timelist[i].begin(),human_timelist[i].end());
    for(int j=0;j<human_timelist[i].size();j++){
      if(human_timelist[i][j][1]==1){
        if(time_n>=-1&&time_n<human_timelist[i][j][2]){
          ans[human_timelist[i][j][2]]=1;
        }else{
          ans[human_timelist[i][j][2]]=0;
        }
      }else if(human_timelist[i][j][1]==0){
        time_n=human_timelist[i][j][2];
      }else if(human_timelist[i][j][1]==2){
        time_n=-2;
      }
    }
  }
  atcoder::lazy_segtree<int,segtree_op,segtree_e,int,segtree_op,segtree_op,segtree_e> count_human((int)time_comp.size()+10);
  for(int i=0;i<N;i++){
    count_human.apply(time2idx(base_info[i].second[0]),time2idx(base_info[i].second[1])+1,1);
  }


  for(int i=0;i<Q;i++){
    auto q=Query_list[i]; 
    if(q.t==2){
      ans[i]=count_human.get(time2idx(q.q_time));
    }else if(q.t==3){
      count_human.apply(time2idx(q.l),time2idx(q.r)+1,1);
    }
  }
  for(int i=0;i<Q;i++){
    if(Query_list[i].t==1){
      cout<<(ans[i]?"Yes\n":"No\n");
    }else if(Query_list[i].t==2){
      cout<<ans[i]<<'\n';
    }
  }
}
0