結果

問題 No.1788 Same Set
ユーザー 👑 tute7627tute7627
提出日時 2021-11-14 10:42:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,297 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 206,428 KB
実行使用メモリ 11,720 KB
最終ジャッジ日時 2023-10-11 23:17:45
合計ジャッジ時間 13,298 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,716 KB
testcase_01 AC 3 ms
4,532 KB
testcase_02 AC 3 ms
4,652 KB
testcase_03 AC 3 ms
4,752 KB
testcase_04 AC 2 ms
4,532 KB
testcase_05 AC 3 ms
4,720 KB
testcase_06 AC 4 ms
4,672 KB
testcase_07 AC 3 ms
4,716 KB
testcase_08 AC 3 ms
4,652 KB
testcase_09 RE -
testcase_10 AC 2 ms
4,652 KB
testcase_11 AC 109 ms
11,180 KB
testcase_12 AC 263 ms
11,180 KB
testcase_13 AC 320 ms
11,064 KB
testcase_14 AC 423 ms
11,448 KB
testcase_15 AC 496 ms
11,448 KB
testcase_16 AC 530 ms
11,472 KB
testcase_17 RE -
testcase_18 AC 501 ms
11,516 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
権限があれば一括ダウンロードができます

ソースコード

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 = 200005;
  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