結果

問題 No.1965 Heavier
ユーザー KudeKude
提出日時 2022-06-03 22:04:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,739 bytes
コンパイル時間 2,756 ms
コンパイル使用メモリ 234,360 KB
実行使用メモリ 10,396 KB
最終ジャッジ日時 2023-10-21 01:52:57
合計ジャッジ時間 6,696 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 96 ms
10,396 KB
testcase_07 AC 97 ms
10,396 KB
testcase_08 AC 161 ms
10,396 KB
testcase_09 AC 170 ms
10,396 KB
testcase_10 AC 162 ms
10,396 KB
testcase_11 AC 167 ms
10,396 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 170 ms
10,396 KB
testcase_16 AC 162 ms
10,396 KB
testcase_17 AC 95 ms
9,364 KB
testcase_18 AC 153 ms
10,360 KB
testcase_19 AC 107 ms
10,288 KB
testcase_20 AC 111 ms
10,360 KB
testcase_21 AC 101 ms
10,144 KB
testcase_22 AC 98 ms
10,096 KB
testcase_23 AC 62 ms
7,140 KB
testcase_24 AC 80 ms
9,868 KB
testcase_25 AC 103 ms
10,396 KB
testcase_26 AC 102 ms
10,396 KB
testcase_27 AC 93 ms
10,396 KB
testcase_28 AC 94 ms
10,396 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) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
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 = 2001001001;

int op1(int x, int y) { return max(x, y); }
int e1() { return -INF; }

int op2(int x, int y) { return min(x, y); }
int e2() { return INF; }

} 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];
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    return b[i] < b[j];
  });
  segtree<int, op1, e1> seg1(n);
  segtree<int, op2, e2> seg2(n);
  VI evs(n + 2, -1);
  for(int i: ord) {
    int l = seg1.min_left(i, [&](int x) { return x < a[i] - b[i]; });
    int r = seg2.max_right(i + 1, [&](int x) { return x > a[i] + b[i]; });
    chmax(evs[i + 1], l);
    chmax(evs[r + 1], i + 1);
    seg1.set(i, a[i] - b[i]);
    seg2.set(i, a[i] + b[i]);
  }
  ll ans = 0;
  int mnl = 0;
  for(int i = 1; i <= n; i++) {
    chmax(mnl, evs[i]);
    int cnt = i - mnl;
    if (cnt > 1) ans += cnt - 1;
  }
  cout << ans << '\n';
}
0