結果

問題 No.1788 Same Set
ユーザー 👑 tute7627tute7627
提出日時 2021-12-01 22:13:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,034 bytes
コンパイル時間 3,683 ms
コンパイル使用メモリ 219,692 KB
実行使用メモリ 12,940 KB
最終ジャッジ日時 2023-10-11 23:19:51
合計ジャッジ時間 10,252 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,560 KB
testcase_01 AC 4 ms
6,312 KB
testcase_02 AC 4 ms
6,292 KB
testcase_03 AC 4 ms
6,336 KB
testcase_04 AC 4 ms
6,156 KB
testcase_05 AC 4 ms
6,192 KB
testcase_06 AC 4 ms
6,320 KB
testcase_07 AC 4 ms
6,188 KB
testcase_08 AC 4 ms
6,240 KB
testcase_09 AC 4 ms
6,196 KB
testcase_10 AC 4 ms
6,272 KB
testcase_11 AC 65 ms
8,532 KB
testcase_12 AC 73 ms
8,868 KB
testcase_13 AC 81 ms
8,692 KB
testcase_14 AC 96 ms
8,696 KB
testcase_15 AC 123 ms
8,684 KB
testcase_16 AC 188 ms
8,532 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

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];
  vector<int>c(n);
  const int sz = 400005;
  vector<int> pre_a(sz, -1), pre_b(sz, -1);
  long long ans = 0;
  int csum = 0;
  for(int i = 0; i < n; i++){
    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]);
      for(int i = l + 1; i < r + 1; i++){
        c[i]--;
        if(c[i] == 0)csum--;
      }
    }
    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]);
      for(int i = l + 1; i < r + 1; i++){
        if(c[i] == 0)csum++;
        c[i]++;
      }
    }
    ans += i + 1 - csum;
  }
  cout << ans << endl;
}
0