QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#208409 | #2266. Colorful Rectangle | AK_Dream | WA | 65ms | 10304kb | C++14 | 2.5kb | 2023-10-09 16:06:47 | 2023-10-09 16:06:48 |
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]);
}
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: 100
Accepted
time: 1ms
memory: 9960kb
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:
75818374
result:
ok single line: '75818374'
Test #2:
score: 0
Accepted
time: 2ms
memory: 10084kb
input:
150 90758267 21234402 1 21737107 45944411 2 71064827 33646685 1 15732041 80099984 2 59366384 89336101 1 23463874 1772178 1 63300491 91439944 2 55016570 76385018 2 68263153 41801574 2 87098378 47936087 1 52162678 88263752 2 33679612 20590713 2 75242487 92720661 1 1669174 61465572 2 99532428 10613104 ...
output:
29171440
result:
ok single line: '29171440'
Test #3:
score: 0
Accepted
time: 0ms
memory: 9956kb
input:
10 4093976 78512657 0 27609174 62042588 1 31354091 61870386 0 35151441 36807411 1 37547440 25518220 0 44055162 7821981 2 66673981 41182270 0 83484785 58963611 1 83713705 24676214 2 88603397 80197017 0
output:
75778302
result:
ok single line: '75778302'
Test #4:
score: 0
Accepted
time: 65ms
memory: 10304kb
input:
10000 12096 65562074 1 14562 60486739 1 20187 50242814 1 35859 51060918 0 50463 52231435 1 56216 44100657 2 68431 98864745 1 73973 62323865 1 74745 22912751 2 100382 29322594 2 106833 31933585 2 123956 66437573 2 124095 72164704 2 130151 80006173 1 149897 26940530 1 150544 42049736 2 154249 83266583...
output:
476190
result:
ok single line: '476190'
Test #5:
score: 0
Accepted
time: 4ms
memory: 10048kb
input:
600 46864911 65058066 1 43812689 67844083 1 47624523 65356242 1 65763113 65439718 2 66870643 65931362 0 100000000 43232094 2 99773659 8651677 1 66502329 65775578 0 67130062 61467562 2 41297284 85249873 0 45570122 61586875 1 68626502 64903738 2 44727214 64595373 1 69383055 64974526 2 50960869 6495575...
output:
29384768
result:
ok single line: '29384768'
Test #6:
score: -100
Wrong Answer
time: 65ms
memory: 10200kb
input:
10000 2177 6599212 0 3313 13493229 1 8624 80455572 2 10635 33135945 0 13266 17210177 0 21252 67913127 0 25630 44096615 0 26868 61301695 0 35959 34225877 2 40034 86139028 1 49019 16335976 0 56879 37023369 1 58406 27475381 2 65029 74490416 1 76280 94487503 0 78480 69430131 0 79030 23340728 0 79320 803...
output:
885288
result:
wrong answer 1st lines differ - expected: '529732', found: '885288'