結果
問題 | No.1000 Point Add and Array Add |
ユーザー | Haar |
提出日時 | 2020-02-28 21:44:15 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 342 ms / 2,000 ms |
コード長 | 4,295 bytes |
コンパイル時間 | 2,251 ms |
コンパイル使用メモリ | 210,720 KB |
実行使用メモリ | 10,568 KB |
最終ジャッジ日時 | 2024-10-13 17:10:55 |
合計ジャッジ時間 | 6,754 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 3 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 4 ms
5,248 KB |
testcase_13 | AC | 3 ms
5,248 KB |
testcase_14 | AC | 5 ms
5,248 KB |
testcase_15 | AC | 4 ms
5,248 KB |
testcase_16 | AC | 220 ms
9,896 KB |
testcase_17 | AC | 197 ms
6,784 KB |
testcase_18 | AC | 315 ms
10,368 KB |
testcase_19 | AC | 316 ms
10,300 KB |
testcase_20 | AC | 342 ms
10,496 KB |
testcase_21 | AC | 256 ms
10,568 KB |
testcase_22 | AC | 341 ms
10,368 KB |
testcase_23 | AC | 269 ms
10,300 KB |
ソースコード
#include <bits/stdc++.h> using i32 = int_fast32_t; using i64 = int_fast64_t; using u32 = uint_fast32_t; using u64 = uint_fast64_t; using f64 = double; using f80 = long double; #define FOR(v, a, b) for(i64 v = (a); v < (b); ++v) #define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v) #define REP(v, n) FOR(v, 0, n) #define REPE(v, n) FORE(v, 0, n) #define REV(v, a, b) for(i64 v = (a); v >= (b); --v) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it) #define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it) #define EXIST(c,x) ((c).find(x) != (c).end()) #define fst first #define snd second #define UNIQ(v) (v).erase(unique(ALL(v)), (v).end()) #define bit(i) (1LL<<(i)) #ifdef DEBUG #include <Mylib/Debug/debug.cpp> #else #define dump(...) ((void)0) #endif using namespace std; template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;} template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;} template <typename T> void puts_all(const T &value){std::cout << value << "\n";} template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);} template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);} template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);} template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);} template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));} struct Init{ Init(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); cerr << fixed << setprecision(12); } }init; template <typename Monoid> class DualSegmentTree{ using value_type = typename Monoid::value_type; private: const int depth, size, hsize; std::vector<value_type> data; inline void propagate(int i){ if(i < hsize){ data[i << 1 | 0] = Monoid::op(data[i], data[i << 1 | 0]); data[i << 1 | 1] = Monoid::op(data[i], data[i << 1 | 1]); data[i] = Monoid::id(); } } inline void propagate_top_down(int i){ std::vector<int> temp; while(i > 1){ i >>= 1; temp.push_back(i); } for(auto it = temp.rbegin(); it != temp.rend(); ++it) propagate(*it); } public: DualSegmentTree(int n): depth(n > 1 ? 32-__builtin_clz(n-1) + 1 : 1), size((1 << depth) - 1), hsize(size / 2 + 1), data(size + 1, Monoid::id()) {} inline void update(int l, int r, const value_type &x){ propagate_top_down(l + hsize); propagate_top_down(r + hsize); int L = l + hsize; int R = r + hsize; while(L < R){ if(R & 1) --R, data[R] = Monoid::op(x, data[R]); if(L & 1) data[L] = Monoid::op(x, data[L]), ++L; L >>= 1, R >>= 1; } } inline value_type get(int i){ propagate_top_down(i + hsize); return data[i + hsize]; } template <typename T> inline void init_with_vector(const std::vector<T> &a){ data.assign(size + 1, Monoid::id()); for(int i = 0; i < (int)a.size(); ++i) data[hsize + i] = a[i]; } template <typename T> inline void init(const T &val){ init_with_vector(std::vector<value_type>(hsize, val)); } auto debug(){ return data; } }; template <typename T> struct SumMonoid{ using value_type = T; constexpr inline static value_type id(){return 0;} constexpr inline static value_type op(const value_type &a, const value_type &b){return a + b;} }; int main(){ int N, Q; while(cin >> N >> Q){ vector<i64> A(N); cin >> A; DualSegmentTree<SumMonoid<i64>> seg(N); vector<i64> B(N); while(Q--){ char c; cin >> c; int x, y; cin >> x >> y; if(c == 'A'){ --x; B[x] += seg.get(x) * A[x]; seg.update(x, x+1, -seg.get(x)); A[x] += y; }else{ seg.update(x-1, y, 1); } } REP(i,N){ B[i] += seg.get(i) * A[i]; } join(cout, ALL(B)); } return 0; }