結果

問題 No.1000 Point Add and Array Add
ユーザー tnakao0123tnakao0123
提出日時 2020-02-29 23:59:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,540 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 93,188 KB
実行使用メモリ 7,748 KB
最終ジャッジ日時 2024-04-21 21:58:26
合計ジャッジ時間 3,520 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 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 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 74 ms
7,296 KB
testcase_17 AC 58 ms
6,400 KB
testcase_18 AC 97 ms
7,748 KB
testcase_19 AC 99 ms
7,680 KB
testcase_20 AC 93 ms
7,620 KB
testcase_21 AC 100 ms
6,144 KB
testcase_22 AC 96 ms
7,628 KB
testcase_23 AC 100 ms
7,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1000.cc:  No.1000 Point Add and Array Add - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;

template <typename T, const int MAX_N>
struct BIT {
  int n;
  T bits[MAX_N + 1];
  
  BIT() {}
  BIT(int _n) { init(_n); }

  void init(int _n) {
    n = _n;
    memset(bits, 0, sizeof(bits));
  }

  T sum(int x) {
    T s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, T v) {
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }
};

/* global variables */

ll as[MAX_N], sbs[MAX_N];
BIT<int,MAX_N+1> bit;

/* subroutines */

/* main */

int main() {
  int n, q;
  scanf("%d%d", &n, &q);

  for (int i = 0; i < n; i++) scanf("%lld", as + i);

  bit.init(n + 1);
  
  while (q--) {
    char s[4];
    int x, y;
    scanf("%s%d%d", s, &x, &y);

    if (s[0] == 'A') {
      x--;
      as[x] += y;
      sbs[x] += (ll)y * bit.sum(x + 1);
    }
    else {
      bit.add(x, 1);
      bit.add(y + 1, -1);
    }
  }

  for (int i = 0; i < n; i++) {
    if (i) putchar(' ');
    printf("%lld", as[i] * bit.sum(i + 1) - sbs[i]);
  }
  putchar('\n');
  return 0;
}
0