ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#204925 | #3642. A | LJ07 | 100 | 2439ms | 47632kb | C++11 | 2.7kb | 2024-06-16 08:33:06 | 2024-06-16 13:52:09 |
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define pb emplace_back
#define sz(a) int(a.size())
const int N = 5e5 + 5;
int n, m, q, a[N], l[N], r[N], qid, fa[N], val[N];
int ql[N], qr[N];
int getf(int x) {
return x == fa[x] ? x : fa[x] = getf(fa[x]);
}
inline int merge(int x, int y) {
if (!x || !y) {
return x + y;
}
fa[x] = y;
return y;
}
pair<int, int> oper[N];
vector<pair<int, int>> vecr[N];
vector<int> vecl[N];
set<pair<int, int>> S;
#define mid ((L + R) >> 1)
#define Ls rt << 1, L, mid
#define Rs rt << 1 | 1, mid + 1, R
int tr[N << 2];
void upd(int p, int v, int rt = 1, int L = 1, int R = n) {
if (L == R) {
tr[rt] = v;
return ;
}
p <= mid ? upd(p, v, Ls) : upd(p, v, Rs);
tr[rt] = max(tr[rt << 1], tr[rt << 1 | 1]);
}
int qry(int l, int r, int rt = 1, int L = 1, int R = n) {
if (l <= L && R <= r) {
return tr[rt];
}
int res = 0;
if (l <= mid) {
res = max(res, qry(l, r, Ls));
}
if (r > mid) {
res = max(res, qry(l, r, Rs));
}
return res;
}
void build(int rt = 1, int L = 1, int R = n) {
if (L == R) {
tr[rt] = a[L];
return ;
}
build(Ls), build(Rs), tr[rt] = max(tr[rt << 1], tr[rt << 1 | 1]);
}
#undef mid
#undef Ls
#undef Rs
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> q;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= m; ++i) {
cin >> l[i] >> r[i];
}
for (int i = 1; i <= q; ++i) {
int op, x, y, z;
cin >> op;
if (op == 1) {
cin >> x >> y;
oper[i] = make_pair(x, y);
}else {
cin >> x >> y >> z;
if (x <= y) {
vecr[y].pb(z, ++qid);
vecl[x].pb(qid);
oper[i] = make_pair(qid, 0);
}else {
oper[i] = make_pair(-z, 0);
}
}
}
for (auto o : {0, 1}) {
iota(fa, fa + 1 + qid, 0);
for (int i = m; i; --i) {
for (auto t : vecr[i]) {
int k = t.first, v = t.second;
S.emplace(k, v), val[v] = k;
}
auto itl = S.lower_bound(make_pair(l[i], 0));
auto itr = itl;
int f = 0;
for (; itr != S.end() && itr->first <= r[i]; ++itr) {
f = merge(f, itr->second);
}
S.erase(itl, itr), S.emplace(o ? l[i] : r[i], f), val[f] = o ? l[i] : r[i];
for (auto v : vecl[i]) {
(o ? ql[v] : qr[v]) = val[getf(v)];
}
}
S.clear();
}
build();
for (int i = 1; i <= q; ++i) {
int x = oper[i].first, y = oper[i].second;
if (y) {
upd(x, y);
}else {
if (x < 0) {
cout << qry(-x, -x) << '\n';
}else {
cout << qry(ql[x], qr[x]) << '\n';
}
}
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 10ms
memory: 28652kb
input:
100 100 100 53 72 1 94 19 49 45 72 27 24 42 63 5 33 91 14 93 32 68 9 33 40 76 80 70 19 13 69 17 82 7...
output:
97 89 97 97 5 10 97 63 33 72 30 97 70 11 29 97 97 58 97 27 77 26 27 100 97 14 47 100 89 100 68 100 1...
result:
ok 45 numbers
Test #2:
score: 10
Accepted
time: 7ms
memory: 28872kb
input:
5000 5000 5000 2125 178 302 2231 3417 2813 3837 1469 2368 1260 4698 2290 2346 99 1111 571 1032 1815 ...
output:
667 4009 2527 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 5000 3090 2714 5000 5000 3867 1874 5...
result:
ok 2540 numbers
Test #3:
score: 10
Accepted
time: 8ms
memory: 28872kb
input:
5000 5000 5000 2336 1476 3268 1316 4956 4724 293 4480 3838 1429 4769 1599 2212 4991 348 2456 4081 39...
output:
3797 1475 5000 2592 4979 1302 4007 892 4752 5000 3155 4072 5000 2907 1349 521 169 4474 5000 5000 500...
result:
ok 2481 numbers
Test #4:
score: 10
Accepted
time: 154ms
memory: 33124kb
input:
100000 100000 100000 47974 54241 45615 57195 91255 73490 99058 92861 6678 14239 62822 32472 51708 99...
output:
100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 10...
result:
ok 50275 numbers
Test #5:
score: 10
Accepted
time: 145ms
memory: 33124kb
input:
100000 100000 100000 69232 50277 23937 73629 32068 23022 24200 6714 67264 78202 24098 72712 37844 89...
output:
100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 10...
result:
ok 50056 numbers
Test #6:
score: 10
Accepted
time: 145ms
memory: 32668kb
input:
100000 100000 100000 9145 6033 8208 69841 86885 67534 38690 56130 93717 50467 85735 8364 62124 5766 ...
output:
81166 99999 99999 99999 7656 99999 25968 99999 99999 99999 58493 55897 99999 99999 99999 47506 93880...
result:
ok 49897 numbers
Test #7:
score: 10
Accepted
time: 150ms
memory: 32676kb
input:
100000 100000 100000 10212 68140 85156 37083 37162 79906 48673 72388 11108 94297 99595 30356 60837 1...
output:
6360 96500 84055 99997 34724 90442 99997 99997 88465 62187 99997 44238 52596 99997 89550 99997 99997...
result:
ok 50113 numbers
Test #8:
score: 10
Accepted
time: 145ms
memory: 32680kb
input:
100000 100000 100000 97753 43128 52530 36251 66738 50281 35601 51599 67144 10993 15287 129 10808 493...
output:
99999 60033 99999 99999 99999 53437 48765 99996 15166 90338 99937 99999 64873 59952 95213 99999 1372...
result:
ok 49926 numbers
Test #9:
score: 10
Accepted
time: 847ms
memory: 47620kb
input:
500000 500000 500000 415786 185000 368060 454299 205276 139329 86243 34712 479410 85757 479364 14346...
output:
273611 306476 499999 350258 499999 497855 499994 220364 499999 179409 180896 259393 499999 499999 30...
result:
ok 250540 numbers
Test #10:
score: 10
Accepted
time: 828ms
memory: 47632kb
input:
500000 500000 500000 477228 236521 205979 331009 82230 405580 353797 374981 16183 335946 132779 3126...
output:
499998 437263 381280 499998 499998 59869 499979 499998 499998 499998 364195 215541 499998 476962 499...
result:
ok 249797 numbers
Extra Test:
score: 0
Extra Test Passed