結果

問題 No.1788 Same Set
ユーザー KudeKude
提出日時 2021-12-17 08:16:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 465 ms / 4,000 ms
コード長 1,798 bytes
コンパイル時間 3,175 ms
コンパイル使用メモリ 229,456 KB
実行使用メモリ 12,992 KB
最終ジャッジ日時 2023-10-12 09:21:12
合計ジャッジ時間 16,164 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,280 KB
testcase_01 AC 3 ms
6,212 KB
testcase_02 AC 4 ms
6,276 KB
testcase_03 AC 4 ms
6,192 KB
testcase_04 AC 4 ms
6,168 KB
testcase_05 AC 4 ms
6,144 KB
testcase_06 AC 4 ms
6,224 KB
testcase_07 AC 4 ms
6,384 KB
testcase_08 AC 4 ms
6,160 KB
testcase_09 AC 4 ms
6,228 KB
testcase_10 AC 4 ms
6,152 KB
testcase_11 AC 64 ms
12,788 KB
testcase_12 AC 177 ms
12,784 KB
testcase_13 AC 214 ms
12,832 KB
testcase_14 AC 288 ms
12,692 KB
testcase_15 AC 338 ms
12,824 KB
testcase_16 AC 360 ms
12,828 KB
testcase_17 AC 299 ms
12,824 KB
testcase_18 AC 344 ms
12,708 KB
testcase_19 AC 232 ms
12,764 KB
testcase_20 AC 79 ms
12,720 KB
testcase_21 AC 351 ms
12,708 KB
testcase_22 AC 418 ms
12,828 KB
testcase_23 AC 298 ms
12,856 KB
testcase_24 AC 339 ms
12,820 KB
testcase_25 AC 457 ms
12,760 KB
testcase_26 AC 465 ms
12,792 KB
testcase_27 AC 86 ms
12,992 KB
testcase_28 AC 420 ms
12,756 KB
testcase_29 AC 442 ms
12,712 KB
testcase_30 AC 88 ms
12,712 KB
testcase_31 AC 447 ms
12,760 KB
testcase_32 AC 395 ms
12,716 KB
testcase_33 AC 403 ms
12,764 KB
testcase_34 AC 408 ms
12,700 KB
testcase_35 AC 380 ms
12,788 KB
testcase_36 AC 392 ms
12,800 KB
testcase_37 AC 395 ms
12,712 KB
testcase_38 AC 411 ms
12,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) { a = max(a, b); }
template<class T> void chmin(T& a, const T& b) { a = min(a, b); }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

constexpr int INF = 1001001001;
struct S { int min = INF, cnt = 0; };
S op(S x, S y) {
  if (x.min == y.min) return {x.min, x.cnt + y.cnt};
  else if (x.min < y.min) return x;
  else return y;
}
S e() { return S(); }
int composition(int f, int g) { return f + g; }
int id() { return 0; }
S mapping(int f, S x) { return {x.min + f, x.cnt}; }

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  lazy_segtree<S, op, e, int, mapping, composition, id> seg(vector<S>(n, S{0, 1}));
  constexpr int MX = 400000;
  VI last_a(MX + 1, -1), last_b(MX + 1, -1);
  ll ans = 0;
  rep(i, n) {
    int x = a[i], y = b[i];
    if (last_a[x] < last_b[x]) seg.apply(last_a[x] + 1, last_b[x] + 1, -1);
    if (last_b[y] < last_a[y]) seg.apply(last_b[y] + 1, last_a[y] + 1, -1);
    if (x != y) {
      seg.apply(max(last_a[x], last_b[x]) + 1, i + 1, 1);
      seg.apply(max(last_a[y], last_b[y]) + 1, i + 1, 1);
    }
    last_a[x] = i;
    last_b[y] = i;
    auto [mn, cnt] = seg.prod(0, i + 1);
    if (mn == 0) ans += cnt;
  }
  cout << ans << '\n';
}
0