結果
問題 | No.865 24時間降水量 |
ユーザー | MarcusAureliusAntoninus |
提出日時 | 2019-08-16 22:27:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 91 ms / 2,000 ms |
コード長 | 3,469 bytes |
コンパイル時間 | 2,930 ms |
コンパイル使用メモリ | 195,392 KB |
最終ジャッジ日時 | 2025-01-07 12:29:01 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:98:36: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘long int*’ [-Wformat=] 98 | for (auto& e: A) scanf("%lld", &e); | ~~~^ ~~ | | | | | long int* | long long int* | %ld main.cpp:113:29: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 3 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=] 113 | scanf("%d%lld", &T, &V); | ~~~^ ~~ | | | | | int64_t* {aka long int*} | long long int* | %ld main.cpp:124:28: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=] 124 | printf("%lld\n", max); | ~~~^ ~~~ | | | | | int64_t {aka long int} | long long int | %ld main.cpp:96:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 96 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:98:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 98 | for (auto& e: A) scanf("%lld", &e); | ~~~~~^~~~~~~~~~~~ main.cpp:108:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result
ソースコード
#include <bits/stdc++.h> /////////////////////////////// // Range Add Range Sum Query // /////////////////////////////// template<typename T = int64_t> class RAddRSumQ { private: // ノードの番号、左端、右端 using NodeInfo = std::array<int, 3>; std::vector<T> added_container_, sum_container_; void build(const unsigned int array_size) { unsigned int length{1}; while (length < array_size) length <<= 1; added_container_.resize(2 * length); sum_container_.resize(2 * length); } // 二つの半開区間[left1,right1)と[left2,right2)の重複する区間の要素数を求める int overlapRange(const int left1, const int right1, const int left2, const int right2) const { return std::max(0, std::min(right1, right2) - std::max(left1, left2)); } // nodeの子ノードをpre_addedにpushする void pushNext(std::stack<NodeInfo> &pre_added, const NodeInfo &node) { const int mid{(node[1] + node[2]) >> 1}; pre_added.push({2 * node[0] + 1, node[1], mid}); pre_added.push({2 * node[0], mid, node[2]}); } public: RAddRSumQ(const unsigned int array_size) { build(array_size); } RAddRSumQ(const std::vector<T> &array) { build(array.size()); std::copy(array.begin(), array.end(), added_container_.begin() + (added_container_.size() >> 1)); std::copy(array.begin(), array.end(), sum_container_.begin() + (sum_container_.size() >> 1)); for (auto i{(sum_container_.size() >> 1) - 1}; i > 0; i--) sum_container_[i] = std::min(sum_container_[2 * i], sum_container_[2 * i + 1]); } // [left,right)の半開区間(0-indexed)にaddedを加算 void update(const int left, const int right, const T added) { std::stack<NodeInfo> pre_added; pre_added.push({1, 0, (int)sum_container_.size() >> 1}); while (!pre_added.empty()) { NodeInfo node{pre_added.top()}; pre_added.pop(); const int add_range{overlapRange(node[1], node[2], left, right)}; if (add_range == 0) continue; sum_container_[node[0]] += add_range * added; if (add_range == node[2] - node[1]) added_container_[node[0]] += added; else pushNext(pre_added, node); } } // left,rightは0-indexed、[left, right)の半開区間 T get(const int left, const int right) { std::stack<NodeInfo> pre_added; pre_added.push({1, 0, (int)sum_container_.size() >> 1}); T sum{}; while (!pre_added.empty()) { NodeInfo node{pre_added.top()}; pre_added.pop(); const int add_range{overlapRange(node[1], node[2], left, right)}; if (add_range == 0) continue; if (add_range == node[2] - node[1]) sum += sum_container_[node[0]]; else { sum += add_range * added_container_[node[0]]; pushNext(pre_added, node); } } return sum; } }; int main() { int N; scanf("%d", &N); std::vector<int64_t> A(N); for (auto& e: A) scanf("%lld", &e); std::vector<int64_t> sum(N + 1); for (int i{}; i < N; i++) sum[i + 1] = sum[i] + A[i]; std::vector<int64_t> baseVec(N - 23); for (int i{}; i < N - 23; i++) baseVec[i] = sum[i + 24] - sum[i]; int64_t max{*std::max_element(baseVec.begin(), baseVec.end())}; int Q; scanf("%d", &Q); for (int loop{}; loop < Q; loop++) { int T; int64_t V; scanf("%d%lld", &T, &V); T--; int64_t diff{V - A[T]}; A[T] = V; // [T - 23, T] int left{std::max(T - 23, 0)}, right{std::min(T + 1, N - 23)}; for (int i{left}; i < right; i++) { baseVec[i] += diff; max = std::max(max, baseVec[i]); } printf("%lld\n", max); } return 0; }