QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#197463 | #2266. Colorful Rectangle | Galex | RE | 0ms | 0kb | C++14 | 3.3kb | 2023-10-02 16:14:05 | 2023-10-02 16:14:05 |
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : 1), ch = getchar();
while (ch >= '0' && ch <= '9')
s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return s * f;
}
int n;
int lsh[100005], tot = 0;
int od[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
struct Node {
int x, y, c;
friend bool operator < (const Node &x, const Node &y) {return x.x < y.x || (x.x == y.x && x.c < y.c);}
} a[100005], b[100005];
#define lb(x) (x & (-x))
struct BIT {
int mx[100005];
BIT() {memset(mx, ~0x3f, sizeof mx);}
void mdf(int x, int v) {
while (x <= tot)
mx[x] = max(mx[x], v), x += lb(x);
}
int qry(int x) {
int res = -1e18;
while (x)
res = max(res, mx[x]), x -= lb(x);
return res;
}
} t1, t2;
struct SGT {
#define ls (p << 1)
#define rs (p << 1 | 1)
#define mid ((l + r) >> 1)
int ans[400005], lmx[400005], rmn[400005];
SGT() {
memset(ans, 0x3f, sizeof ans);
memset(lmx, ~0x3f, sizeof lmx);
memset(rmn, 0x3f, sizeof rmn);
}
void pushtag(int p, int lx, int rn) {
ans[p] = min(ans[p], rn - lmx[p]);
rmn[p] = min(rmn[p], rn), lmx[p] = max(lmx[p], lx);
}
void pushdown(int p) {
pushtag(ls, lmx[p], rmn[p]), pushtag(rs, lmx[p], rmn[p]);
lmx[p] = -1e18, rmn[p] = 1e18;
}
void mdf(int l, int r, int p, int x, int y, int vl, int vr) {
if (r < x || y < l)
return ;
if (x <= l && r <= y) {
pushtag(p, vl, vr);
return ;
}
pushdown(p);
mdf(l, mid, ls, x, y, vl, vr), mdf(mid + 1, r, rs, x, y, vl, vr);
}
int qry(int l, int r, int p, int x) {
if (l == r)
return ans[p];
pushdown(p);
int res = x <= mid ? qry(l, mid, ls, x) : qry(mid + 1, r, rs, x);
return min(res, ans[p]);
}
} t;
int ans = 1e18;
void solve() {
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
lsh[i] = a[i].y;
sort(lsh + 1, lsh + n + 1);
tot = unique(lsh + 1, lsh + n + 1) - lsh - 1;
for (int i = 1; i <= n; i++)
a[i].y = lower_bound(lsh + 1, lsh + tot + 1, a[i].y) - lsh;
t1 = BIT(), t2 = BIT();
for (int i = 1; i <= n; i++) {
if (a[i].c == 0)
t1.mdf(a[i].y, lsh[a[i].x] + lsh[a[i].y]);
else if (a[i].c == 1)
t2.mdf(a[i].y, t1.qry(a[i].y));
else
ans = min(ans, lsh[a[i].x] + lsh[a[i].y] - t2.qry(a[i].y));
}
// for (int i = 1; i <= n; i++) {
// if (a[i].c == 0)
// t.mdf(1, tot, 1, a[i].y + 1, tot, lsh[a[i].x] + lsh[a[i].y], 1e18);
// else if (a[i].c == 1)
// t.mdf(1, tot, 1, a[i].y + 1, tot, -1e18, lsh[a[i].y]);
// else
// ans = min(ans, lsh[a[i].x] + t.qry(1, tot, 1, a[i].y));
// }
}
signed main() {
n = read();
for (int i = 1; i <= n; i++)
a[i].x = read(), a[i].y = read(), a[i].c = read(), b[i] = a[i];
for (int o = 0; o < 6; o++) {
for (int i = 1; i <= n; i++)
a[i] = b[i], a[i].c = od[o][b[i].c];
solve();
for (int i = 1; i <= n; i++)
a[i] = b[i], a[i].x = -a[i].x, a[i].c = od[o][b[i].c];
solve();
for (int i = 1; i <= n; i++)
a[i] = b[i], a[i].y = -a[i].y, a[i].c = od[o][b[i].c];
solve();
for (int i = 1; i <= n; i++)
a[i] = b[i], a[i].x = -a[i].x, a[i].c = od[o][b[i].c];
solve();
}
printf("%lld", ans * 2);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
10 9991473 83825681 1 26476526 51616963 1 50765942 43355004 0 53028333 5604344 2 57100206 5782798 0 80628150 92688632 2 82964896 73929713 2 85102330 11439534 1 86076990 82286008 0 89626190 52420216 0