結果

問題 No.3164 [Chery 7th Tune B] La vie en rose
ユーザー pengin_2000
提出日時 2025-05-30 23:02:57
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 25,216 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-05-30 23:03:09
合計ジャッジ時間 8,658 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%lld", &n);
      |         ^~~~~~~~~~~~~~~~~
main.c:10:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |                 scanf("%lld", &a[i]);
      |                 ^~~~~~~~~~~~~~~~~~~~
main.c:25:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%lld", &q);
      |         ^~~~~~~~~~~~~~~~~
main.c:28:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |                 scanf("%lld %lld", &x, &b);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
long long int a[300005];
long long int sum[300005];
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int i;
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	sum[0] = a[0];
	for (i = 1; i < n; i++)
	{
		if (a[i] > 0)
			sum[i] = sum[i - 1] + a[i];
		else
			sum[i] = 0;
	}
	for (i = n - 2; i >= 0; i--)
	{
		if (sum[i + 1] > 0 && sum[i] > 0)
			sum[i] = sum[i + 1];
	}
	long long int q, x, b;
	scanf("%lld", &q);
	for (; q > 0; q--)
	{
		scanf("%lld %lld", &x, &b);
		x--;
		b -= a[x];
		if (n == 1)
		{
			printf("%lld\n", a[0] + b);
			continue;
		}
		if (a[x] > 0)
			printf("%lld\n", sum[x] + b);
		else if (x == 0)
			printf("%lld\n", sum[x + 1] + b);
		else if (x == n - 1)
			printf("%lld\n", sum[x - 1] + b);
		else
			printf("%lld\n", sum[x + 1] + sum[x - 1] + b);
	}
	return 0;
}
0