QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#515720#2266. Colorful RectanglePlentyOfPenaltyWA 1ms5700kbC++204.7kb2024-08-11 21:58:042024-08-11 21:58:05

Judging History

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

  • [2024-08-11 21:58:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5700kb
  • [2024-08-11 21:58:04]
  • 提交

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;

inline void updmin(int &x, int y) {
  if (y < x) x = y;
}

const int N = 1e5 + 9, S = 300, inf = 2e8;
int n, m, ans;
vector<int> val;

struct atom {
  int x, y, ty, c, oc;
  bool operator<(const atom &rhs) const {
    if (x != rhs.x) return x < rhs.x;
    if (c != rhs.c) return c < rhs.c;
    return y < rhs.y;
  }
} a[N];

struct segment {
  int l, r, mid;
  int x2, xy2, s12, y1;
} p[N << 2];

void maintain(int u) {
  updmin(p[u].x2, min(p[u << 1].x2, p[u << 1 | 1].x2));
  updmin(p[u].xy2, min(p[u << 1].xy2, p[u << 1 | 1].xy2));
  updmin(p[u].s12, min(p[u << 1].s12, p[u << 1 | 1].s12));
}
void pushup(int u, int y1) {
  updmin(p[u].y1, y1);
  updmin(p[u].s12, y1 + p[u].x2);
}
void pushdown(int u) {
  if (p[u].y1 != inf && p[u].l != p[u].r) {
    pushup(u << 1, p[u].y1);
    pushup(u << 1 | 1, p[u].y1);
  }
  p[u].y1 = inf;
}

void build(int u, int l, int r) {
  p[u].l = l, p[u].r = r, p[u].mid = (l + r) >> 1;
  p[u].x2 = p[u].xy2 = p[u].s12 = p[u].y1 = inf;
  if (l == r) {
    return;
  }
  build(u << 1, l, p[u].mid);
  build(u << 1 | 1, p[u].mid + 1, r);
}

void modify12(int u, int k, int it) {
  pushdown(u);
  if (p[u].l == p[u].r) {
    updmin(p[u].s12, it);
    return;
  }
  modify12(k <= p[u].mid ? u << 1 : u << 1 | 1, k, it);
  maintain(u);
}
void modify2(int u, int k, const pair<int, int> &it) {
  pushdown(u);
  if (p[u].l == p[u].r) {
    updmin(p[u].x2, it.first);
    updmin(p[u].xy2, it.second);
    return;
  }
  modify2(k <= p[u].mid ? u << 1 : u << 1 | 1, k, it);
  maintain(u);
}
void modify1(int u, int l, int r, int it) {
  pushdown(u);
  if (p[u].l == l && p[u].r == r) {
    pushup(u, it);
    return;
  }
  if (r <= p[u].mid) {
    modify1(u << 1, l, r, it);
  } else if (l > p[u].mid) {
    modify1(u << 1 | 1, l, r, it);
  } else {
    modify1(u << 1, l, p[u].mid, it);
    modify1(u << 1 | 1, p[u].mid + 1, r, it);
  }
  maintain(u);
}

int query2(int u, int l, int r) {
  pushdown(u);
  if (p[u].l == l && p[u].r == r) return p[u].xy2;
  if (r <= p[u].mid) return query2(u << 1, l, r);
  if (l > p[u].mid) return query2(u << 1 | 1, l, r);
  return min(query2(u << 1, l, p[u].mid), query2(u << 1 | 1, p[u].mid + 1, r));
}
int query12(int u, int l, int r) {
  pushdown(u);
  if (p[u].l == l && p[u].r == r) return p[u].s12;
  if (r <= p[u].mid) return query12(u << 1, l, r);
  if (l > p[u].mid) return query12(u << 1 | 1, l, r);
  return min(query12(u << 1, l, p[u].mid), query12(u << 1 | 1, p[u].mid + 1, r));
}

void solve(int x, int y, int z) {
  log("\n\n\n=== solve %d %d %d ===\n", x, y, z);
  for (int i = 1; i <= n; i++) {
    a[i].c = a[i].oc == x ? 0 : (a[i].oc == y ? 1 : 2);
  }
  sort(a + 1, a + n + 1);
  build(1, 1, sz(val));
  for (int i = n; i >= 1; i--) {
    if (a[i].c == 2) {
      log("modify2 %d << %d %d\n", a[i].ty, a[i].x, a[i].x + a[i].y);
      modify2(1, a[i].ty, make_pair(a[i].x, a[i].x + a[i].y));
    } else if (a[i].c == 1) {
      log("modify12 %d >> %d\n", a[i].ty, query2(1, a[i].ty, sz(val)));
      modify12(1, a[i].ty, query2(1, a[i].ty, sz(val)));
      modify1(1, 1, a[i].ty, a[i].y);
    } else if (a[i].c == 0) {
      updmin(ans, query12(1, a[i].ty, sz(val)) - a[i].x - a[i].y);
    }
    log("i=%d >> (%d %d %d) >> ans=%d\n", i, a[i].x, a[i].y, a[i].c, ans);
  }
  // exit(0);
}

int main() {
#ifdef memset0
  freopen("D.in", "r", stdin);
#endif
  cin.tie(0)->sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].x >> a[i].y >> a[i].oc;
  }
  ans = inf;
  for (int t = 0; t < 4; t++) {
    for (int r = 0; r < 4; r++) {
      val.clear();
      for (int i = 1; i <= n; i++) {
        val.push_back(a[i].y);
      }
      sort(all(val));
      val.erase(unique(all(val)), val.end());
      for (int i = 1; i <= n; i++) {
        a[i].ty = lower_bound(all(val), a[i].y) - val.begin() + 1;
      }
      solve(0, 1, 2);
      solve(0, 2, 1);
      solve(1, 0, 2);
      solve(1, 2, 0);
      solve(2, 0, 1);
      solve(2, 1, 0);
      for (int i = 1; i <= n; i++) {
        swap(a[i].x, a[i].y), a[i].y *= -1;
      }
    }
    for (int i = 1; i <= n; i++) {
      a[i].y *= -1;
    }
  }
  cout << (ans << 1) << endl;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5700kb

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:

53366436

result:

wrong answer 1st lines differ - expected: '75818374', found: '53366436'