QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#163091#7105. Pixel Artucup-team1321AC ✓342ms13888kbC++232.5kb2023-09-03 20:29:522023-09-04 04:31:28

Judging History

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

  • [2023-09-04 04:31:28]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:342ms
  • 内存:13888kb
  • [2023-09-03 20:29:53]
  • 评测
  • 测评结果:100
  • 用时:371ms
  • 内存:13792kb
  • [2023-09-03 20:29:52]
  • 提交

answer

#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rp(i, n) rep(i, 0, n)
#define pb emplace_back
using namespace std;
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
  x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
  x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
template <class T> using vc = vector<T>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
mt19937 rng(time(NULL));
const int inf = 1000000000;
const ll lnf = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)

void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  vi r1(k), r2(k), c1(k), c2(k);
  vc<vi> add(n), del(n);
  rp(i, k) {
    cin >> r1[i] >> c1[i] >> r2[i] >> c2[i];
    r1[i]--;
    c1[i]--;
    add[r1[i]].pb(i);
    if (r2[i] < n) {
      del[r2[i]].pb(i);
    }
  }

  vi f(k);
  iota(all(f), 0);
  auto find = [&](int x) {
    while (x != f[x]) {
      x = f[x] = f[f[x]];
    }
    return x;
  };


  ll ans = 0;
  int comp = 0;
  int width = 0;
  auto merge = [&](int x, int y) {
    x = find(x);
    y = find(y);
    if (x != y) {
      f[y] = x;
      comp--;
    }
  };

  set<array<int, 3>> s;

  for (int x = 0; x < n; x++) {
    for (int i : add[x]) {
      auto it = s.lower_bound({c1[i], 0, 0});
      if (it != s.begin()) {
        it--;
      }
      while (it != s.end() && (*it)[0] < c2[i]) {
        if ((*it)[1] > c1[i]) {
          merge((*it)[2], i);
        }
        it++;
      }
    }
    for (int i : del[x]) {
      width -= c2[i] - c1[i];
      s.erase({c1[i], c2[i], i});
    }
    for (int i : add[x]) {
      auto it = s.insert({c1[i], c2[i], i}).first;
      if (it != s.begin()) {
        auto prv = prev(it);
        if ((*prv)[1] == c1[i]) {
          merge((*prv)[2], i);
        }
      }
      auto nxt = next(it);
      if (nxt != s.end()) {
        if ((*nxt)[0] == c2[i]) {
          merge((*nxt)[2], i);
        }
      }
      width += c2[i] - c1[i];
      comp++;
    }
    ans += width;
    cout << ans << " " << comp << "\n";
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 342ms
memory: 13888kb

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