답안 #378819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378819 2021-03-17T05:13:19 Z abc864197532 Chessboard (IZhO18_chessboard) C++17
8 / 100
214 ms 136172 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int, int>
#define pll pair<lli, lli>
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define test(x) cout << #x << ' ' << x << endl
#define printv(x) {\
    for (auto a : x) cout << x << ' ';\
    cout << endl;\
}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int N = 2000000;

struct range {
    int l, r;
};

vector <int> p;
int sz;

struct Seg {
    int l, r, m;
    bool lz;
    int tag[128]{}, sum[128]{};
    Seg* ch[2];
    Seg (int _l, int _r) : l(_l), r(_r), m(l + r >> 1), lz(false) {
        if (r - l > 1) {
            ch[0] = new Seg(l, m);
            ch[1] = new Seg(m, r);
            for (int i = 0; i < sz; ++i) tag[i] = ch[0]->tag[i] + ch[1]->tag[i];
        } else {
            for (int i = 0; i < sz; ++i) tag[i] = (l / p[i]) & 1 ? -1 : 1;
        }
    }
    void pull() {
        for (int i = 0; i < sz; ++i) {
            if (lz) sum[i] = tag[i];
            else if (r - l == 1) sum[i] = 0;
            else sum[i] = ch[0]->sum[i] + ch[1]->sum[i];
        }
    }
    void modify(int a, int b, bool v) {
        if (a <= l && r <= b) lz = v;
        else {
            if (a < m) ch[0]->modify(a, b, v);
            if (m < b) ch[1]->modify(a, b, v);
        }
        pull();
    }
};

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i < n; ++i) if (n % i == 0) p.pb(i), sz++;
    vector <range> block[n + 1][2];
    for (int i = 0, x1, y1, x2, y2; i < m; ++i) {
        cin >> x1 >> y1 >> x2 >> y2, --x1, --y1;
        block[x1][1].pb({y1, y2});
        block[x2][0].pb({y1, y2});
    }
    lli ans = 1ll * n * n;
    vector <lli> cur(sz);
    for (int i = 0; i < sz; ++i) cur[i] = 1ll * p[i] * p[i] * (1ll * (n / p[i]) * (n / p[i]) / 2);
    Seg root(0, n);
    for (int i = 0; i <= n; ++i) {
        for (range &j : block[i][0]) root.modify(j.l, j.r, false);
        for (range &j : block[i][1]) root.modify(j.l, j.r, true);
        for (int j = 0; j < sz; ++j) {
            if ((i / p[j]) & 1) cur[j] -= root.sum[j];
            else cur[j] += root.sum[j];
            ans = min({ans, cur[j], 1ll * n * n - cur[j]});
        }
    }
    cout << ans << '\n';
}

/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
 */

Compilation message

chessboard.cpp: In constructor 'Seg::Seg(int, int)':
chessboard.cpp:32:46: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     Seg (int _l, int _r) : l(_l), r(_r), m(l + r >> 1), lz(false) {
      |                                            ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 214 ms 136172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 214 ms 136172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Incorrect 214 ms 136172 KB Output isn't correct
10 Halted 0 ms 0 KB -