QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#208414 | #2266. Colorful Rectangle | AK_Dream | WA | 0ms | 10136kb | C++14 | 2.5kb | 2023-10-09 16:11:09 | 2023-10-09 16:11:10 |
Judging History
answer
#include <bits/stdc++.h>
#define N 100005
using namespace std;
const int inf = 0x3f3f3f3f;
int n, ans, srt[N], mx;
struct node {
int x, y, c;
} a[N], b[N];
struct BIT {
int tr[N];
void init() { memset(tr,0x3f,sizeof(tr)); }
void upd(int x, int v) { for(;x<=mx;x+=x&-x)tr[x]=min(tr[x],v); }
int qry(int x) { int r=inf;for(;x;x-=x&-x)r=min(r,tr[x]);return r; }
} T0, T1;
struct segtree {
int L[N<<2], R[N<<2], V[N<<2];
void build(int p, int l, int r) {
L[p] = R[p] = V[p] = inf;
if (l == r) return;
int mid = (l+r)>>1;
build(p<<1,l,mid); build(p<<1|1,mid+1,r);
}
inline void pushtg(int p, int vl, int vr) {
V[p] = min(V[p], L[p]+vr);
L[p] = min(L[p], vl); R[p] = min(R[p], vr);
}
inline void pushdw(int p) {
pushtg(p<<1,L[p],R[p]);
pushtg(p<<1|1,L[p],R[p]);
// R[p] = inf;
}
void upd(int p, int l, int r, int x, int y, int vl, int vr) {
if (x <= l && r <= y) return pushtg(p, vl, vr);
pushdw(p); int mid = (l+r)>>1;
if (x <= mid) upd(p<<1,l,mid,x,y,vl,vr);
if (mid < y) upd(p<<1|1,mid+1,r,x,y,vl,vr);
}
int qry(int p, int l, int r, int x) {
if (l == r) return V[p];
pushdw(p); int mid = (l+r)>>1;
if (x <= mid) return min(V[p],qry(p<<1,l,mid,x));
else return min(V[p],qry(p<<1|1,mid+1,r,x));
}
} T;
void solve() {
for (int i = 1; i <= n; i++) srt[i] = a[i].y;
sort(srt+1, srt+n+1); mx = unique(srt+1, srt+n+1)-srt-1;
for (int i = 1; i <= n; i++) a[i].y = lower_bound(srt+1,srt+mx+1,a[i].y)-srt;
sort(a+1, a+n+1, [&](node _,node __){ return _.x!=__.x?_.x<__.x:_.y<__.y; });
T0.init(); T1.init(); T.build(1,1,mx);
for (int i = 1; i <= n; i++) {
if (a[i].c == 0) T0.upd(a[i].y, -a[i].x-srt[a[i].y]);
else if (a[i].c == 1) T1.upd(a[i].y, T0.qry(a[i].y));
else ans = min(ans, a[i].x+srt[a[i].y]+T1.qry(a[i].y));
if (a[i].c == 0) T.upd(1,1,mx,a[i].y,mx,-a[i].x-srt[a[i].y],inf);
else if (a[i].c == 1) T.upd(1,1,mx,1,a[i].y,inf,srt[a[i].y]);
else ans = min(ans, T.qry(1,1,mx,a[i].y)+a[i].x);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
// int x, y; char c;
// scanf("%d %d %c", &x, &y, &c);
// b[i] = (node){x,y,c=='I'?0:c=='O'?1:2};
scanf("%d %d %d", &b[i].x, &b[i].y, &b[i].c);
}
ans = inf;
for (int tt = 0; tt < 4; tt++) {
int o[3] = {0,1,2};
do {
for (int i = 1; i <= n; i++) {
a[i] = b[i]; a[i].c = o[a[i].c];
}
solve();
} while (next_permutation(o,o+3));
for (int i = 1; i <= n; i++) {
swap(b[i].x, b[i].y);
b[i].y = 100000000-b[i].y;
}
}
printf("%d\n", ans*2);
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 10136kb
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:
26016124
result:
wrong answer 1st lines differ - expected: '75818374', found: '26016124'