結果
問題 | No.631 Noelちゃんと電車旅行 |
ユーザー | Haar |
提出日時 | 2019-12-22 14:34:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 297 ms / 2,000 ms |
コード長 | 4,998 bytes |
コンパイル時間 | 2,330 ms |
コンパイル使用メモリ | 209,920 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-10-02 09:44:18 |
合計ジャッジ時間 | 7,887 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 223 ms
5,248 KB |
testcase_01 | AC | 294 ms
8,192 KB |
testcase_02 | AC | 284 ms
8,192 KB |
testcase_03 | AC | 297 ms
8,064 KB |
testcase_04 | AC | 296 ms
8,064 KB |
testcase_05 | AC | 292 ms
7,936 KB |
testcase_06 | AC | 109 ms
5,632 KB |
testcase_07 | AC | 52 ms
5,760 KB |
testcase_08 | AC | 216 ms
7,936 KB |
testcase_09 | AC | 256 ms
5,504 KB |
testcase_10 | AC | 169 ms
8,064 KB |
testcase_11 | AC | 149 ms
5,888 KB |
testcase_12 | AC | 188 ms
8,064 KB |
testcase_13 | AC | 195 ms
5,248 KB |
testcase_14 | AC | 91 ms
5,248 KB |
testcase_15 | AC | 160 ms
5,248 KB |
testcase_16 | AC | 3 ms
5,248 KB |
testcase_17 | AC | 3 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> #define LLI long long int #define FOR(v, a, b) for(LLI v = (a); v < (b); ++v) #define FORE(v, a, b) for(LLI 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(LLI 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 popcount __builtin_popcount #define UNIQ(v) (v).erase(unique(ALL(v)), (v).end()) #define bit(i) (1LL<<(i)) #ifdef DEBUG #include <misc/C++/Debug.cpp> #else #define dump(...) ((void)0) #endif #define gcd __gcd using namespace std; template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;} 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, 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);} struct Init{ Init(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); cerr << fixed << setprecision(12); } }init; template <typename T, typename U, typename TFunc, typename UFunc, typename Op> class LazySegmentTree{ const int depth, size, hsize; const T e1; const TFunc f1; const U e2; const UFunc f2; const Op g; // g(T, U, int) -> T std::vector<T> data; std::vector<U> lazy; inline void propagate(int i, int l){ if(lazy[i] == e2) return; if(i < size/2){ lazy[i*2+1] = f2(lazy[i], lazy[i*2+1]); lazy[i*2+2] = f2(lazy[i], lazy[i*2+2]); } data[i] = g(data[i], lazy[i], l); lazy[i] = e2; } inline T update_aux(int i, int l, int r, int s, int t, const U &x){ propagate(i,r-l); if(r <= s || t <= l) return data[i]; else if(s <= l && r <= t){ lazy[i] = f2(x, lazy[i]); propagate(i,r-l); return data[i]; } else return data[i] = f1(update_aux(i*2+1,l,(l+r)/2,s,t,x), update_aux(i*2+2,(l+r)/2,r,s,t,x)); } inline T query_aux(int i, int l, int r, int x, int y){ propagate(i,r-l); if(r <= x || y <= l) return e1; else if(x <= l && r <= y) return data[i]; else return f1(query_aux(i*2+1,l,(l+r)/2,x,y), query_aux(i*2+2,(l+r)/2,r,x,y)); } public: LazySegmentTree(){} LazySegmentTree(int n, const T &e1, const TFunc &f1, const U &e2, const UFunc &f2, const Op &g): depth(n > 1 ? 32-__builtin_clz(n-1) + 1 : 1), size((1 << depth) - 1), hsize(size / 2 + 1), e1(e1), f1(f1), e2(e2), f2(f2), g(g), data(size + 1, e1), lazy(size + 1, e2) {} inline void update(int s, int t, const U &x){ update_aux(0,0,hsize,s,t,x); } inline void update_at(int i, const U &x){ update(i, i+1, x); } inline T get(int x, int y){ return query_aux(0,0,hsize,x,y); } inline T at(int x){ return get(x, x+1); } inline void init(const T &val){ data.assign(size, e1); lazy.assign(size, e2); for(int i = size/2; i < size; ++i){ data[i] = val; } for(int i = size/2-1; i >= 0; --i){ data[i] = f1(data[i*2+1], data[i*2+2]); } } inline void init_with_vector(const std::vector<T> &val){ data.assign(size, e1); lazy.assign(size, e2); for(int i = size/2; i < size; ++i){ if(i-size/2 < (int)val.size()) data[i] = val[i-size/2]; } for(int i = size/2-1; i >= 0; --i){ data[i] = f1(data[i*2+1], data[i*2+2]); } } inline void debug(){ #ifdef DEBUG std::cerr << "{"; for(int i = 0; i < hsize; ++i){ if(i) std::cerr << ","; std::cerr << at(i); } std::cerr << "}" << std::endl; #endif } }; template <typename T, typename U> auto make_segment_tree_range_add_range_max(int size, const T &e1, const U &e2){ auto f1 = [](const auto &a, const auto &b){return std::max(a, b);}; auto f2 = [](const auto &a, const auto &b){return a + b;}; auto g = [](const auto &a, const auto &b, int l){return a + b;}; return LazySegmentTree<T, U, decltype(f1), decltype(f2), decltype(g)>(size, e1, f1, e2, f2, g); } int main(){ int N; while(cin >> N){ auto seg = make_segment_tree_range_add_range_max<LLI,LLI>(N-1, 0, 0); vector<LLI> T(N-1); cin >> T; REP(i,N-1){ T[i] += 3 * (N-1-i); } seg.init_with_vector(T); int M; cin >> M; REP(i,M){ int L, R, D; cin >> L >> R >> D; --L, --R; seg.update(L, R+1, D); auto ans = seg.get(0, N-1); cout << ans << endl; } } return 0; }