답안 #492357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492357 2021-12-07T02:41:03 Z Rainbowbunny Chessboard (IZhO18_chessboard) C++17
8 / 100
94 ms 4924 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 5;

int n, k;   
int xl[MAXN], xr[MAXN], yl[MAXN], yr[MAXN]; 

int ST[4 * MAXN], Lazy[4 * MAXN];

void Build(int node, int l, int r, int id)
{
    Lazy[node] = 0;
    if(l == r)
    {
        ST[node] = ((l - 1) / id) & 1;
        return;
    }
    int mid = (l + r) >> 1;
    Build(node << 1, l, mid, id);
    Build(node << 1 | 1, mid + 1, r, id);
    ST[node] = ST[node << 1] + ST[node << 1 | 1];
}

void Push(int node, int l, int r)
{
    if(Lazy[node])
    {
        ST[node] = (r - l + 1) - ST[node];
        if(l != r)
        {
            Lazy[node << 1] ^= Lazy[node];
            Lazy[node << 1 | 1] ^= Lazy[node];
        }
        Lazy[node] = 0;
    }
}

void Update(int node, int l, int r, int L, int R)
{
    Push(node, l, r);
    if(l > R or r < L or L > R)
    {
        return;
    }
    if(L <= l and r <= R)
    {
        Lazy[node] = 1;
        Push(node, l, r);
        return;
    }
    int mid = (l + r) >> 1;
    Update(node << 1, l, mid, L, R);
    Update(node << 1 | 1, mid + 1, r, L, R);
    ST[node] = ST[node << 1] + ST[node << 1 | 1];
}

vector <pair <int, pair <int, int> > > Queries;

long long Solve(int id)
{
    long long ans1 = 0;
    int pt = 0;
    Build(1, 1, n, id);
    for(int i = 1; i <= n; i++)
    {
        while(pt < (int)Queries.size() and Queries[pt].first == i)
        {
            Update(1, 1, n, Queries[pt].second.first, Queries[pt].second.second);
            pt++;
        }
        if(i % id == 0)
        {
            Update(1, 1, n, 1, n);
        }
        ans1 += ST[1];
    }
    return min(ans1, 1ll * n * n - ans1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long ans = 1e18;
    cin >> n >> k;
    for(int i = 1; i <= k; i++)
    {
        cin >> xl[i] >> yl[i] >> xr[i] >> yr[i];
    }
    for(int i = 1; i <= k; i++)
    {
        Queries.emplace_back(xl[i], make_pair(yl[i], yr[i]));
        Queries.emplace_back(xr[i] + 1, make_pair(yl[i], yr[i]));
    } 
    sort(Queries.begin(), Queries.end());
    for(int i = 1; i < n; i++)
    {
        if(n % i == 0)
        {
            ans = min(ans, Solve(i));
        }
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 3824 KB Output is correct
2 Correct 18 ms 1480 KB Output is correct
3 Correct 47 ms 4032 KB Output is correct
4 Correct 41 ms 2632 KB Output is correct
5 Correct 62 ms 3516 KB Output is correct
6 Correct 39 ms 2868 KB Output is correct
7 Correct 8 ms 1164 KB Output is correct
8 Correct 38 ms 2880 KB Output is correct
9 Correct 91 ms 4924 KB Output is correct
10 Correct 53 ms 3472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 3824 KB Output is correct
2 Correct 18 ms 1480 KB Output is correct
3 Correct 47 ms 4032 KB Output is correct
4 Correct 41 ms 2632 KB Output is correct
5 Correct 62 ms 3516 KB Output is correct
6 Correct 39 ms 2868 KB Output is correct
7 Correct 8 ms 1164 KB Output is correct
8 Correct 38 ms 2880 KB Output is correct
9 Correct 91 ms 4924 KB Output is correct
10 Correct 53 ms 3472 KB Output is correct
11 Incorrect 1 ms 332 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -