結果

問題 No.1496 不思議な数え上げ
ユーザー 👑 ygussanyygussany
提出日時 2021-04-30 23:18:53
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 537 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 28,548 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-26 08:19:19
合計ジャッジ時間 7,217 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
7,624 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 77 ms
4,376 KB
testcase_04 AC 78 ms
4,380 KB
testcase_05 AC 78 ms
4,380 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
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 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main()
{
	int i, j, k, l, r, N, P[200001], P_inv[200001];
	long long A, sum, ans;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(P[i]));
		P_inv[P[i]] = i;
	}
	for (i = 1; i <= N; i++) {
		scanf("%lld", &A);
		
		k = P_inv[i];
		ans = 0;
		for (r = k, sum = 0; r <= N && P[r] >= i; r++) sum += P[r];
		r--;
		for (l = k; l >= 1 && P[l] >= i; sum += P[--l]) {
			for (; r >= k && sum > A; sum -= P[r--]);
			if (r >= k) ans += r - k + 1;
		}
		printf("%lld\n", ans);
	}
	fflush(stdout);
	return 0;
}
0