Compile Error
foo.cc: In member function 'long long int STL::query(int, int, int, int, int)': foo.cc:72:12: error: declaration of 'long long int b' shadows a parameter 72 | ll b = query(rc, mid + 1, i, j); | ^ foo.cc:64:28: note: 'int b' previously declared here 64 | ll query(int node, int b, int e, int i, int j) { | ~~~~^ foo.cc:72:21: error: no matching function for call to 'STL::query(int, int, int&, int&)' 72 | ll b = query(rc, mid + 1, i, j); | ~~~~~^~~~~~~~~~~~~~~~~~~ foo.cc:64:8: note: candidate: 'long long int STL::query(int, int, int, int, int)' 64 | ll query(int node, int b, int e, int i, int j) { | ^~~~~ foo.cc:64:8: note: candidate expects 5 arguments, 4 provided foo.cc: In function 'void Try()': foo.cc:92:13: error: 'upd' was not declared in this scope 92 | upd(1, 1, n, l, r, x); | ^~~ foo.cc:94:22: error: 'query' was not declared in this scope 94 | else cout << query(1, 1, n, l, r) << endl; | ^~~~~
Code
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int nn = 1e5 + 17, mod = 1e9 + 7;
int n, A[nn];
struct STL {
#define lc (node << 1)
#define rc ((node << 1) + 1)
ll T[4 * nn], Lazy [4 * nn];
inline void push(int node, int b, int e) {
if (Lazy[node] == 0) {
return;
}
T[node] = T[node] + Lazy[node] * (e - b + 1);
if (b != e) {
Lazy[lc] = Lazy[lc] + Lazy[node];
Lazy[rc] = Lazy[rc] + Lazy[node];
}
Lazy[node] = 0;
}
inline long long combine(ll a, ll b) {
return max(a, b);
}
inline void pull(int node) {
T[node] = max(T[lc], T[rc]);
}
void build(int node, int b, int e) {
Lazy[node] = 0;
if (b == e) {
T[node] = A[b]; return;
}
int mid = (b + e) / 2;
build(lc, b, mid);
build(rc, mid + 1, e);
T[node] = max(T[lc], T[rc]);
}
void upd(int node, int b, int e, int i, int j, int x) {
push(node, b, e);
if (j < b || e < i) {
return;
}
if (i <= b && e <= b) {
Lazy[node] += x;
push(node, b, e);
return;
}
int mid = (e + b) / 2;
upd(lc, b, mid, i, j, x);
upd(rc, mid + 1, e, i, j, x);
pull(node);
}
ll query(int node, int b, int e, int i, int j) {
push(node, b, e);
if (i > e || b > j) return 0;
if (i <= b && e <= j) {
return T[node];
}
int mid = (b + e) / 2;
ll a = query(lc, b, mid, i, j);
ll b = query(rc, mid + 1, i, j);
return max(a, b);
}
}T;
void Try() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> A[i];
}
T.build(1, 1, n);
int q; cin >> q;
while(q--) {
int t, l, r;
cin >> t >> l >> r;
if (t == 1) {
int x; cin >> x;
upd(1, 1, n, l, r, x);
}
else cout << query(1, 1, n, l, r) << endl;
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
Try();
}
}
Information
- Submit By
- Type
- Pretest
- Problem
- P1211 Range MAX
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-09-01 06:43:54
- Judged At
- 2025-09-01 06:43:54
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes