QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#648347#9464. 基础 01? 练习题hos_lyric#0 0ms0kbC++144.2kb2024-10-17 18:34:142024-10-17 18:34:24

Judging History

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

  • [2024-10-17 18:34:24]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-10-17 18:34:14]
  • 提交

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


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, int>>> ess(N);
  for (int x0 = 0; x0 < N; ++x0) for (int x1 = x0 + 1; x1 < N; ++x1) {
    const int y = max((~B[x0] & B[x1])._Find_first(), (B[x0] & ~B[x1])._Find_first());
    if (y < N) {
      ess[y].emplace_back(x0, x1);
      ess[y].emplace_back(x0, N + y);
    }
  }
  for (int y0 = 0; y0 < N; ++y0) for (int y1 = y0 + 1; y1 < N; ++y1) {
    const int x = max((~C[y0] & C[y1])._Find_first(), (C[y0] & ~C[y1])._Find_first());
    if (x < N) {
      ess[y1].emplace_back(N + y0, N + y1);
      ess[y1].emplace_back(N + y0, x);
    }
  }
  
  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);
// 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
Runtime Error

Test #1:

score: 0
Runtime Error

input:

15 15
0???0??01???1??
2 14
0 9
6 10
1 14
1 14
0 12
5 14
6 7
0 6
4 14
1 12
10 10
0 14
1 12
4 7

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #7:

score: 0
Runtime Error

input:

20 200000
???10?10???????1????
1 19
2 17
5 19
6 19
6 15
5 19
1 11
0 15
4 6
3 16
10 13
12 18
16 16
0 15
7 14
2 11
14 19
9 16
0 18
11 16
7 13
1 17
5 18
7 7
6 10
4 17
5 19
2 9
0 16
1 19
5 14
4 19
0 11
0 16
15 19
0 12
1 15
4 17
13 16
3 14
4 13
5 13
3 10
0 19
2 17
6 18
0 18
7 10
3 18
10 14
1 13
0 16
0 19...

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #13:

score: 0
Runtime Error

input:

50000 200000
011001101001011?10011001011010010110011010011001011?011010010110?0011001011001101?011?010?10100101100110100110010110011?1001011010011001011?10010?1?0?10100101101?01100101100110100110010110?001011001101001100101100?10100101101?0110?10110011010011001011010010110011010010110100110?10110100...

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #19:

score: 0
Runtime Error

input:

50000 1
0101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010011001011001101001011010011001011010010110011010010110100110010110011010011001011010...

output:


result:


Subtask #5:

score: 0
Runtime Error

Test #25:

score: 0
Runtime Error

input:

50000 1
01011010011000110100110010110010?1001?0001011001101?001011001101?0101101?011011001101001010?10100101101001100101?01100101010?101001100110?1011010011001011010??110011?1?011001?1100110?101101001100101100100110010110011100110100101001?1?0?00?100101101001011001101001011100?1010010110101101001011...

output:


result:


Subtask #6:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

500 1000
011000100010010010010010110010101100101100101011010010011001101001011010011000010011010001011010000001100101100110100101101001001011010010110010110100101100111001100111010011010010110100110010110100101100110101000101100110100110010110100101100110100101101?01101101100101011001010010100110010...

output:

500 1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 8000 8500 9000 9500 10000 10500 11000 11500 12000 12500 13000 13500 14000 14500 15000 15500 16000 16500 17000 17500 18000 18500 19000 19500 20000 20500 21000 21500 22000 22500 23000 23500 24000 24500 25000 25500 26000 26500 27...

result:


Subtask #7:

score: 0
Time Limit Exceeded

Test #37:

score: 0
Time Limit Exceeded

input:

1000 2000
01100101101001011001101001011010011001011010010110011010011001011001101001011010011001011010010110011010000110100101101001100101100110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100101101001100101101001011001101001...

output:

1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000 20000 21000 22000 23000 24000 25000 26000 27000 28000 29000 30000 31000 32000 33000 34000 35000 36000 37000 38000 39000 40000 41000 42000 43000 44000 45000 46000 47000 48000 49000 50000 51000 520...

result:


Subtask #8:

score: 0
Time Limit Exceeded

Test #43:

score: 0
Time Limit Exceeded

input:

5000 100000
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:


result:


Subtask #9:

score: 0
Runtime Error

Test #49:

score: 0
Runtime Error

input:

20000 100000
????????????????????????????0??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:


result:


Subtask #10:

score: 0
Runtime Error

Test #55:

score: 0
Runtime Error

input:

50000 200000
?01101001011001?01?011?010?1001101001?110?001?0?1?1?001101?0110?101?010??01100110?00?1001011001101001011??001?001?110100101100110100101?01?0110?1011?011010011001?1?0100??110011?100?01101001100?011010?10??00110100?1?0?0110?1101?01??1?10??10010?10?00101?00??0???101101?0???010110??1?10011?...

output:


result: