-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
ifstream fin("IHateIt_1754.in"); | ||
ofstream fout("IHateIt_1754.out"); | ||
|
||
class SegTree | ||
{ | ||
private: | ||
int sizeA; //原数组的大小 | ||
vector<int> a; //原数组 | ||
vector<int> segTree; //线段树的数组 | ||
|
||
void build(int l, int r, int i) | ||
{ | ||
if (i > sizeA * 4 - 1) | ||
return; | ||
|
||
if (l == r) | ||
{ | ||
segTree[i] = a[l]; | ||
return; | ||
} | ||
|
||
int m = (l + r) / 2; | ||
|
||
build(l, m, i * 2); | ||
build(m + 1, r, i * 2 + 1); | ||
|
||
segTree[i] = max(segTree[i * 2], segTree[i * 2 + 1]); | ||
} | ||
|
||
int query(int l, int r, int i, int nowLeft, int nowRight) | ||
{ | ||
if (nowRight < l || r < nowLeft) | ||
{ | ||
return INT_MIN; | ||
} | ||
if (nowLeft >= l && nowRight <= r) | ||
{ | ||
return segTree[i]; | ||
} | ||
|
||
int m = (nowLeft + nowRight) / 2; | ||
|
||
return max(query(l, r, i * 2, nowLeft, m), query(l, r, i * 2 + 1, m + 1, nowRight)); | ||
} | ||
|
||
void update(int pos, int _new, int i, int nowLeft, int nowRight) | ||
{ | ||
if (pos < nowLeft || pos > nowRight) | ||
{ | ||
return; | ||
} | ||
|
||
if (nowLeft == nowRight) | ||
{ | ||
a[pos] = _new; | ||
segTree[i] = _new; | ||
return; | ||
} | ||
|
||
int m = (nowLeft + nowRight) / 2; | ||
update(pos, _new, i * 2, nowLeft, m); | ||
update(pos, _new, i * 2 + 1, m + 1, nowRight); | ||
//segTree[i] = max(update(pos, _new, i * 2, nowLeft, m), update(pos, _new, i * 2 + 1, m + 1, nowRight)); | ||
segTree[i] = max(segTree[i*2],segTree[i*2+1]); | ||
} | ||
|
||
public: | ||
SegTree(const vector<int> & p_Sour) | ||
{ | ||
a = p_Sour; | ||
sizeA = a.size(); | ||
segTree.assign(sizeA * 4, INT_MIN); | ||
|
||
build(0, sizeA-1, 1); | ||
} | ||
|
||
int query(int l, int r) | ||
{ | ||
return query(l, r, 1, 0, sizeA-1); | ||
} | ||
|
||
void update(int index, int newVal) | ||
{ | ||
update(index, newVal, 1, 0, sizeA-1); | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
while (true) | ||
{ | ||
int n = 0, m = 0; | ||
fin >> n >> m; | ||
if (n + m == 0) | ||
break; | ||
|
||
vector<int> a(n); | ||
|
||
for (int i = 0; i <= n-1; ++i) | ||
{ | ||
fin >> a[i]; | ||
} | ||
|
||
SegTree tree(a); | ||
|
||
for (int c = 1; c <= m; ++c) | ||
{ | ||
char ch; | ||
int _i, _j; | ||
fin >> ch >> _i >> _j; | ||
|
||
if (ch == 'Q') | ||
{ | ||
fout << tree.query(_i-1, _j-1) << '\n'; | ||
} | ||
else | ||
{ | ||
tree.update(_i-1, _j); | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
5 7 | ||
17 29 27 19 25 | ||
U 3 5 | ||
Q 1 2 | ||
Q 2 4 | ||
U 3 5 | ||
U 3 5 | ||
Q 1 3 | ||
Q 2 3 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
29 | ||
29 | ||
29 | ||
29 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
// ifstream cin("IHateIt_1754.in"); | ||
// ofstream cout("IHateIt_1754.out"); | ||
|
||
class SegTree | ||
{ | ||
private: | ||
int sizeA; //原数组的大小 | ||
vector<int> a; //原数组 | ||
vector<int> segTree; //线段树的数组 | ||
|
||
void build(int l, int r, int i) | ||
{ | ||
if (i > sizeA * 4 - 1) | ||
return; | ||
|
||
if (l == r) | ||
{ | ||
segTree[i] = a[l]; | ||
return; | ||
} | ||
|
||
int m = (l + r) / 2; | ||
|
||
build(l, m, i * 2); | ||
build(m + 1, r, i * 2 + 1); | ||
|
||
segTree[i] = max(segTree[i * 2], segTree[i * 2 + 1]); | ||
} | ||
|
||
int query(int l, int r, int i, int nowLeft, int nowRight) | ||
{ | ||
if (nowRight < l || r < nowLeft) | ||
{ | ||
return INT_MIN; | ||
} | ||
if (nowLeft >= l && nowRight <= r) | ||
{ | ||
return segTree[i]; | ||
} | ||
|
||
int m = (nowLeft + nowRight) / 2; | ||
|
||
return max(query(l, r, i * 2, nowLeft, m), query(l, r, i * 2 + 1, m + 1, nowRight)); | ||
} | ||
|
||
void update(int pos, int _new, int i, int nowLeft, int nowRight) | ||
{ | ||
if (pos < nowLeft || pos > nowRight) | ||
{ | ||
return; | ||
} | ||
|
||
if (nowLeft == nowRight) | ||
{ | ||
a[pos] = _new; | ||
segTree[i] = _new; | ||
return; | ||
} | ||
|
||
int m = (nowLeft + nowRight) / 2; | ||
update(pos, _new, i * 2, nowLeft, m); | ||
update(pos, _new, i * 2 + 1, m + 1, nowRight); | ||
//segTree[i] = max(update(pos, _new, i * 2, nowLeft, m), update(pos, _new, i * 2 + 1, m + 1, nowRight)); | ||
segTree[i] = max(segTree[i*2],segTree[i*2+1]); | ||
} | ||
|
||
public: | ||
SegTree(const vector<int> & p_Sour) | ||
{ | ||
a = p_Sour; | ||
sizeA = a.size(); | ||
segTree.assign(sizeA * 4, INT_MIN); | ||
|
||
build(0, sizeA-1, 1); | ||
} | ||
|
||
int query(int l, int r) | ||
{ | ||
return query(l, r, 1, 0, sizeA-1); | ||
} | ||
|
||
void update(int index, int newVal) | ||
{ | ||
update(index, newVal, 1, 0, sizeA-1); | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
while (true) | ||
{ | ||
int n = 0, m = 0; | ||
cin >> n >> m; | ||
if (n + m == 0) | ||
break; | ||
|
||
vector<int> a(n); | ||
|
||
for (int i = 0; i <= n-1; ++i) | ||
{ | ||
cin >> a[i]; | ||
} | ||
|
||
SegTree tree(a); | ||
|
||
for (int c = 1; c <= m; ++c) | ||
{ | ||
char ch; | ||
int _i, _j; | ||
cin >> ch >> _i >> _j; | ||
|
||
if (ch == 'Q') | ||
{ | ||
cout << tree.query(_i-1, _j-1) << '\n'; | ||
} | ||
else | ||
{ | ||
tree.update(_i-1, _j); | ||
} | ||
} | ||
} | ||
|
||
cout.flush(); | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
4 2 | ||
8 3 10 19 | ||
Q 1 3 | ||
Q 1 2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
10 | ||
8 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
9 3 | ||
30 2 21 5 10 25 19 21 27 | ||
U 7 8 | ||
U 1 3 | ||
Q 2 8 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
25 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
17 4 | ||
26 23 7 26 6 9 4 13 19 27 28 4 26 22 12 10 2 | ||
Q 2 6 | ||
Q 10 17 | ||
Q 13 17 | ||
Q 1 7 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
26 | ||
28 | ||
26 | ||
26 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
20 6 | ||
8 1 12 8 26 2 5 14 13 29 9 26 26 30 26 7 13 29 5 27 | ||
Q 6 9 | ||
U 4 5 | ||
Q 1 12 | ||
Q 2 5 | ||
U 5 10 | ||
Q 8 19 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
14 | ||
29 | ||
26 | ||
30 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
11 2 | ||
19 12 9 18 25 30 6 21 25 22 16 | ||
Q 1 7 | ||
Q 4 11 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
30 | ||
30 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
11 8 | ||
19 16 18 22 1 10 4 1 15 1 23 | ||
Q 6 11 | ||
Q 2 7 | ||
Q 3 9 | ||
U 1 11 | ||
U 1 7 | ||
Q 1 11 | ||
U 4 9 | ||
Q 7 11 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
23 | ||
22 | ||
22 | ||
23 | ||
23 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
3 6 | ||
5 25 23 | ||
Q 2 3 | ||
Q 1 3 | ||
Q 1 2 | ||
Q 1 3 | ||
U 1 3 | ||
Q 1 2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
25 | ||
25 | ||
25 | ||
25 | ||
25 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
4 10 | ||
14 16 12 25 | ||
U 2 4 | ||
U 3 4 | ||
U 3 4 | ||
U 2 4 | ||
U 1 4 | ||
Q 1 3 | ||
U 1 2 | ||
U 1 4 | ||
Q 2 4 | ||
Q 2 3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
4 | ||
25 | ||
4 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
4 5 | ||
19 3 26 10 | ||
U 1 2 | ||
U 2 4 | ||
Q 1 2 | ||
Q 2 3 | ||
Q 1 3 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
4 | ||
26 | ||
26 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
19 3 | ||
20 17 15 11 23 8 19 15 3 17 11 10 4 28 12 7 17 25 26 | ||
Q 1 11 | ||
Q 5 8 | ||
Q 10 11 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
23 | ||
23 | ||
17 |