結果

問題 No.2422 regisys?
ユーザー Nzt3
提出日時 2023-08-15 01:13:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 1,341 bytes
コンパイル時間 2,485 ms
コンパイル使用メモリ 213,424 KB
最終ジャッジ日時 2025-02-16 08:16:03
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N,M;
  cin>>N>>M;
  vector<array<int,3>>A(N);
  for(auto &i:A)cin>>i[0];
  for(auto &i:A)cin>>i[1];
  for(int i=0;i<N;i++)A[i][2]=i;
  sort(A.begin(),A.end());
  vector<int>p_A,p_B;
  for(int i=0;i<M;i++){
    int T,C;
    cin>>T>>C;
    if(T==1){
      p_B.push_back(C);
    }else{
      p_A.push_back(C);
    }
  }
  cerr<<"inout ok"<<endl;
  sort(p_A.begin(),p_A.end());
  sort(p_B.begin(),p_B.end());
  priority_queue<array<int,2>>pq1;
  vector<int>ans(N,1);
  for(int i=0,cnt=0;i<p_A.size();i++){
    while(cnt<N&&A[cnt][0]<=p_A[i]){
      pq1.push({A[cnt][1],A[cnt][2]});
      cnt+=1;
    }
    if(pq1.size()){
      int t=pq1.top()[1];
      pq1.pop();
      ans[t]=0;
    }
  }
  cerr<<"buy A ok"<<endl;
  sort(A.begin(),A.end(),[](array<int,3> a,array<int,3> b){
    return a[1]<b[1];
  });
  priority_queue<array<int,2>>pq2;
  for(int i=0,cnt=0;i<p_B.size();i++){
    while(cnt<N&&A[cnt][1]<=p_B[i]){
      pq2.push({A[cnt][1],A[cnt][2]});
      cnt+=1;
    }
    while(pq2.size()&&ans[pq2.top()[1]]==0){
      pq2.pop();
    }
    if(pq2.size()){
      int t=pq2.top()[1];
      pq2.pop();
      ans[t]=0;
    }
  }
  cerr<<"buy B ok"<<endl;
  cout<<accumulate(ans.begin(),ans.end(),0)<<'\n';
}
0