Submission #878922

# Submission time Handle Problem Language Result Execution time Memory
878922 2023-11-25T14:00:08 Z TheSahib Chessboard (IZhO18_chessboard) C++17
39 / 100
785 ms 7044 KB
#include <bits/stdc++.h>

#define ll long long
#define oo 1e9
#define pii pair<int, int>

using namespace std;

const int MAX = 1e5 + 5;

int tree[MAX * 4], lazy[MAX * 4];

void build(int node, int l, int r, int k){
    lazy[node] = 0;
    if(l == r){
        tree[node] = ((l - 1) / k) & 1;
        return;
    }
    int mid = (l + r) / 2;
    build(node * 2, l, mid, k);
    build(node * 2 + 1, mid + 1, r, k);
    tree[node] = tree[node * 2] + tree[node * 2 + 1];
}

void relax(int node, int l, int r){
    if(!lazy[node]) return;
    tree[node] = (r - l + 1) - tree[node];
    if(l != r){
        lazy[node * 2] ^= 1;
        lazy[node * 2 + 1] ^= 1;
    }
    lazy[node] = 0;
    return;
}

void update(int node, int l, int r, int ql, int qr){
    relax(node, l, r);
    if(ql > r || qr < l) return;
    if(ql <= l && r <= qr){
        lazy[node] ^= 1;
        relax(node, l, r);
        return;
    }
    int mid = (l + r) / 2;
    update(node * 2, l, mid, ql, qr);
    update(node * 2 + 1, mid + 1, r, ql, qr);
    tree[node] = tree[node * 2] + tree[node * 2 + 1];
}

vector<array<int, 2>> events[MAX];
int n, k; 

ll check(int d){
    build(1, 1, n, d);
    ll a = 0, b = 0;
    for (int i = 1; i <= n; i++)
    {
        if((i - 1) % d == 0) lazy[1] ^= 1;
        for(auto& e:events[i]){
            update(1, 1, n, e[0], e[1]);
        }
        relax(1, 1, n);
        a += tree[1];
        b += n - tree[1];
    }
    return min(a, b);
}

void solve(){
    cin >> n >> k;
    for (int i = 0; i < k; i++)
    {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        events[x1].push_back({y1, y2});
        events[x2 + 1].push_back({y1, y2});
    }
    ll ans = oo;
    for (int i = 1; i * i <= n; i++)
    {
        if(n % i == 0){
            ans = min(ans, check(i));
            if(i != 1){
                ans = min(ans, check(n / i));
            }
        }
    }
    cout << ans << '\n';
}

int main()
{
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 99 ms 7044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 3 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 1 ms 4732 KB Output is correct
7 Correct 3 ms 4700 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 2 ms 4756 KB Output is correct
14 Correct 2 ms 4704 KB Output is correct
15 Correct 2 ms 4704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4952 KB Output is correct
4 Correct 3 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 1 ms 4732 KB Output is correct
7 Correct 3 ms 4700 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 2 ms 4756 KB Output is correct
14 Correct 2 ms 4704 KB Output is correct
15 Correct 2 ms 4704 KB Output is correct
16 Correct 40 ms 5208 KB Output is correct
17 Correct 78 ms 7000 KB Output is correct
18 Correct 144 ms 6960 KB Output is correct
19 Correct 692 ms 6872 KB Output is correct
20 Correct 785 ms 6860 KB Output is correct
21 Correct 72 ms 6880 KB Output is correct
22 Correct 4 ms 4700 KB Output is correct
23 Correct 106 ms 5808 KB Output is correct
24 Correct 129 ms 6908 KB Output is correct
25 Correct 23 ms 4956 KB Output is correct
26 Correct 86 ms 6048 KB Output is correct
27 Correct 132 ms 6740 KB Output is correct
28 Correct 147 ms 6864 KB Output is correct
29 Correct 31 ms 5464 KB Output is correct
30 Correct 5 ms 4816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 99 ms 7044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Incorrect 99 ms 7044 KB Output isn't correct
10 Halted 0 ms 0 KB -