답안 #503155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503155 2022-01-07T11:47:07 Z Pety Chessboard (IZhO18_chessboard) C++14
47 / 100
2000 ms 12220 KB
#include <bits/stdc++.h>
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ll long long
#define ld long double

using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const int N = 1e5 + 2;

int n, sum[100002], k, lazy[400002], aint[400002], l[400002], r[400002];

struct query {
  int type, l, r;
  bool operator < (const query &other) {
    return type < other.type;
  }
};
vector<query>q[100002];

void push (int nod, int st, int dr) {
  if (lazy[nod] != -1) {
    if (st != dr) {
      lazy[2 * nod] = lazy[nod];
      lazy[2 * nod + 1] = lazy[nod];
    }
    if (lazy[nod] == 0)
      aint[nod] = sum[dr] - (st > 0 ? sum[st - 1] : 0);
    else
      aint[nod] = (dr - st + 1) - (sum[dr] - (st > 0 ? sum[st - 1] : 0));
  }
  lazy[nod] = -1;
}

int cnt = 0;

void update (int nod, int st, int dr, int a, int b, int val) {
  push(nod, st, dr);
  //cnt++;
  if (a <= st && dr <= b) {
    if (val == 0)
      aint[nod] = sum[dr] - (st > 0 ? sum[st - 1] : 0);
    else
      aint[nod] = (dr - st + 1) - (sum[dr] - (st > 0 ? sum[st - 1] : 0));
    if (st != dr) {
      lazy[2 * nod] = val;
      lazy[2 * nod + 1] = val;
    }
    return;
  }
  int  mij = ((st + dr) >> 1);
  if (a <= mij)
    update(2 * nod, st, mij, a, b, val);
  else
    update(2 * nod + 1, mij + 1, dr, a, b, val);
  aint[nod] = aint[2 * nod] + aint[2 * nod + 1];
}


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n >> k;
  while (k--) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--; y1--; x2--; y2--;
    q[x1].push_back({1, y1, y2});
    q[x2 + 1].push_back({0, y1, y2});
  }
  memset(l, -1, sizeof(l));
  memset(r, -1, sizeof(r));

  l[1] = 0;
  r[1] = n - 1;
  for (int i = 1; i <= 4 * n; i++) {
    if (l[i] < r[i]) {
      l[2 * i] = l[i];
      r[2 * i] = (l[i] + r[i]) / 2;
      l[2 * i + 1] = (l[i] + r[i]) / 2 + 1;
      r[2 * i + 1] = r[i];
    }
  }
  for (int i = 0; i < n; i++)
    sort(q[i].begin(), q[i].end());
  ll sol = 1ll * n * n, div = 0;;
  for (int lat = 1; lat < n; lat++) {
    if (n % lat == 0) {
      div++;
      for (int i = 0; i < n; i++) {
        sum[i] = ((i / lat) & 1) + (i > 0 ? sum[i - 1] : 0);
      }
      ll nr = 0;
      for (int i = 1; i <= 4 * n; i++) {
        if (l[i] == -1)
          continue;
        lazy[i] = -1;
        aint[i] = sum[r[i]] - (l[i] > 0 ? sum[l[i] - 1] : 0);
      }
      for (int i = 0; i < n; i++) {
        for (auto it : q[i]) {
          if (it.type == 0) 
            update(1, 0, n - 1, it.l, it.r, 0);
          else
            update(1, 0, n - 1, it.l, it.r, 1);
        }
        if ((i / lat) & 1)
          nr += n - aint[1];
        else
          nr += aint[1];
      }
      sol = min(sol, min(nr, 1l * n  * n - nr));
    }
  }
  cout << sol;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 2 ms 5708 KB Output is correct
