結果
問題 |
No.2942 Sigma Music Game Level Problem
|
ユーザー |
![]() |
提出日時 | 2024-10-21 11:40:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 452 ms / 6,000 ms |
コード長 | 1,661 bytes |
コンパイル時間 | 1,561 ms |
コンパイル使用メモリ | 57,664 KB |
最終ジャッジ日時 | 2025-02-24 22:10:42 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:65:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 65 | scanf("%d%d%d", &n, &qn, &li); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:66:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 66 | for (int i = 0; i < n; i++) scanf("%d", as + i); | ~~~~~^~~~~~~~~~~~~~ main.cpp:78:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 78 | scanf("%d", &op); | ~~~~~^~~~~~~~~~~ main.cpp:83:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 83 | scanf("%d", &l); | ~~~~~^~~~~~~~~~ main.cpp:90:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 90 | scanf("%d%d", &l, &r); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:98:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 98 | scanf("%d", &m); | ~~~~~^~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 2942.cc: No.2942 Sigma Music Game Level Problem - yukicoder */ #include<cstdio> #include<vector> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 1000000; const int MAX_M = 200000; /* typedef */ using ll = long long; template <typename T> struct BIT { int n; vector<T> bits; BIT() {} BIT(int _n) { init(_n); } void init(int _n) { n = _n; bits.assign(n + 1, 0); } T sum(int x) { x = min(x, n); T s = 0; while (x > 0) { s += bits[x]; x -= (x & -x); } return s; } void add(int x, T v) { if (x <= 0) return; while (x <= n) { bits[x] += v; x += (x & -x); } } }; /* global variables */ int as[MAX_N]; BIT<int> bit0; BIT<ll> bit1; /* subroutines */ /* main */ int main() { int n, qn, li; scanf("%d%d%d", &n, &qn, &li); for (int i = 0; i < n; i++) scanf("%d", as + i); bit0.init(MAX_M + 1); bit1.init(MAX_M + 1); for (int i = 0; i < n; i++) { bit0.add(as[i] + 1, 1); bit1.add(as[i] + 1, as[i]); } int qcs[3] = {0, 0, 0}; while (qn--) { int op; scanf("%d", &op); qcs[op - 1]++; if (op == 1) { int l; scanf("%d", &l); bit0.add(l + 1, 1); bit1.add(l + 1, l); } else if (op == 2) { int l, r; scanf("%d%d", &l, &r); int c = bit0.sum(r + 1) - bit0.sum(l); ll s = bit1.sum(r + 1) - bit1.sum(l); printf("%d %lld\n", c, s); } else { int m; scanf("%d", &m); li = m; } } if (! qcs[1]) puts("Not Found!"); //printf(" %d %d %d\n", qcs[0], qcs[1], qcs[2]); return 0; }