Compile Error
foo.cc:3:29: error: 'vector' does not name a type
3 | struct SegmentTree { int n; vector<ll> st, lazy;
| ^~~~~~
foo.cc:10:39: error: 'vector' does not name a type
10 | void build(int p, int l, int r, const vector<ll>& a) {
| ^~~~~~
foo.cc:10:45: error: expected ',' or '...' before '<' token
10 | void build(int p, int l, int r, const vector<ll>& a) {
| ^
foo.cc:21:19: error: 'll' has not been declared
21 | void apply(int p, ll val) {
| ^~
foo.cc:34:48: error: 'll' has not been declared
34 | void update(int p, int l, int r, int i, int j, ll val) {
| ^~
foo.cc:47:1: error: 'll' does not name a type
47 | ll query(int p, int l, int r, int i, int j) {
| ^~
foo.cc: In constructor 'SegmentTree::SegmentTree(int)':
foo.cc:6:5: error: 'st' was not declared in this scope; did you mean 'std'?
6 | st.assign(4*n+4, 0);
| ^~
| std
foo.cc:7:5: error: 'lazy' was not declared in this scope
7 | lazy.assign(4*n+4, 0);
| ^~~~
foo.cc: In member function 'void SegmentTree::build(int, int, int, int)':
foo.cc:12:9: error: 'st' was not declared in this scope; did you mean 'std'?
12 | st[p] = a[l];
| ^~
| std
foo.cc:12:17: error: 'a' was not declared in this scope
12 | st[p] = a[l];
| ^
foo.cc:16:23: error: 'a' was not declared in this scope
16 | build(p<<1, l, m, a);
| ^
foo.cc:18:5: error: 'st' was not declared in this scope; did you mean 'std'?
18 | st[p] = max(st[p<<1], st[p<<1|1]);
| ^~
| std
foo.cc:18:13: error: 'max' was not declared in this scope; did you mean 'std::max'?
18 | st[p] = max(st[p<<1], st[p<<1|1]);
| ^~~
| std::max
In file included from /usr/include/c++/13/algorithm:61,
from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
from foo.cc:1:
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: 'std::max' declared here
5805 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
foo.cc: In member function 'void SegmentTree::apply(int, int)':
foo.cc:22:5: error: 'st' was not declared in this scope; did you mean 'std'?
22 | st[p] += val;
| ^~
| std
foo.cc:23:5: error: 'lazy' was not declared in this scope
23 | lazy[p] += val;
| ^~~~
foo.cc: In member function 'void SegmentTree::push(int)':
foo.cc:27:9: error: 'lazy' was not declared in this scope
27 | if (lazy[p] != 0) {
| ^~~~
foo.cc: In member function 'void SegmentTree::update(int, int, int, int, int, int)':
foo.cc:44:5: error: 'st' was not declared in this scope; did you mean 'std'?
44 | st[p] = max(st[p<<1], st[p<<1|1]);
| ^~
| std
foo.cc:44:13: error: 'max' was not declared in this scope; did you mean 'std::max'?
44 | st[p] = max(st[p<<1], st[p<<1|1]);
| ^~~
| std::max
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: 'std::max' declared here
5805 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
foo.cc: In function 'int main()':
foo.cc:57:14: error: 'ios' has not been declared
57 | int main() { ios::sync_with_stdio(false); cin.tie(NULL);
| ^~~
foo.cc:57:43: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
57 | int main() { ios::sync_with_stdio(false); cin.tie(NULL);
| ^~~
| std::cin
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:146:
/usr/include/c++/13/iostream:62:18: note: 'std::cin' declared here
62 | extern istream cin; ///< Linked to standard input
| ^~~
foo.cc:64:5: error: 'vector' was not declared in this scope
64 | vector<ll> a(N+1);
| ^~~~~~
foo.cc:64:5: note: suggested alternatives:
In file included from /usr/include/c++/13/vector:66,
from /usr/include/c++/13/functional:64,
from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:428:11: note: 'std::vector'
428 | class vector : protected _Vector_base<_Tp, _Alloc>
| ^~~~~~
/usr/include/c++/13/vector:86:13: note: 'std::pmr::vector'
86 | using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
| ^~~~~~
foo.cc:64:12: error: 'll' was not declared in this scope
64 | vector<ll> a(N+1);
| ^~
foo.cc:64:16: error: 'a' was not declared in this scope
64 | vector<ll> a(N+1);
| ^
foo.cc:76:15: error: expected ';' before 'X'
76 | ll X;
| ^~
| ;
foo.cc:77:20: error: 'X' was not declared in this scope
77 | cin >> X;
| ^
foo.cc:80:15: error: expected ';' before 'ans'
80 | ll ans = st.query(1, 1, N, L, R);
| ^~~~
| ;
foo.cc:81:13: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
81 | cout << ans << '\n';
| ^~~~
| std::cout
/usr/include/c++/13/iostream:63:18: note: 'std::cout' declared here
63 | extern ostream cout; ///< Linked to standard output
| ^~~~
foo.cc:81:21: error: 'ans' was not declared in this scope; did you mean 'abs'?
81 | cout << ans << '\n';
| ^~~
| abs
Code
#include <bits/stdc++.h> using namespace std; typedef long long ll;
struct SegmentTree { int n; vector<ll> st, lazy;
SegmentTree(int _n) : n(_n) {
st.assign(4*n+4, 0);
lazy.assign(4*n+4, 0);
}
void build(int p, int l, int r, const vector<ll>& a) {
if (l == r) {
st[p] = a[l];
return;
}
int m = (l + r) >> 1;
build(p<<1, l, m, a);
build(p<<1|1, m+1, r, a);
st[p] = max(st[p<<1], st[p<<1|1]);
}
void apply(int p, ll val) {
st[p] += val;
lazy[p] += val;
}
void push(int p) {
if (lazy[p] != 0) {
apply(p<<1, lazy[p]);
apply(p<<1|1, lazy[p]);
lazy[p] = 0;
}
}
void update(int p, int l, int r, int i, int j, ll val) {
if (i > r || j < l) return;
if (l >= i && r <= j) {
apply(p, val);
return;
}
push(p);
int m = (l + r) >> 1;
update(p<<1, l, m, i, j, val);
update(p<<1|1, m+1, r, i, j, val);
st[p] = max(st[p<<1], st[p<<1|1]);
}
ll query(int p, int l, int r, int i, int j) {
if (i > r || j < l) return LLONG_MIN;
if (l >= i && r <= j) return st[p];
push(p);
int m = (l + r) >> 1;
return max(query(p<<1, l, m, i, j), query(p<<1|1, m+1, r, i, j));
}
};
int main() { ios::sync_with_stdio(false); cin.tie(NULL);
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
vector<ll> a(N+1);
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
SegmentTree st(N);
st.build(1, 1, N, a);
int Q;
cin >> Q;
while (Q--) {
int type, L, R;
cin >> type >> L >> R;
if (type == 1) {
ll X;
cin >> X;
st.update(1, 1, N, L, R, X);
} else if (type == 2) {
ll ans = st.query(1, 1, N, L, R);
cout << ans << '\n';
}
}
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1211 Range MAX
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-07-10 10:25:06
- Judged At
- 2025-07-10 10:25:06
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes