結果

問題 No.1788 Same Set
ユーザー 👑 tute7627tute7627
提出日時 2021-12-01 22:15:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 616 ms / 4,000 ms
コード長 1,297 bytes
コンパイル時間 2,461 ms
コンパイル使用メモリ 206,244 KB
実行使用メモリ 13,076 KB
最終ジャッジ日時 2023-10-11 23:19:21
合計ジャッジ時間 17,387 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,236 KB
testcase_01 AC 4 ms
6,304 KB
testcase_02 AC 4 ms
6,192 KB
testcase_03 AC 4 ms
6,260 KB
testcase_04 AC 4 ms
6,320 KB
testcase_05 AC 3 ms
6,304 KB
testcase_06 AC 4 ms
6,232 KB
testcase_07 AC 5 ms
6,244 KB
testcase_08 AC 5 ms
6,324 KB
testcase_09 AC 4 ms
6,164 KB
testcase_10 AC 4 ms
6,284 KB
testcase_11 AC 110 ms
12,876 KB
testcase_12 AC 265 ms
12,872 KB
testcase_13 AC 323 ms
12,900 KB
testcase_14 AC 427 ms
12,760 KB
testcase_15 AC 497 ms
12,744 KB
testcase_16 AC 532 ms
12,732 KB
testcase_17 AC 419 ms
12,792 KB
testcase_18 AC 501 ms
12,696 KB
testcase_19 AC 328 ms
12,796 KB
testcase_20 AC 166 ms
13,068 KB
testcase_21 AC 546 ms
13,040 KB
testcase_22 AC 561 ms
12,700 KB
testcase_23 AC 425 ms
12,828 KB
testcase_24 AC 458 ms
12,752 KB
testcase_25 AC 616 ms
12,852 KB
testcase_26 AC 608 ms
12,688 KB
testcase_27 AC 181 ms
12,764 KB
testcase_28 AC 608 ms
12,744 KB
testcase_29 AC 583 ms
12,876 KB
testcase_30 AC 182 ms
13,032 KB
testcase_31 AC 594 ms
12,848 KB
testcase_32 AC 517 ms
12,700 KB
testcase_33 AC 533 ms
12,852 KB
testcase_34 AC 547 ms
13,076 KB
testcase_35 AC 536 ms
12,692 KB
testcase_36 AC 536 ms
13,076 KB
testcase_37 AC 535 ms
12,748 KB
testcase_38 AC 545 ms
12,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct S{
  int min;
  int min_num;
};

S op(S l, S r){
  if(l.min == r.min){
    return S{l.min, l.min_num + r.min_num};
  }
  if(l.min < r.min)return l;
  else return r;
}

S e(){
  return S{998244353, 0};
}

S mapping(int l, S r){
  return S{r.min + l, r.min_num};
}

int composition(int l, int r){
  return l + r;
}

int id(){
  return 0;
}

int main(){
  int n;
  cin >> n;
  vector<int>a(n), b(n);
  for(int i = 0; i < n; i++)cin >> a[i];
  for(int i = 0; i < n; i++)cin >> b[i];
  atcoder::lazy_segtree<S, op, e, int, mapping, composition, id> seg(n + 1);
  const int sz = 400005;
  vector<int> pre_a(sz, -1), pre_b(sz, -1);
  long long ans = 0;
  seg.set(n, S{0, 0});
  for(int i = 0; i < n; i++){
    seg.set(i, S{0, 1});
    vector<int>upd;
    upd.push_back(a[i]);
    if(a[i] != b[i])upd.push_back(b[i]);
    for(auto val:upd){
      int l = min(pre_a[val], pre_b[val]);
      int r = max(pre_a[val], pre_b[val]);
      seg.apply(l + 1, r + 1, -1);
    }
    pre_a[a[i]] = i;
    pre_b[b[i]] = i;
    for(auto val:upd){
      int l = min(pre_a[val], pre_b[val]);
      int r = max(pre_a[val], pre_b[val]);
      seg.apply(l + 1, r + 1, 1);
    }
    ans += seg.all_prod().min_num;
  }
  cout << ans << endl;
}
0