3 Correct 3 ms 5808 KB Output is correct
4 Correct 5 ms 5708 KB Output is correct
5 Correct 3 ms 5712 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 3 ms 5708 KB Output is correct
8 Correct 3 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 9536 KB Output is correct
2 Correct 16 ms 6732 KB Output is correct
3 Correct 52 ms 9888 KB Output is correct
4 Correct 31 ms 7880 KB Output is correct
5 Correct 48 ms 9212 KB Output is correct
6 Correct 32 ms 8468 KB Output is correct
7 Correct 9 ms 6684 KB Output is correct
8 Correct 39 ms 8476 KB Output is correct
9 Correct 76 ms 9984 KB Output is correct
10 Correct 44 ms 9024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 3 ms 5708 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 4 ms 5836 KB Output is correct
5 Correct 5 ms 5748 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 4 ms 5836 KB Output is correct
9 Correct 4 ms 5708 KB Output is correct
10 Correct 3 ms 5708 KB Output is correct
11 Correct 4 ms 5836 KB Output is correct
12 Correct 4 ms 5836 KB Output is correct
13 Correct 4 ms 5836 KB Output is correct
14 Correct 5 ms 5760 KB Output is correct
15 Correct 3 ms 5836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 3 ms 5708 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 4 ms 5836 KB Output is correct
5 Correct 5 ms 5748 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 4 ms 5836 KB Output is correct
8 Correct 4 ms 5836 KB Output is correct
9 Correct 4 ms 5708 KB Output is correct
10 Correct 3 ms 5708 KB Output is correct
11 Correct 4 ms 5836 KB Output is correct
12 Correct 4 ms 5836 KB Output is correct
13 Correct 4 ms 5836 KB Output is correct
14 Correct 5 ms 5760 KB Output is correct
15 Correct 3 ms 5836 KB Output is correct
16 Correct 30 ms 6840 KB Output is correct
17 Correct 51 ms 9028 KB Output is correct
18 Correct 109 ms 9056 KB Output is correct
19 Correct 559 ms 9040 KB Output is correct
20 Correct 674 ms 9032 KB Output is correct
21 Correct 45 ms 9156 KB Output is correct
22 Correct 5 ms 5836 KB Output is correct
23 Correct 83 ms 7460 KB Output is correct
24 Correct 96 ms 9176 KB Output is correct
25 Correct 20 ms 6196 KB Output is correct
26 Correct 58 ms 7716 KB Output is correct
27 Correct 110 ms 8852 KB Output is correct
28 Correct 95 ms 8968 KB Output is correct
29 Correct 20 ms 7244 KB Output is correct
30 Correct 6 ms 5836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 9536 KB Output is correct
2 Correct 16 ms 6732 KB Output is correct
3 Correct 52 ms 9888 KB Output is correct
4 Correct 31 ms 7880 KB Output is correct
5 Correct 48 ms 9212 KB Output is correct
6 Correct 32 ms 8468 KB Output is correct
7 Correct 9 ms 6684 KB Output is correct
8 Correct 39 ms 8476 KB Output is correct
9 Correct 76 ms 9984 KB Output is correct
10 Correct 44 ms 9024 KB Output is correct
11 Correct 3 ms 5708 KB Output is correct
12 Correct 3 ms 5708 KB Output is correct
13 Correct 3 ms 5708 KB Output is correct
14 Correct 4 ms 5836 KB Output is correct
15 Correct 5 ms 5748 KB Output is correct
16 Correct 3 ms 5708 KB Output is correct
17 Correct 4 ms 5836 KB Output is correct
18 Correct 4 ms 5836 KB Output is correct
19 Correct 4 ms 5708 KB Output is correct
20 Correct 3 ms 5708 KB Output is correct
21 Correct 4 ms 5836 KB Output is correct
22 Correct 4 ms 5836 KB Output is correct
23 Correct 4 ms 5836 KB Output is correct
24 Correct 5 ms 5760 KB Output is correct
25 Correct 3 ms 5836 KB Output is correct
26 Correct 30 ms 6840 KB Output is correct
27 Correct 51 ms 9028 KB Output is correct
28 Correct 109 ms 9056 KB Output is correct
29 Correct 559 ms 9040 KB Output is correct
30 Correct 674 ms 9032 KB Output is correct
31 Correct 45 ms 9156 KB Output is correct
32 Correct 5 ms 5836 KB Output is correct
33 Correct 83 ms 7460 KB Output is correct
34 Correct 96 ms 9176 KB Output is correct
35 Correct 20 ms 6196 KB Output is correct
36 Correct 58 ms 7716 KB Output is correct
37 Correct 110 ms 8852 KB Output is correct
38 Correct 95 ms 8968 KB Output is correct
39 Correct 20 ms 7244 KB Output is correct
40 Correct 6 ms 5836 KB Output is correct
41 Correct 955 ms 11644 KB Output is correct
42 Correct 197 ms 12128 KB Output is correct
43 Correct 441 ms 11656 KB Output is correct
44 Correct 215 ms 11864 KB Output is correct
45 Correct 99 ms 12220 KB Output is correct
46 Correct 981 ms 12032 KB Output is correct
47 Correct 83 ms 11748 KB Output is correct
48 Correct 329 ms 11844 KB Output is correct
49 Correct 165 ms 11688 KB Output is correct
50 Execution timed out 2069 ms 11840 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5708 KB Output is correct
2 Correct 2 ms 5708 KB Output is correct
3 Correct 3 ms 5808 KB Output is correct
4 Correct 5 ms 5708 KB Output is correct
5 Correct 3 ms 5712 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 3 ms 5708 KB Output is correct
8 Correct 3 ms 5708 KB Output is correct
9 Correct 60 ms 9536 KB Output is correct
10 Correct 16 ms 6732 KB Output is correct
11 Correct 52 ms 9888 KB Output is correct
12 Correct 31 ms 7880 KB Output is correct
13 Correct 48 ms 9212 KB Output is correct
14 Correct 32 ms 8468 KB Output is correct
15 Correct 9 ms 6684 KB Output is correct
16 Correct 39 ms 8476 KB Output is correct
17 Correct 76 ms 9984 KB Output is correct
18 Correct 44 ms 9024 KB Output is correct
19 Correct 3 ms 5708 KB Output is correct
20 Correct 3 ms 5708 KB Output is correct
21 Correct 3 ms 5708 KB Output is correct
22 Correct 4 ms 5836 KB Output is correct
23 Correct 5 ms 5748 KB Output is correct
24 Correct 3 ms 5708 KB Output is correct
25 Correct 4 ms 5836 KB Output is correct
26 Correct 4 ms 5836 KB Output is correct
27 Correct 4 ms 5708 KB Output is correct
28 Correct 3 ms 5708 KB Output is correct
29 Correct 4 ms 5836 KB Output is correct
30 Correct 4 ms 5836 KB Output is correct
31 Correct 4 ms 5836 KB Output is correct
32 Correct 5 ms 5760 KB Output is correct
33 Correct 3 ms 5836 KB Output is correct
34 Correct 30 ms 6840 KB Output is correct
35 Correct 51 ms 9028 KB Output is correct
36 Correct 109 ms 9056 KB Output is correct
37 Correct 559 ms 9040 KB Output is correct
38 Correct 674 ms 9032 KB Output is correct
39 Correct 45 ms 9156 KB Output is correct
40 Correct 5 ms 5836 KB Output is correct
41 Correct 83 ms 7460 KB Output is correct
42 Correct 96 ms 9176 KB Output is correct
43 Correct 20 ms 6196 KB Output is correct
44 Correct 58 ms 7716 KB Output is correct
45 Correct 110 ms 8852 KB Output is correct
46 Correct 95 ms 8968 KB Output is correct
47 Correct 20 ms 7244 KB Output is correct
48 Correct 6 ms 5836 KB Output is correct
49 Correct 955 ms 11644 KB Output is correct
50 Correct 197 ms 12128 KB Output is correct
51 Correct 441 ms 11656 KB Output is correct
52 Correct 215 ms 11864 KB Output is correct
53 Correct 99 ms 12220 KB Output is correct
54 Correct 981 ms 12032 KB Output is correct
55 Correct 83 ms 11748 KB Output is correct
56 Correct 329 ms 11844 KB Output is correct
57 Correct 165 ms 11688 KB Output is correct
58 Execution timed out 2069 ms 11840 KB Time limit exceeded
59 Halted 0 ms 0 KB -