Submission #378759

# Submission time Handle Problem Language Result Execution time Memory
378759 2021-03-17T03:55:11 Z abc864197532 Chessboard (IZhO18_chessboard) C++17
8 / 100
151 ms 23660 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, v;
};

vector <int> p;
int sz;

struct Seg {
    int l, r, m, lz;
    vector <int> tag, sum;
    Seg* ch[2];
    Seg (int _l, int _r) : l(_l), r(_r), m(l + r >> 1), lz(0) {
        sum.assign(sz, 0);
        if (r - l > 1) {
            ch[0] = new Seg(l, m);
            ch[1] = new Seg(m, r);
            for (int i = 0; i < sz; ++i) tag.pb(ch[0]->tag[i] + ch[1]->tag[i]);
        } else {
            for (int i = 0; i < sz; ++i) tag.pb((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, int 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];
    for (int i = 0, x1, y1, x2, y2; i < m; ++i) {
        cin >> x1 >> y1 >> x2 >> y2, --x1, --y1;
        block[x1].pb({y1, y2, 1});
        block[x2].pb({y1, y2, -1});
    }
    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]) root.modify(j.l, j.r, j.v);
        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:31:46: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |     Seg (int _l, int _r) : l(_l), r(_r), m(l + r >> 1), lz(0) {
      |                                            ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 23660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 23660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Incorrect 151 ms 23660 KB Output isn't correct
10 Halted 0 ms 0 KB -