結果
| 問題 |
No.631 Noelちゃんと電車旅行
|
| コンテスト | |
| ユーザー |
ats5515
|
| 提出日時 | 2018-01-05 21:44:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,369 bytes |
| コンパイル時間 | 825 ms |
| コンパイル使用メモリ | 78,648 KB |
| 最終ジャッジ日時 | 2024-11-15 04:46:18 |
| 合計ジャッジ時間 | 2,858 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:31:35: error: ‘numeric_limits’ is not a member of ‘std’
31 | static const T INF = std::numeric_limits<T>::max() / 2;
| ^~~~~~~~~~~~~~
main.cpp:31:51: error: expected primary-expression before ‘>’ token
31 | static const T INF = std::numeric_limits<T>::max() / 2;
| ^
main.cpp:31:57: error: no matching function for call to ‘max()’
31 | static const T INF = std::numeric_limits<T>::max() / 2;
| ~~~~~^~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
from /usr/include/c++/11/ios:40,
from /usr/include/c++/11/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: ‘template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)’
254 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: template argument deduction/substitution failed:
main.cpp:31:57: note: candidate expects 2 arguments, 0 provided
31 | static const T INF = std::numeric_limits<T>::max() / 2;
| ~~~~~^~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
from /usr/include/c++/11/ios:40,
from /usr/include/c++/11/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: ‘template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
300 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: template argument deduction/substitution failed:
main.cpp:31:57: not
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
template <typename T>
class segment_tree {
public:
segment_tree(int n_) : n(__lowest_power_of_2(n_)), dat(n * 2, 0), lazy(n * 2, 0) {}
template <typename Iterator>
segment_tree(Iterator left, Iterator right)
: n(__lowest_power_of_2(std::distance(left, right))), dat(n * 2, 0), lazy(n * 2, 0) {
std::copy(left + n, right + n, dat.begin());
for (int i = n - 1; i >= 1; --i) {
dat[i] = dat[i * 2] + dat[i * 2 + 1];
}
}
private:
int n;
std::vector<T> dat, lazy;
static const T INF = std::numeric_limits<T>::max() / 2;
public:
void add(int ql, int qr, const T &x) { __add(1, 0, n, ql, qr, x); }
T max(int ql, int qr) { return __max(1, 0, n, ql, qr); }
private:
void __flush_lazy(int v) {
dat[v] += lazy[v];
if (v < n) {
lazy[v * 2] += lazy[v];
lazy[v * 2 + 1] += lazy[v];
}
lazy[v] = 0;
}
void __update_dat(int v) { dat[v] = std::max(dat[v * 2], dat[v * 2 + 1]); }
void __add(int n, int l, int r, const int ql, const int qr, const T &x) {
__flush_lazy(n);
if (r <= ql || qr <= l) {
return;
}
else if (ql <= l && r <= qr) {
lazy[n] += x;
__flush_lazy(n);
}
else {
int m = (l + r) / 2;
__add(n * 2, l, m, ql, qr, x);
__add(n * 2 + 1, m, r, ql, qr, x);
__update_dat(n);
}
}
T __max(int n, int l, int r, const int ql, const int qr) {
__flush_lazy(n);
if (r <= ql || qr <= l) {
return -INF;
}
else if (ql <= l && r <= qr) {
return dat[n];
}
else {
int m = (l + r) / 2;
T res_left = __max(n * 2, l, m, ql, qr);
T res_right = __max(n * 2 + 1, m, r, ql, qr);
__update_dat(n);
return std::max(res_left, res_right);
}
}
int __lowest_power_of_2(int x) const {
int res = 1;
while (res < x) res <<= 1;
return res;
}
};
;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N;
segment_tree<int> sg(N - 1);
vector<int> A(N);
int res = 0;
for (int i = 0; i < N - 1; i++) {
cin >> A[i];
A[i] -= 3 * i;
sg.add(i, i + 1, A[i]);
}
int l, r, d;
cin >> M;
for (int i = 0; i < M; i++) {
cin >> l >> r >> d;
l--;
sg.add(l, r, d);
cout << 3 * (N - 1) + sg.max(0, N) << endl;
}
}
ats5515