結果

問題 No.1496 不思議な数え上げ
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-04-01 01:33:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 978 ms / 3,000 ms
コード長 1,405 bytes
コンパイル時間 4,086 ms
コンパイル使用メモリ 207,932 KB
実行使用メモリ 13,704 KB
最終ジャッジ日時 2024-04-01 01:34:33
合計ジャッジ時間 41,640 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 924 ms
13,704 KB
testcase_04 AC 915 ms
13,704 KB
testcase_05 AC 932 ms
13,704 KB
testcase_06 AC 920 ms
13,704 KB
testcase_07 AC 898 ms
13,704 KB
testcase_08 AC 937 ms
13,704 KB
testcase_09 AC 960 ms
13,704 KB
testcase_10 AC 946 ms
13,704 KB
testcase_11 AC 978 ms
13,704 KB
testcase_12 AC 874 ms
13,704 KB
testcase_13 AC 920 ms
13,704 KB
testcase_14 AC 938 ms
13,704 KB
testcase_15 AC 928 ms
13,704 KB
testcase_16 AC 937 ms
13,704 KB
testcase_17 AC 912 ms
13,704 KB
testcase_18 AC 879 ms
13,704 KB
testcase_19 AC 880 ms
13,704 KB
testcase_20 AC 938 ms
13,704 KB
testcase_21 AC 933 ms
13,704 KB
testcase_22 AC 904 ms
13,704 KB
testcase_23 AC 931 ms
13,704 KB
testcase_24 AC 938 ms
13,704 KB
testcase_25 AC 857 ms
13,704 KB
testcase_26 AC 855 ms
13,704 KB
testcase_27 AC 920 ms
13,704 KB
testcase_28 AC 889 ms
13,704 KB
testcase_29 AC 914 ms
13,704 KB
testcase_30 AC 920 ms
13,704 KB
testcase_31 AC 896 ms
13,704 KB
testcase_32 AC 792 ms
12,912 KB
testcase_33 AC 416 ms
8,448 KB
testcase_34 AC 388 ms
8,192 KB
testcase_35 AC 9 ms
6,676 KB
testcase_36 AC 802 ms
12,976 KB
testcase_37 AC 451 ms
8,704 KB
testcase_38 AC 413 ms
8,448 KB
testcase_39 AC 580 ms
11,608 KB
testcase_40 AC 327 ms
7,808 KB
testcase_41 AC 612 ms
11,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace atcoder;
using namespace std;
using ll = long long;
ll INF = (1LL << 60);
ll op(ll a, ll b) {
	return min(a, b);
}
ll e() {
	return INF;
}
int main() {
	int N;cin >> N;
	vector<ll> P(N + 1, 0);
	vector<ll>A(N + 1, 0);
	for (int i = 1;i <= N;i++)cin >> P[i];
	for (int i = 1;i <= N;i++) cin >> A[i];
	vector<ll> S(N + 1, 0);
	for (int i = 1;i <= N;i++) S[i] = S[i - 1] + P[i];
	segtree<ll, op, e> seg(P);
	vector<ll> ans(N + 1, 0);
	for (int i = 1;i <= N;i++) {
		ll x = P[i];
		int ok = i;
		int ng = 0;
		while (ok - ng > 1) {
			int m = (ok + ng) / 2;
			if (seg.prod(m, i + 1) != x) {
				ng = m;
			} else {
				ok = m;
			}
		}
		int L = ok;
		ok = i;
		ng = N + 1;
		while (ng - ok > 1) {
			int m = (ok + ng) / 2;
			if (seg.prod(i, m + 1) != x) {
				ng = m;
			} else {
				ok = m;
			}
		}
		int R = ok;
		if (i - L >= R - i) {
			for (int j = i;j <= R;j++) {
				auto itr = lower_bound(S.begin(), S.end(), S[j] - A[x]);
				int t = itr - S.begin();
				if (t + 1 > i) continue;
				int st = max(t + 1, L);
				ans[x] += i - st + 1;
			}
		} else {
			for (int j = i;j >= L;j--) {
				auto itr = upper_bound(S.begin(), S.end(), S[j - 1] + A[x]);
				itr--;
				int t = itr - S.begin();
				if (t < i) continue;
				int ed = min(t, R);
				ans[x] += ed - i + 1;
			}
		}
	}
	for (int x = 1;x <= N;x++) cout << ans[x] << endl;
}
0