QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#648392#9465. 基础 01 练习题hos_lyric#0 2749ms299320kbC++144.3kb2024-10-17 18:45:572024-10-17 18:45:58

Judging History

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

  • [2024-10-17 18:45:58]
  • 评测
  • 测评结果:0
  • 用时:2749ms
  • 内存:299320kb
  • [2024-10-17 18:45:57]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#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 <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#pragma GCC target("avx2")

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")


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


int N, Q, O;
vector<int> X0, X1, Y0, Y1;


namespace brute {
int A[5010][5010];
bitset<5010> B[5010], C[5010];

vector<Int> run() {
  for (int x = 0; x <= N; ++x) for (int y = 0; y <= N; ++y) A[x][y] = 0;
  for (int q = 0; q < Q; ++q) {
    A[X0[q]][Y0[q]] ^= 1;
    A[X0[q]][Y1[q]] ^= 1;
    A[X1[q]][Y0[q]] ^= 1;
    A[X1[q]][Y1[q]] ^= 1;
  }
  for (int x = 0; x <= N; ++x) for (int y = 0; y <= N; ++y) A[x + 1][y] ^= A[x][y];
  for (int x = 0; x <= N; ++x) for (int y = 0; y <= N; ++y) A[x][y + 1] ^= A[x][y];
// for(int x=0;x<N;++x){for(int y=0;y<N;++y)cerr<<A[x][y];cerr<<endl;}
  
  for (int x = 0; x < N; ++x) {
    B[x].reset();
    for (int y = 0; y < N; ++y) B[x][y] = A[x][y];
  }
  for (int y = 0; y < N; ++y) {
    C[y].reset();
    for (int x = 0; x < N; ++x) C[y][x] = A[x][y];
  }
  vector<vector<pair<int, pair<int, int>>>> ess(N);
  for (int x0 = 0; x0 < N; ++x0) for (int x1 = 0; x1 < x0; ++x1) {
    const int y = max((~B[x0] & B[x1])._Find_first(), (B[x0] & ~B[x1])._Find_first());
    if (y < N) {
      ess[y].emplace_back(N + y, make_pair(x0, x1));
    }
  }
  for (int y0 = 0; y0 < N; ++y0) for (int y1 = 0; y1 < y0; ++y1) {
    const int x = max((~C[y0] & C[y1])._Find_first(), (C[y0] & ~C[y1])._Find_first());
    if (x < N) {
      ess[y0].emplace_back(x, make_pair(N + y0, N + y1));
      break;
    }
  }
  
  vector<int> uf(N + N, -1);
  vector<Int> fs(N + N, 0), gs(N + N, 0);
  for (int x = 0; x < N; ++x) fs[x] = 1;
  for (int y = 0; y < N; ++y) gs[N + y] = 1;
  Int now = 0;
  auto conn = [&](int u, int v) -> void {
    u = root(uf, u);
    v = root(uf, v);
    if (u != v) {
      connect(uf, u, v);
      if (u != uf[v]) swap(u, v);
      assert(u == uf[v]);
      now -= max(fs[u] * gs[u] - 1, 0LL);
      now -= max(fs[v] * gs[v] - 1, 0LL);
      fs[u] += fs[v];
      gs[u] += gs[v];
      now += max(fs[u] * gs[u] - 1, 0LL);
    }
  };
  
  vector<Int> ans(N);
  for (int y = 0; y < N; ++y) {
    for (const auto &e : ess[y]) {
      conn(e.first, e.second.first);
      conn(e.first, e.second.second);
    }
// for(int r=0;r<N+N;++r)if(uf[r]<0)cerr<<make_pair(fs[r],gs[r])<<" ";cerr<<endl;
    ans[y] = N * (y + 1) - now;
  }
  if (O == 0) ans = {ans.back()};
  return ans;
}
}  // brute


