結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-28 22:44:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,137 bytes |
| コンパイル時間 | 1,550 ms |
| コンパイル使用メモリ | 170,564 KB |
| 実行使用メモリ | 13,640 KB |
| 最終ジャッジ日時 | 2024-10-13 18:34:49 |
| 合計ジャッジ時間 | 5,714 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 TLE * 1 -- * 7 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
template <class T>
struct fenwick_tree
{
int n;
std::vector<T> x;
fenwick_tree(int n_ = 0) : n(n_), x(n + 1, 0) {}
int size() const { return n; }
T sum(int r) const
{
T S = 0;
for (r = r - 1; r >= 0; r = (r & (r + 1)) - 1)
S += x[r];
return S;
}
T sum(int l, int r) const { return sum(r) - sum(l); }
void add(int k, const T &a)
{
for (; k < n; k |= k + 1)
x[k] += a;
}
void set(int k, const T &a) { add(k, a - sum(k, k + 1)); }
};
template <class T>
struct fenwick_tree_range
{
fenwick_tree<T> a, b;
fenwick_tree_range(int n = 0) : a(n), b(n) {}
int size() const { return a.size(); }
T sum(int r) const { return a.sum(r) + b.sum(r) * r; }
T sum(int l, int r) const { return sum(r) - sum(l); }
void add(int r, const T &x)
{
a.add(r, x * r);
b.add(r, -x);
}
void add(int l, int r, const T &x)
{
add(l, -x);
add(r, x);
}
};
int main()
{
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
ll N, Q;
cin >> N >> Q;
vector<ll> A(N);
fenwick_tree<ll> B(N);
rep(i, N) cin >> A[i];
rep(i, Q){
char c;
ll x, y;
cin >> c >> x >> y;
--x;
if(c == 'A') A[x] += y;
else{
--y;
for (ll j = x; j <= y; ++j){
B.add(j, A[j]);
}
}
}
rep(i,N){
ll x = B.sum(i, i + 1);
cout << x << " ";
}
return 0;
}