結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
noisy_noimin
|
| 提出日時 | 2020-02-28 21:58:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,161 bytes |
| コンパイル時間 | 1,339 ms |
| コンパイル使用メモリ | 123,616 KB |
| 最終ジャッジ日時 | 2025-01-09 02:44:57 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 19 WA * 1 RE * 2 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
{ 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
template<class T> class SegmentTree {
public:
typedef function<T(T, T)> F;
size_t n;
vector<T> data;
T def; // 単位元
T initial_value; // 初期値
F update_func; // 更新用関数
F find_func; //クエリ用関数
SegmentTree(size_t _n, T def, T initial_value, F update_func, F find_func)
: def(def), initial_value(initial_value), update_func(update_func), find_func(find_func) {
n = 1;
while(n < _n) n <<= 1;
data = vector<T>(2*n-1, initial_value);
}
void update(size_t i, T x) {
i += n-1;
data[i] = update_func(data[i], x);
while(i) {
i = (i-1) / 2;
data[i] = find_func(data[2*i+1], data[2*i+2]);
}
}
T find(size_t s, size_t t, size_t k, size_t kl, size_t kr) {
if(kr <= s || t <= kl) return initial_value;
if(s <= kl && kr <= t) return data[k];
size_t kc = (kl+kr) / 2;
T vl = find(s, t, 2*k+1, kl, kc);
T vr = find(s, t, 2*k+2, kc, kr);
return find_func(vl, vr);
}
T find(size_t s, size_t t) {
return find(s, t, 0, 0, n);
}
};
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<ll> a(n+1);
for(int i=1;i<=n;++i) {
cin >> a[i];
}
vector<vector<ll>> query(q+1, vector<ll>(3, 0));
char c;
vector<ll> b(n+1, 0);
{
vector<ll> qb_cnt(q+3, 0);
for(int i=1;i<=q;++i) {
cin >> c;
cin >> query[i][1] >> query[i][2];
if(c == 'B') {
query[i][0] = 1;
++qb_cnt[query[i][1]];
--qb_cnt[query[i][2]+1];
} else {
}
}
for(int i=1;i<=n;++i) qb_cnt[i] += qb_cnt[i-1];
for(int i=1;i<=n;++i) {
b[i] = qb_cnt[i] * a[i];
}
}
{
SegmentTree<ll> tree(
n+3, 0LL, 0LL,
[](unsigned int a, unsigned int b) { return a+b; },
[](unsigned int a, unsigned int b) { return a+b; }
);
for(int i=q;i>=1;--i) {
if(query[i][0] == 0) {
ll cnt = tree.find(0, query[i][1]+1);
b[query[i][1]] += cnt * query[i][2];
} else {
tree.update(query[i][1], 1);
tree.update(query[i][2]+1, -1);
}
}
}
cout << b[1];
for(int i=2;i<=n;++i) cout << " " << b[i];
cout << endl;
}
noisy_noimin