답안 #492355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492355 2021-12-07T02:36:38 Z Rainbowbunny Chessboard (IZhO18_chessboard) C++17
31 / 100
2000 ms 8956 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];
}

long long Solve(int id)
{
    long long ans1 = 0, ans2 = 0;
    vector <pair <int, pair <int, int> > > Queries;
    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]));
    } 
    for(int i = 1; i <= n; i++)
    {
        if(i % id == 0)
        {
            Queries.emplace_back(i + 1, make_pair(1, n));
        }
    }
    sort(Queries.begin(), Queries.end());
    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++;
        }
        ans1 += ST[1];
    }
    pt = 0;
    Build(1, 1, n, id);
    Update(1, 1, n, 1, n);
    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++;
        }
        ans2 += ST[1];
    }
    // cout << ans1 << ' ' << ans2 << '\n';
    return min(ans1, ans2);
}

int main()
{
    // freopen("Input.txt", "r", stdin);
    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 < 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 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 6128 KB Output is correct
2 Correct 26 ms 1864 KB Output is correct
3 Correct 79 ms 5864 KB Output is correct
4 Correct 68 ms 3516 KB Output is correct
5 Correct 94 ms 5688 KB Output is correct
6 Correct 64 ms 4320 KB Output is correct
7 Correct 17 ms 1604 KB Output is correct
8 Correct 61 ms 4160 KB Output is correct
9 Correct 164 ms 6944 KB Output is correct
10 Correct 89 ms 5440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 5 ms 356 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 324 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 4 ms 432 KB Output is correct
14 Correct 4 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 5 ms 356 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 324 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 3 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 4 ms 432 KB Output is correct
14 Correct 4 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 72 ms 2644 KB Output is correct
17 Correct 86 ms 6104 KB Output is correct
18 Correct 261 ms 8952 KB Output is correct
19 Correct 1876 ms 8508 KB Output is correct
20 Execution timed out 2047 ms 8956 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 6128 KB Output is correct
2 Correct 26 ms 1864 KB Output is correct
3 Correct 79 ms 5864 KB Output is correct
4 Correct 68 ms 3516 KB Output is correct
5 Correct 94 ms 5688 KB Output is correct
6 Correct 64 ms 4320 KB Output is correct
7 Correct 17 ms 1604 KB Output is correct
8 Correct 61 ms 4160 KB Output is correct
9 Correct 164 ms 6944 KB Output is correct
10 Correct 89 ms 5440 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 5 ms 356 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 2 ms 324 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 4 ms 432 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 3 ms 332 KB Output is correct
26 Correct 72 ms 2644 KB Output is correct
27 Correct 86 ms 6104 KB Output is correct
28 Correct 261 ms 8952 KB Output is correct
29 Correct 1876 ms 8508 KB Output is correct
30 Execution timed out 2047 ms 8956 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 109 ms 6128 KB Output is correct
10 Correct 26 ms 1864 KB Output is correct
11 Correct 79 ms 5864 KB Output is correct
12 Correct 68 ms 3516 KB Output is correct
13 Correct 94 ms 5688 KB Output is correct
14 Correct 64 ms 4320 KB Output is correct
15 Correct 17 ms 1604 KB Output is correct
16 Correct 61 ms 4160 KB Output is correct
17 Correct 164 ms 6944 KB Output is correct
18 Correct 89 ms 5440 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 5 ms 356 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 324 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 3 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 4 ms 432 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 72 ms 2644 KB Output is correct
35 Correct 86 ms 6104 KB Output is correct
36 Correct 261 ms 8952 KB Output is correct
37 Correct 1876 ms 8508 KB Output is correct
38 Execution timed out 2047 ms 8956 KB Time limit exceeded
39 Halted 0 ms 0 KB -