結果

問題 No.1965 Heavier
ユーザー 👑 platinumplatinum
提出日時 2022-05-03 23:37:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,037 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 82,080 KB
実行使用メモリ 8,176 KB
最終ジャッジ日時 2023-09-16 20:22:54
合計ジャッジ時間 5,667 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 154 ms
4,616 KB
testcase_07 AC 155 ms
4,508 KB
testcase_08 AC 146 ms
8,176 KB
testcase_09 AC 162 ms
7,672 KB
testcase_10 AC 161 ms
7,660 KB
testcase_11 AC 161 ms
7,940 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 160 ms
7,672 KB
testcase_16 AC 159 ms
7,668 KB
testcase_17 AC 110 ms
5,524 KB
testcase_18 AC 162 ms
6,588 KB
testcase_19 AC 161 ms
6,248 KB
testcase_20 AC 166 ms
6,232 KB
testcase_21 AC 150 ms
5,488 KB
testcase_22 AC 147 ms
5,476 KB
testcase_23 AC 103 ms
4,380 KB
testcase_24 AC 129 ms
4,644 KB
testcase_25 AC 148 ms
8,036 KB
testcase_26 AC 144 ms
7,952 KB
testcase_27 AC 157 ms
6,688 KB
testcase_28 AC 157 ms
6,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <cassert>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int, int>;

const int Max_N = (int)2e5;
const int Max_A = (int)1e9;

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];

	assert(2 <= N && N <= Max_N);
	rep(i, N - 1) assert(A[i] < A[i + 1]);
	rep(i, N) assert(1 <= A[i] && A[i] <= Max_A);
	rep(i, N) assert(1 <= B[i] && B[i] <= Max_A);

	LL ans = 0;
	int l = -1, r = 0;
	priority_queue<P> q_dif, q_sum;

	while (r < N) {
		int d = A[r] - B[r], s = A[r] + B[r];
		while (!q_dif.empty()) {
			P p = q_dif.top();
			if (p.first >= d) {
				l = max(l, p.second);
				q_dif.pop();
			}
			else break;
		}
		while (!q_sum.empty()) {
			P p = q_sum.top();
			if (p.first >= s) {
				l = max(l, p.second);
				q_sum.pop();
			}
			else break;
		}
		ans += r - l - 1;
		q_dif.emplace(d, r), q_sum.emplace(s, r);
		r++;
	}
	cout << ans << endl;

	return 0;
}
0