QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#163066#7105. Pixel Arthos_lyricAC ✓395ms17312kbC++144.3kb2023-09-03 20:00:582023-09-04 04:31:27

Judging History

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

  • [2023-09-04 04:31:27]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:395ms
  • 内存:17312kb
  • [2023-09-03 20:00:59]
  • 评测
  • 测评结果:100
  • 用时:393ms
  • 内存:17052kb
  • [2023-09-03 20:00:58]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


vector<int> uf;
int root(int u) {
  return (uf[u] < 0) ? u : (uf[u] = root(uf[u]));
}
bool connect(int u, int v) {
  u = root(u);
  v = root(v);
  if (u == v) return false;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
  return true;
}


int M, N, K;
vector<int> X0, X1, Y0, Y1;

void transpose() {
  swap(M, N);
  for (int k = 0; k < K; ++k) {
    swap(X0[k], Y0[k]);
    swap(X1[k], Y1[k]);
  }
}

vector<vector<pair<int, int>>> edgess;
void solve(int phase) {
  vector<vector<int>> kss0(M + 1), kss1(M + 1);
  for (int k = 0; k < K; ++k) {
    kss0[X0[k]].push_back(k);
    kss1[X1[k]].push_back(k);
  }
  auto cmpY = [&](int k0, int k1) -> bool {
    return (Y0[k0] < Y0[k1]);
  };
  for (int x = 0; x <= M; ++x) {
    sort(kss0[x].begin(), kss0[x].end(), cmpY);
    sort(kss1[x].begin(), kss1[x].end(), cmpY);
  }
  // x-1, x
  for (int x = 1; x < M; ++x) {
    const auto &ks1 = kss1[x];
    const auto &ks0 = kss0[x];
    for (int i1 = 0, i0 = 0; i1 < (int)ks1.size() && i0 < (int)ks0.size(); ) {
      const int k1 = ks1[i1];
      const int k0 = ks0[i0];
      if (Y1[k1] <= Y0[k0]) {
        ++i1;
      } else if (Y1[k0] <= Y0[k1]) {
        ++i0;
      } else {
        const int y = max(Y0[k1], Y0[k0]);
        assert(y < Y1[k1]);
        assert(y < Y1[k0]);
        edgess[phase ? y : x].emplace_back(k1, k0);
        (Y1[k1] <= Y1[k0]) ? ++i1 : ++i0;
      }
    }
  }
}

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d%d%d", &M, &N, &K);
    X0.resize(K);
    X1.resize(K);
    Y0.resize(K);
    Y1.resize(K);
    for (int k = 0; k < K; ++k) {
      scanf("%d%d%d%d", &X0[k], &Y0[k], &X1[k], &Y1[k]);
      --X0[k];
      --Y0[k];
    }
    
    vector<Int> areas(M + 1, 0);
    for (int k = 0; k < K; ++k) {
      const int dy = Y1[k] - Y0[k];
      areas[X0[k]] += dy;
      areas[X1[k]] -= dy;
    }
    for (int x = 0; x < M; ++x) areas[x + 1] += areas[x];
    for (int x = 0; x < M; ++x) areas[x + 1] += areas[x];
    
    // done area -> compress
    vector<int> ys(K << 1);
    for (int k = 0; k < K; ++k) {
      ys[k << 1 | 0] = Y0[k];
      ys[k << 1 | 1] = Y1[k];
    }
    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
    N = (int)ys.size() - 1;
    for (int k = 0; k < K; ++k) {
      Y0[k] = lower_bound(ys.begin(), ys.end(), Y0[k]) - ys.begin();
      Y1[k] = lower_bound(ys.begin(), ys.end(), Y1[k]) - ys.begin();
    }
    
    vector<int> app(M + 1, 0);
    for (int k = 0; k < K; ++k) {
      ++app[X0[k]];
    }
    edgess.assign(M, {});
    solve(0);
    transpose();
    solve(1);
    transpose();
    
    uf.assign(K, -1);
    int numComps = 0;
    for (int x = 0; x < M; ++x) {
      numComps += app[x];
      for (const auto &edge : edgess[x]) {
        if (connect(edge.first, edge.second)) {
          --numComps;
        }
      }
      printf("%lld %d\n", areas[x], numComps);
    }
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3828kb

input:

3
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2

result:

ok 7 lines

Test #2:

score: 0
Accepted
time: 395ms
memory: 17312kb

input:

2130
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3
3 100 51
1 2 2 2
1 4 2 4
1 6 2 6
1 8 2 8
1 10 2 10
1 12 2 12
1 14 2 14
1 16 2 16
1 18 2 18
1 20 2 20
1 22 2 22
1 24 2 24
1 26 2 26
1 28 2 28
1 30 2 30
1 32 2 32
1 34 2 34
1 36 2 36
1 38 2 38
1 40 2 40
1 42 2 42
1 44 2 44
...

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2
50 50
100 50
200 1
50 50
150 1
200 1
2 1
4 1
6 1
8 1
10 1
12 1
14 1
16 1
18 1
20 1
22 1
24 1
26 1
28 1
30 1
32 1
34 1
36 1
38 1
40 1
42 1
44 1
46 1
48 1
50 1
52 1
54 1
56 1
58 1
60 1
62 1
64 1
66 1
68 1
70 1
72 1
74 1
76 1
78 1
80 1
82 1
84 1
86 1
88 1
90 1
92 1
94 1
96 1...

result:

ok 355756 lines

Extra Test:

score: 0
Extra Test Passed