QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#761470 | #6733. Moniphant Sleep | XfJbUhpyzgaW | WA | 1ms | 5708kb | C++17 | 3.4kb | 2024-11-18 23:24:30 | 2024-11-18 23:24:31 |
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 modify1(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) {
auto ti = arr[p] * k1;
if (ti.d2 <= 0)
return modify(p, k1);
if (ti.d1 > 0)
return modify(p, k2);
}
down(p);
modify1(x, y, k1, k2, l, mid, lc);
modify1(x, y, k1, k2, mid + 1, r, rc);
up(p);
}
void modify(int x, int y, const tag_t &k, int l, int r, int p) {
if (x > r || y < l) return;
if (x <= l && y >= r) return modify(p, k);
down(p);
modify(x, y, k, l, mid, lc);
modify(x, y, k, 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) -> (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}, {0, 0, inf, 0, 0, 0}},
{{inf, inf, 0, inf, inf, inf}, {inf, inf, 0, inf, inf, inf}}
};
int main() {
cin >> n >> q;
build(1, n, 1);
F(i, 1, q) {
int p, x, y;
cin >> p >> x >> y;
if (p <= 4) {
if (p == 2)
modify1(x, y, op[p][0], op[p][1], 1, n, 1);
else
modify(x, y, op[p][0], 1, n, 1);
} else {
auto ret = query(x, y, 1, n, 1);
cout << ret.x << "\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5708kb
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:
1061109567
result:
wrong answer 1st numbers differ - expected: '500004', found: '1061109567'