結果
| 問題 |
No.2931 Shibuya 109
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-10-15 09:49:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 222 ms / 4,000 ms |
| コード長 | 783 bytes |
| コンパイル時間 | 461 ms |
| コンパイル使用メモリ | 41,216 KB |
| 最終ジャッジ日時 | 2025-02-24 19:46:05 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | scanf("%d%d", &n, &qn);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:29:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | for (int i = 0; i < n; i++) scanf("%d", as + i);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:39:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
39 | scanf("%d%d", &l, &r), l--;
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2931.cc: No.2931 Shibuya 109 - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 500000;
/* typedef */
/* global variables */
int as[MAX_N];
int ass[MAX_N + 1], ops[8];
/* subroutines */
/* main */
int main() {
int n, qn;
scanf("%d%d", &n, &qn);
for (int i = 0; i < n; i++) scanf("%d", as + i);
for (int i = 0; i < n; i++) ass[i + 1] = ass[i] + as[i] / 9;
int k = 0;
for (int i = 0; i < n; i++)
if (as[i] == 1) ops[k++] = i;
while (qn--) {
int l, r;
scanf("%d%d", &l, &r), l--;
int sum = (ass[r] - ass[l]);
for (int i = 0; i < k; i++)
if (l <= ops[i] && ops[i] < r) sum += r - (ops[i] + 1);
printf("%d\n", sum);
}
return 0;
}
tnakao0123