QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#761835 | #6733. Moniphant Sleep | XfJbUhpyzgaW | TL | 1ms | 5572kb | C++17 | 3.2kb | 2024-11-19 10:38:26 | 2024-11-19 10:38:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define F(i, a, b) for (int i = (a), iee = (b); i <= iee; i++)
const int N = 500100, inf = 0x3f3f3f3f;
int n, q;
struct info {
int x, y, d1, d2;
friend info operator + (const info &a, const info &b) {
return {min(a.x, b.x), min(a.y, b.y), min(a.d1, b.d1), max(a.d2, b.d2)};
}
static const info id;
} arr[N << 2];
const info info::id = {inf, inf, inf, -inf};
struct tag_t {
int xx, xy, yx, yy, _d, dd;
friend info operator * (const info &a, const tag_t &b) {
return {
min({a.x + b.xx, a.y + b.yx, inf}),
min({a.x + b.xy, a.y + b.yy, inf}),
min({a.d1 + b.dd, b._d}),
min({a.d2 + b.dd, b._d})
};
}
friend tag_t operator * (const tag_t &a, const tag_t &b) {
return {
min({a.xx + b.xx, a.xy + b.yx, inf}),
min({a.xx + b.xy, a.xy + b.yy, inf}),
min({a.yx + b.xx, a.yy + b.yx, inf}),
min({a.yx + b.xy, a.yy + b.yy, inf}),
min({a._d + b.dd, b._d}),
min({a.dd + b.dd, inf})
};
}
static const tag_t id;
} tag[N << 2];
const tag_t tag_t::id = {0, inf, inf, 0, inf, 0};
#define lc p << 1
#define rc lc | 1
#define mid ((l + r) >> 1)
void build(int l, int r, int p) {
arr[p] = {500000, inf, inf, inf};
tag[p] = tag_t::id;
if (l == r) return;
build(l, mid, lc), build(mid + 1, r, rc);
}
void up(int p) { arr[p] = arr[lc] + arr[rc]; }
void modify(int p, const tag_t &t) { arr[p] = arr[p] * t, tag[p] = tag[p] * t; }
void down(int p) { modify(lc, tag[p]), modify(rc, tag[p]), tag[p] = tag_t::id; }
info query(int x, int y, int l, int r, int p) {
if (x > r || y < l) return info::id;
if (x <= l && y >= r) return arr[p];
return (query(x, y, l, mid, lc) + query(x, y, mid + 1, r, rc)) * tag[p];
}
void modify(int x, int y, const tag_t &k1, const tag_t &k2, int l, int r, int p) {
if (x > r || y < l) return;
if (x <= l && y >= r && l == r) { // debug!
auto ti = arr[p] * k1;
if (ti.d2 <= 0)
return modify(p, k1);
if (ti.d1 > 0)
return modify(p, k2);
//if (l == 1) cerr << arr[p].x << " " << arr[p].y << " " << arr[p].d1 << " " << arr[p].d2 << "\n";
//return;
}
down(p);
modify(x, y, k1, k2, l, mid, lc);
modify(x, y, k1, k2, mid + 1, r, rc);
up(p);
}
// (v1+v2)*A=v1*A+v2*A
/*
(x, y, y - x) -> (+1, =, -1)
(x, y, y - x) -> (-1, =, +1); (x, y, 0) -> (x - 1, inf, inf) // min >= 0 ??
(x, y, y - x) -> (=, min(x, y), min(y - x, 0))
(x, y, y - x) -> (min(x, y), inf, inf)
*/
const tag_t op[5][2] = {
{tag_t::id, tag_t::id},
{{1, inf, inf, 0, inf, -1}, tag_t::id},
{{-1, inf, inf, 0, inf, 1}, {-1, inf, inf, inf, inf, inf}},
{{0, 0, inf, 0, 0, 0}, tag_t::id},
{{0, inf, 0, inf, inf, inf}, tag_t::id}
};
int main() {
cin >> n >> q;
build(1, n, 1);
F(i, 1, q) {
int p, x, y;
cin >> p >> x >> y;
if (p <= 4) {
modify(x, y, op[p][0], op[p][p == 2], 1, n, 1);
} else {
auto ret = query(x, y, 1, n, 1);
cout << ret.x << "\n";
}
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5572kb
input:
1 9 1 1 1 1 1 1 1 1 1 3 1 1 2 1 1 1 1 1 1 1 1 4 1 1 5 1 1
output:
500004
result:
ok 1 number(s): "500004"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5568kb
input:
3 7 2 1 3 3 1 3 1 1 3 1 1 3 5 1 1 4 1 3 5 1 1
output:
500001 499999
result:
ok 2 number(s): "500001 499999"
Test #3:
score: -100
Time Limit Exceeded
input:
500000 500000 2 132991 371170 5 15281 15281 1 278642 397098 2 152103 176573 2 13797 47775 3 139320 370045 3 79054 432340 3 82556 212775 4 270171 469418 5 148000 148000 3 371255 401414 5 71051 71051 2 358945 473071 2 231663 265401 2 20243 58131 1 247710 313373 5 154549 154549 1 17317 233265 5 37602 3...
output:
500000 499999 500000 499998 499999 500000 500000 499997 500000 499997 499997 499999 499998 500000 499997 500000 499999 500001 499999 499999 499997 499997 499996 499998 500000 500001 500001 499996 499998 499999 499996 499999 500001 500000 500000 500002 500002 499997 500001 499997 499995 499999 500004...