int main() {
  for (; ~scanf("%d%d%d", &N, &Q, &O); ) {
    X0.resize(Q);
    X1.resize(Q);
    Y0.resize(Q);
    Y1.resize(Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d%d%d%d", &X0[q], &X1[q], &Y0[q], &Y1[q]);
      --X0[q];
      --Y0[q];
    }
    
    const auto ans = brute::run();
    for (int i = 0; i < (int)ans.size(); ++i) {
      if (i) printf(" ");
      printf("%lld", ans[i]);
    }
    puts("");
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 0ms
memory: 7936kb

input:

4 1000 0
2 3 1 2
1 3 1 3
1 2 1 2
1 2 3 4
1 4 2 4
1 3 1 2
1 4 1 2
1 3 1 4
3 3 2 3
1 2 2 4
4 4 1 3
3 3 3 4
3 4 3 4
2 3 1 1
1 2 2 4
1 4 3 4
3 4 1 2
1 2 2 3
3 4 3 3
1 2 4 4
4 4 2 4
1 4 1 1
1 1 1 3
2 3 2 3
1 1 2 4
2 3 2 4
3 3 1 4
3 3 3 3
1 3 3 3
2 3 2 4
3 3 2 2
1 3 2 4
1 3 1 2
3 4 1 2
2 3 1 3
1 1 1 2
1 2...

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 5
Accepted
time: 0ms
memory: 8012kb

input:

4 1000 0
1 4 3 3
2 3 4 4
3 4 3 4
3 4 1 2
1 4 2 4
2 3 1 3
3 4 2 4
2 3 3 3
3 4 1 3
1 3 1 4
2 3 1 3
1 1 2 2
1 4 3 4
1 4 1 3
1 2 3 4
1 2 1 2
2 3 1 4
2 2 2 2
1 3 1 3
2 2 2 4
1 2 1 4
1 1 1 1
1 2 3 4
4 4 1 3
2 4 1 3
1 1 1 3
1 4 2 2
2 3 1 2
2 2 1 2
1 2 1 4
1 4 2 4
1 2 1 3
1 2 1 3
2 4 2 2
1 2 1 1
1 2 1 3
2 4...

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

4 1000 0
1 4 1 2
1 4 2 2
1 4 3 4
2 4 4 4
2 3 3 4
2 4 2 4
1 2 2 2
4 4 2 4
1 3 1 3
1 4 1 4
3 3 3 4
4 4 2 3
2 3 1 4
2 2 1 3
2 3 2 4
2 2 1 4
1 2 2 3
1 4 1 3
4 4 1 4
3 4 1 4
1 2 1 2
1 2 1 3
2 2 3 3
1 2 1 4
1 1 1 4
2 2 1 4
1 4 3 4
2 4 2 4
2 2 1 4
3 4 1 3
2 3 2 4
1 3 1 4
1 3 1 4
3 3 1 3
1 2 1 3
3 3 1 4
1 4...

output:

8

result:

wrong answer 1st numbers differ - expected: '5', found: '8'

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 10
Accepted
time: 27ms
memory: 10540kb

input:

50 200000 0
1 45 2 6
29 44 2 6
31 37 2 50
2 37 1 19
7 13 8 38
38 46 19 38
10 30 30 46
22 42 1 45
5 35 24 27
10 36 19 31
20 47 17 35
7 9 23 42
15 26 31 42
7 8 7 42
1 26 33 48
2 5 30 36
17 44 21 44
5 44 24 36
19 47 15 17
29 36 2 42
31 34 11 41
9 24 12 30
30 43 8 20
2 12 13 20
11 12 10 15
14 22 3 29
2 ...

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Wrong Answer
time: 2ms
memory: 10012kb

input:

50 70 0
1 50 1 50
24 50 1 1
50 50 2 2
34 50 3 3
36 50 4 4
32 50 5 5
18 50 6 6
12 50 7 7
6 50 8 8
28 50 9 9
38 50 10 10
4 50 11 11
26 50 12 12
14 50 13 13
46 50 14 14
2 50 15 15
8 50 16 16
44 50 17 17
10 50 18 18
30 50 19 19
22 50 20 20
48 50 21 21
20 50 22 22
42 50 23 23
40 50 24 24
16 50 25 25
16 5...

output:

2299

result:

wrong answer 1st numbers differ - expected: '2280', found: '2299'

Subtask #3:

score: 0
Wrong Answer

Test #8:

score: 10
Accepted
time: 1887ms
memory: 281944kb

input:

5000 200000 0
1438 2561 3478 4930
1740 4634 87 3003
590 3275 1376 1681
2035 2793 2004 4945
567 3159 550 4470
61 3039 3431 3519
2654 3834 3460 4960
591 3560 409 443
345 2599 746 2891
1288 4570 1577 4402
249 377 1951 4534
2411 2455 294 1192
1679 3153 1645 4259
1735 1856 601 668
477 4881 411 2094
424 1...

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: 0
Wrong Answer
time: 2749ms
memory: 160620kb

input:

5000 200000 0
4336 5000 1 1
686 5000 2 2
3130 5000 3 3
672 5000 4 4
1664 5000 5 5
1480 5000 6 6
1326 5000 7 7
3726 5000 8 8
4170 5000 9 9
4794 5000 10 10
3374 5000 11 11
1836 5000 12 12
310 5000 13 13
2146 5000 14 14
3266 5000 15 15
820 5000 16 16
1152 5000 17 17
2876 5000 18 18
134 5000 19 19
828 5...

output:

6046380

result:

wrong answer 1st numbers differ - expected: '24995', found: '6046380'

Subtask #4:

score: 0
Wrong Answer

Test #14:

score: 10
Accepted
time: 1978ms
memory: 299320kb

input:

5000 200000 1
565 4401 1659 1826
429 1640 2999 3495
572 3994 9 3863
3844 4284 2307 3144
1054 1943 358 2592
727 4248 29 1171
1685 2392 4559 4929
1149 2787 1204 1947
2349 2619 405 998
1910 2786 25 1275
912 3475 4384 4387
3822 4895 1849 4548
3082 4749 3457 4220
3174 4885 117 1085
2517 3919 4325 4869
17...

output:

5000 5653 3715 1781 1031 823 540 185 190 71 56 61 66 71 76 81 86 91 96 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

result:

ok 5000 numbers

Test #15:

score: 0
Wrong Answer
time: 2575ms
memory: 111164kb

input:

5000 200000 1
1 1 4840 5000
2 2 1690 5000
3 3 908 5000
4 4 1212 5000
5 5 2712 5000
6 6 3950 5000
7 7 4724 5000
8 8 3706 5000
9 9 1888 5000
10 10 4056 5000
11 11 1074 5000
12 12 3806 5000
13 13 3756 5000
14 14 2822 5000
15 15 1264 5000
16 16 4088 5000
17 17 796 5000
18 18 4888 5000
19 19 4610 5000
20...

output:

5000 9997 14997 19997 24997 29994 34980 39966 44953 49938 54914 59886 64872 69848 74848 79811 84777 89746 94728 99694 104694 109641 114620 119580 124538 129473 134426 139354 144326 149248 154192 159107 164018 168925 173888 178758 183718 188645 193604 198604 203423 208296 213250 218126 222998 227825 ...

result:

wrong answer 7th numbers differ - expected: '34974', found: '34980'

Subtask #5:

score: 0
Runtime Error

Test #21:

score: 0
Runtime Error

input:

200000 200000 1
1 2 1 6
3 4 1 1
5 6 1 5
7 8 1 3
9 10 1 3
11 12 1 6
13 14 1 5
15 16 1 6
17 18 1 6
19 20 1 1
21 22 1 4
23 24 1 5
25 26 1 2
27 28 1 4
29 30 1 3
31 32 1 2
33 34 1 6
35 36 1 3
37 38 1 2
39 40 1 2
41 42 1 3
43 44 1 1
45 46 1 2
47 48 1 3
49 50 1 4
51 52 1 5
53 54 1 1
55 56 1 5
57 58 1 5
59 ...

output:


result:


Subtask #6:

score: 0
Runtime Error

Test #28:

score: 0
Runtime Error

input:

200000 200000 0
91264 123676 6826 154505
121351 188051 108158 131448
65413 163961 26771 116304
93852 110556 34929 187363
31794 142162 33578 38712
26574 67763 178013 197235
46436 146042 95 122860
11683 50463 60177 195245
60862 194711 37817 97212
144366 176271 113551 171098
120095 170517 73555 167299
...

output:


result:


Subtask #7:

score: 0
Runtime Error

Test #37:

score: 0
Runtime Error

input:

100000 200000 1
1 22878 1 2
1 7957 3 4
1 21779 5 6
1 34321 7 8
1 41692 9 10
1 49473 11 12
1 10254 13 14
1 43995 15 16
1 46975 17 18
1 668 19 20
1 25996 21 22
1 24975 23 24
1 43259 25 26
1 4174 27 28
1 39330 29 30
1 35462 31 32
1 27523 33 34
1 5574 35 36
1 47955 37 38
1 47013 39 40
1 3846 41 42
1 276...

output:


result: