結果

問題 No.1698 Face to Face
ユーザー 👑 NachiaNachia
提出日時 2021-10-01 23:54:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,157 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 102,940 KB
実行使用メモリ 43,576 KB
最終ジャッジ日時 2023-09-26 23:27:58
合計ジャッジ時間 14,261 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 298 ms
41,968 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,376 KB
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 -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 2 ms
4,380 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 346 ms
43,248 KB
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <atcoder/segtree>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)


const int maxN = 100000;

namespace RQ{
  struct S { int Amax, Bmax, q, i; };
  S op(S l, S r){
    S res = {
      max(l.Amax,r.Amax),
      max(l.Bmax,r.Bmax),
      0,0
    };
    res.q = max(l.q,r.Bmax);
    res.i = l.i;
    if(res.q > max(l.Amax,r.q)){
      res.q = max(l.Amax,r.q);
      res.i = r.i;
    }
    return res;
  }
  S e(){ return { 0,0,maxN*2,0 }; }
  using RQ = atcoder::segtree<S,op,e>;
  RQ createRQ1(int N, const vector<int>& A, const vector<int>& B){
    vector<S> tmp(2*N-1);
    rep(i,N-1) tmp[2*i+1].Amax = max(A[i],A[i+1]);
    rep(i,N-1) tmp[2*i+1].Bmax = max(B[i],B[i+1]);
    rep(i,N-1) tmp[2*i+1].q = max(tmp[i].Amax, tmp[i].Bmax);
    rep(i,2*N-1) tmp[i].i = i/2;
    return RQ(tmp);
  }
  RQ createRQ2(int N, const vector<int>& A, const vector<int>& B){
    vector<S> tmp(2*N-1);
    rep(i,N-1) tmp[2*i+1].Bmax = max(A[i],A[i+1]);
    rep(i,N-1) tmp[2*i+1].Amax = max(B[i],B[i+1]);
    rep(i,N-1) tmp[2*i+1].q = max(tmp[i].Amax, tmp[i].Bmax);
    rep(i,2*N-1) tmp[i].i = i/2;
    return RQ(tmp);
  }
}


struct CompNode{
  int pos;
  int type;
  bool operator<(const CompNode& r) const {
    if(pos != r.pos) return pos < r.pos;
    return type < r.type;
  }
};

struct ValNode{
  int w;
  int cnt;
};


int main(){
  int N; cin >> N;
  vector<int> A(N); rep(i,N){ cin >> A[i]; A[i]--; }
  vector<int> B(N); rep(i,N){ cin >> B[i]; B[i]--; }
  vector<int> Z(N); rep(i,N){ cin >> Z[i]; Z[i]--; }
  vector<int> invA(N); rep(i,N) invA[A[i]] = i;
  vector<int> invB(N); rep(i,N) invB[B[i]] = i;

  map<CompNode, ValNode> G;
  rep(i,N+1) G[{i,0}] = {0,0};
  rep(i,N+1) G[{i,1}] = {0,0};
  for(int i=1; i<=N; i++) G[{i,0}].w += 1;

  auto rq1 = RQ::createRQ1(N,A,B);
  auto rq2 = RQ::createRQ2(N,A,B);
  vector<vector<int>> toAddCnt(N);
  rep(i,N){
    int za = invA[i], zb = invB[Z[i]];
    RQ::S q;
    if(za <= zb) q = rq1.prod(za*2, zb*2+1);
    else q = rq2.prod(zb*2, za*2+1);
    toAddCnt[q.q].push_back(q.i);
  }

  vector<vector<CompNode>> toEraseSep(N);
  rep(i,N-1) toEraseSep[max(A[i],A[i+1])].push_back({i+1,0});
  rep(i,N-1) toEraseSep[max(B[i],B[i+1])].push_back({i+1,1});

  int ans = 0;

  rep(i,N){
    for(auto s : toEraseSep[i]){
      auto itr = G.find(s);
      auto nxitr = itr; nxitr++;
      ans -= min(itr->second.cnt, itr->second.w);
      ans -= min(nxitr->second.cnt, nxitr->second.w);
      nxitr->second.cnt += itr->second.cnt;
      nxitr->second.w += itr->second.w;
      ans += min(nxitr->second.cnt, nxitr->second.w);
      G.erase(itr);
    }
    for(auto s : toAddCnt[i]){
      auto itr = G.upper_bound({s,2});
      ans -= min(itr->second.cnt, itr->second.w);
      itr->second.cnt += 1;
      ans += min(itr->second.cnt, itr->second.w);
    }
    cout << ans << endl;
  }

  return 0;
}




struct ios_do_not_sync {
    ios_do_not_sync() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0