QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200553 | #2266. Colorful Rectangle | ZZZ | WA | 13ms | 16836kb | C++14 | 3.0kb | 2023-10-04 17:30:09 | 2023-10-04 17:30:09 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#define rep(i, j, k) for (int i = j; i <= k; i++)
#define per(i, j, k) for (int i = j; i >= k; i--)
#define int long long
using namespace std;
int read() {
int s = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') { f = c == '-' ? -1 : 1, c = getchar(); }
while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
return s * f;
}
int n, o[3], lsh[100005], ans = 1e18;
const int N = 100000000, maxn = 100000;
struct node {
int x, y, c;
} a[100005], b[100005];
struct BIT {
int maxx[100005];
void clear() { memset(maxx, ~0x3f, sizeof maxx); }
void update(int x, int y) { for (; x <= maxn; x += x & -x) maxx[x] = max(maxx[x], y); }
int query(int x) { int res = -0x3f; for (; x; x -= x & -x) res = max(res, maxx[x]); return res; }
} b1, b2;
struct SGT {
int ans[400005], maxx[400005], minn[400005];
void init() {
memset(ans, 0x3f, sizeof ans);
memset(maxx, ~0x3f, sizeof maxx);
memset(minn, 0x3f, sizeof minn);
}
void pushtag(int t, int lx, int rn) {
ans[t] = min(ans[t], rn - maxx[t]);
minn[t] = min(minn[t], rn), maxx[t] = max(maxx[t], lx);
}
void pushdown(int t) {
pushtag(t << 1, maxx[t], minn[t]), pushtag(t << 1 | 1, maxx[t], minn[t]);
minn[t] = 1e18;
}
void update(int l, int r, int t, int x, int y, int L, int R) {
if (r < x || y < l) return ;
if (x <= l && r <= y) {
pushtag(t, L, R);
return ;
}
pushdown(t);
int mid = (l + r) >> 1;
update(l, mid, t << 1, x, y, L, R);
update(mid + 1, r, t << 1 | 1, x, y, L, R);
}
int query(int l, int r, int t, int x) {
if (l == r) return ans[t];
pushdown(t);
int mid = (l + r) >> 1, res = ans[t];
if (mid >= x) res = min(res, query(l, mid, t << 1, x));
else res = min(res, query(mid + 1, r, t << 1 | 1, x));
return res;
}
} t;
void solve() {
sort(a + 1, a + n + 1, [](node x, node y) { return x.x == y.x ? x.y < y.y : x.x < y.x; });
rep(i, 1, n) lsh[i] = a[i].y;
sort(lsh + 1, lsh + n + 1);
int len = unique(lsh + 1, lsh + n + 1) - lsh - 1;
rep(i, 1, n) a[i].y = lower_bound(lsh + 1, lsh + len + 1, a[i].y) - lsh;
b1.clear(), b2.clear();
rep(i, 1, n) {
if (!a[i].c) b1.update(a[i].y, a[i].x + lsh[a[i].y]);
else if (a[i].c == 1) b2.update(a[i].y, b1.query(a[i].y));
else ans = min(ans, a[i].x + lsh[a[i].y] - b2.query(a[i].y));
}
t.init();
rep(i, 1, n) {
if (!a[i].c) t.update(1, len, 1, a[i].y, len, a[i].x + lsh[a[i].y], 1e18);
else if (a[i].c == 1) t.update(1, len, 1, 1, a[i].y, -1e18, lsh[a[i].y]);
else ans = min(ans, a[i].x + t.query(1, len, 1, a[i].y));
}
}
signed main() {
n = read();
rep(i, 1, n) b[i].x = read(), b[i].y = read(), b[i].c = read();
o[0] = 0, o[1] = 1, o[2] = 2;
rep(T, 1, 4) {
rep(i, 1, n) {
int xx = b[i].x;
b[i].x = b[i].y;
b[i].y = N - xx + 1;
}
do {
rep(i, 1, n) {
a[i] = node{b[i].x, b[i].y, o[b[i].c]};
}
solve();
} while (next_permutation(o, o + 3));
}
printf("%lld\n", ans << 1);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 13ms
memory: 16836kb
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
output:
52331712
result:
wrong answer 1st lines differ - expected: '75818374', found: '52331712'