답안 #503153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503153 2022-01-07T11:41:58 Z Pety Chessboard (IZhO18_chessboard) C++14
8 / 100
63 ms 9636 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)
          break;
        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 5712 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 3 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 9636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 5708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 9636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 3 ms 5708 KB Output is correct
4 Correct 3 ms 5708 KB Output is correct
5 Correct 3 ms 5708 KB Output is correct
6 Correct 3 ms 5708 KB Output is correct
7 Correct 3 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Incorrect 63 ms 9636 KB Output isn't correct
10 Halted 0 ms 0 KB -