結果
| 問題 |
No.3164 [Chery 7th Tune B] La vie en rose
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-05-31 16:50:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 144 ms / 2,000 ms |
| コード長 | 927 bytes |
| コンパイル時間 | 741 ms |
| コンパイル使用メモリ | 40,960 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-05-31 16:51:00 |
| 合計ジャッジ時間 | 12,357 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 34 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:31:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | for (int i = 0; i < n; i++) scanf("%d", as + i);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:44:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
44 | scanf("%d", &qn);
| ~~~~~^~~~~~~~~~~
main.cpp:48:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | scanf("%d%d", &x, &b), x--;
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 3164.cc: No.3164 [Chery 7th Tune B] La vie en rose - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 300000;
/* typedef */
using ll = long long;
/* global variables */
int as[MAX_N];
ll ass[MAX_N];
/* subroutines */
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", as + i);
for (int i = 0; i < n;) {
while (i < n && as[i] == 0) i++;
if (i >= n) break;
int j = i;
ll s = 0;
while (i < n && as[i] > 0) s += as[i++];
while (j < i) ass[j++] = s;
}
int qn;
scanf("%d", &qn);
while (qn--) {
int x, b;
scanf("%d%d", &x, &b), x--;
ll s = ass[x] - as[x] + b;
if (as[x] == 0) {
if (x > 0 && as[x - 1] > 0) s += ass[x - 1];
if (x + 1 < n && as[x + 1] > 0) s += ass[x + 1];
}
printf("%lld\n", s);
}
return 0;
}
tnakao0123