Submission #878921

# Submission time Handle Problem Language Result Execution time Memory
878921 2023-11-25T14:00:07 Z TheSahib Chessboard (IZhO18_chessboard) C++17
39 / 100
782 ms 8524 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 2 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4708 KB Output is correct
4 Correct 1 ms 4696 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 98 ms 8524 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 2 ms 4704 KB Output is correct
4 Correct 3 ms 4700 KB Output is correct
5 Correct 2 ms 4736 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 3 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 1 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 4728 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 3 ms 4700 KB Output is correct
15 Correct 2 ms 4700 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 2 ms 4704 KB Output is correct
4 Correct 3 ms 4700 KB Output is correct
5 Correct 2 ms 4736 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 3 ms 4700 KB Output is correct
8 Correct 2 ms 4700 KB Output is correct
9 Correct 1 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 4728 KB Output is correct
13 Correct 2 ms 4700 KB Output is correct
14 Correct 3 ms 4700 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 45 ms 5840 KB Output is correct
17 Correct 79 ms 8316 KB Output is correct
18 Correct 170 ms 8484 KB Output is correct
19 Correct 710 ms 8296 KB Output is correct
20 Correct 782 ms 8460 KB Output is correct
21 Correct 90 ms 8272 KB Output is correct
22 Correct 4 ms 4696 KB Output is correct
23 Correct 106 ms 6492 KB Output is correct
24 Correct 129 ms 8212 KB Output is correct
25 Correct 23 ms 5208 KB Output is correct
26 Correct 81 ms 6956 KB Output is correct
27 Correct 138 ms 7844 KB Output is correct
28 Correct 137 ms 8252 KB Output is correct
29 Correct 32 ms 5980 KB Output is correct
30 Correct 6 ms 4740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 8524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4708 KB Output is correct
4 Correct 1 ms 4696 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 98 ms 8524 KB Output isn't correct
10 Halted 0 ms 0 KB -