結果

問題 No.1000 Point Add and Array Add
ユーザー batsumarubatsumaru
提出日時 2020-02-28 23:36:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 1,993 ms
コンパイル使用メモリ 168,604 KB
実行使用メモリ 17,536 KB
最終ジャッジ日時 2024-04-21 20:57:16
合計ジャッジ時間 5,693 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 189 ms
13,184 KB
testcase_17 AC 159 ms
12,320 KB
testcase_18 AC 273 ms
17,408 KB
testcase_19 AC 256 ms
17,536 KB
testcase_20 AC 247 ms
17,280 KB
testcase_21 AC 259 ms
17,228 KB
testcase_22 AC 256 ms
17,380 KB
testcase_23 AC 254 ms
17,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

// 1-indexed
class BIT {
 public:
  vector<ll> bit;
  ll M;

  BIT(ll M) : bit(vector<ll>(M + 1, 0)), M(M) {}

  // a[1] + a[2] + ... + a[i]を求める
  ll sum(ll i) {
    if (i == 0) return 0;
    return bit[i] + sum(i - (i & -i));
  }
  // a[i] += x
  void add(ll i, ll x) {
    if (i > M) return;
    bit[i] += x;
    add(i + (i & -i), x);
  }
};

int main() {
  ll n, q;
  cin >> n >> q;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }
  // 1-indexed
  vector<ll> b(n + 1, 0);
  vector<pair<string, P>> sxy(q);
  REP(i, q) {
    string s;
    ll x, y;
    cin >> sxy[i].first >> sxy[i].second.first >> sxy[i].second.second;
  }
  BIT bit(n);
  IREP(i, q) {
    string s = sxy[i].first;
    ll x = sxy[i].second.first;
    ll y = sxy[i].second.second;
    if (s == "A") {
      b[x] += y * (bit.sum(x));
    } else {
      bit.add(x, 1);
      if (y + 1 <= n) bit.add(y + 1, -1);
    }
  }
  REP(i, n) { b[i + 1] += a[i] * (bit.sum(i + 1)); }
  REP(i, n) { cout << b[i + 1] << " \n"[i == n - 1]; }
}
0