QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#515263#2266. Colorful RectanglePlentyOfPenalty#WA 110ms9956kbC++203.8kb2024-08-11 16:36:342024-08-11 16:36:35

Judging History

你现在查看的是最新测评结果

  • [2024-08-11 16:36:35]
  • 评测
  • 测评结果:WA
  • 用时:110ms
  • 内存:9956kb
  • [2024-08-11 16:36:34]
  • 提交

answer

#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#define rep(i, l, r) for (int i = (l), i##end = (r); i <= i##end; ++i)
#define per(i, l, r) for (int i = (l), i##end = (r); i >= i##end; --i)
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define log(...) (void(0))
#define endl '\n'
#endif
using namespace std;
using ll = long long;
using lf = long double;
using lll = __int128;
using ull = unsigned long long;
const int N = 1e5 + 10;
const int INF = 1e9;
struct elem {
  int x, y, ty, c;
  bool operator<(const elem &t) const { return x == t.x ? (c == t.c ? y < t.y : c < t.c) : x < t.x; }
} a[N], ta[N];
struct st {
  int v, *pos;
  bool operator<(const st &t) const { return v < t.v; }
} ar[N];
struct BIT {
  int n, mn[N], vis[N], TIM;
  void clear() { ++TIM; }
  void init(int x) { n = x; }
  void Ins(int x, int v) {
    while (x <= n) mn[x] = (vis[x] == TIM ? min(mn[x], v) : (vis[x] = TIM, v)), x += (x & -x);
  }
  int Que(int x) {
    static int ret;
    ret = INF;
    while (x) ret = (vis[x] == TIM ? min(ret, mn[x]) : ret), x -= (x & -x);
    return ret;
  }
} B1, B2;
int ans, m;
void Getans(int n) {
  // log("!!GETANS:\n");
  // for (int i = 1; i <= n; ++i) log("(%d,%d) %d\n", ta[i].x, ta[i].y, ta[i].c);
  B1.clear(), B2.clear();
  static int premin, mnx;
  premin = INF;
  for (int i = n; i >= 1; --i) {
    // log("i=%d\n", i);
    if (!ta[i].c) {
      ans = min(ans, ta[i].y - ta[i].x + premin);
      // log("CMIN %d\n", ta[i].y - ta[i].x + premin);
    } else if (ta[i].c == 1) {
      mnx = min(B1.Que(m - ta[i].ty + 1) - ta[i].y, B2.Que(ta[i].ty));
      premin = min(premin, mnx);
      // log("premin %d\n", premin);
    } else {
      B1.Ins(m - ta[i].ty + 1, ta[i].x);
      B2.Ins(ta[i].ty, ta[i].x - ta[i].y);
    }
  }
  // log("Done,ans=%d\n", ans);
}
int n;
int xi[N], yi[N], py[N], ci[N];
int sz;
void Solve(int l, int r, int al, int ar) {
  if (l > r || al > ar) return;
  // log(">>>>>SOLVE %d %d,ar:\n", l, r);
  // for (int i = al; i <= ar; ++i) log("(%d,%d[%d]) %d\n", a[i].x, a[i].y, a[i].ty, a[i].c);
  int mid = (l + r >> 1);
  // log("MID=%d\n", mid);
  sz = 0;
  for (int i = al; i <= ar; ++i) {
    if (!a[i].c && a[i].ty >= mid) ta[++sz] = a[i];
    if (a[i].c && a[i].ty <= mid) ta[++sz] = a[i];
  }
  Getans(sz);
  int p1 = al - 1, p2 = ar + 1;
  for (int i = al; i <= ar; ++i) {
    if (a[i].ty > mid) ta[--p2] = a[i];
    if (a[i].ty < mid) ta[++p1] = a[i];
  }
  for (int i = al; i <= p1; ++i) a[i] = ta[i];
  for (int i = p2; i <= ar; ++i) a[p2 + ar - i] = ta[i];
  Solve(l, mid - 1, al, p1), Solve(mid + 1, r, p2, ar);
}
int tc[N];
void Calc(int x, int y, int z) {
  // log("---------------------\nCALC %d%d%d\nsets:\n", x, y, z);
  for (int i = 1; i <= n; ++i) ci[i] = (tc[i] == x ? 0 : (tc[i] == y ? 1 : 2));
  // for (int i = 1; i <= n; ++i) log("(%d,%d) %d\n", xi[i], yi[i], ci[i]);
  for (int i = 1; i <= n; ++i) ar[i] = (st){yi[i], &py[i]};
  sort(ar + 1, ar + n + 1);
  m = 0;
  ar[0].v = -INF;
  for (int i = 1; i <= n; ++i) m += (ar[i].v != ar[i - 1].v), *ar[i].pos = m;
  for (int i = 1; i <= n; ++i) a[i] = (elem){xi[i], yi[i], py[i], ci[i]};
  sort(a + 1, a + n + 1);
  B1.init(m), B2.init(m);
  Solve(1, m, 1, n);
  log("ans=%d\n", ans);
}
void Rotate() {
  for (int i = 1; i <= n; ++i) swap(xi[i], yi[i]), yi[i] = -yi[i];
}
int main() {
#ifdef memset0
  freopen("D.in", "r", stdin);
#endif
  // cin.tie(0)->sync_with_stdio(0);
  ans = INF;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> xi[i] >> yi[i] >> tc[i];
  for (int i = 0; i < 4; ++i) {
    log("`````````````````````ROT=%d\n", i);
    Calc(0, 1, 2);
    Calc(0, 2, 1);
    Calc(1, 0, 2);
    Calc(1, 2, 0);
    Calc(2, 0, 1);
    Calc(2, 1, 0);
    Rotate();
  }
  assert(ans >= 0);
  cout << (ans << 1) << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9784kb

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: 9776kb

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: 1ms
memory: 9852kb

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: -100
Wrong Answer
time: 110ms
memory: 9956kb

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:

490286

result:

wrong answer 1st lines differ - expected: '476190', found: '490286'