답안 #492356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
492356 2021-12-07T02:39:04 Z Rainbowbunny Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 11796 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;
    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];
    }
    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 < n; i++)
    {
        if(n % i == 0)
        {
            ans = min(ans, Solve(i));
        }
    }
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 4796 KB Output is correct
2 Correct 18 ms 1608 KB Output is correct
3 Correct 55 ms 5172 KB Output is correct
4 Correct 41 ms 2780 KB Output is correct
5 Correct 63 ms 4504 KB Output is correct
6 Correct 41 ms 3512 KB Output is correct
7 Correct 10 ms 1604 KB Output is correct
8 Correct 45 ms 3556 KB Output is correct
9 Correct 93 ms 5068 KB Output is correct
10 Correct 55 ms 4408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 420 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 3 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 420 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 46 ms 2324 KB Output is correct
17 Correct 61 ms 4972 KB Output is correct
18 Correct 171 ms 7428 KB Output is correct
19 Correct 1154 ms 7248 KB Output is correct
20 Correct 1302 ms 7776 KB Output is correct
21 Correct 60 ms 6080 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 156 ms 4240 KB Output is correct
24 Correct 152 ms 8444 KB Output is correct
25 Correct 32 ms 1240 KB Output is correct
26 Correct 95 ms 4980 KB Output is correct
27 Correct 179 ms 7192 KB Output is correct
28 Correct 165 ms 8756 KB Output is correct
29 Correct 27 ms 3012 KB Output is correct
30 Correct 5 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 4796 KB Output is correct
2 Correct 18 ms 1608 KB Output is correct
3 Correct 55 ms 5172 KB Output is correct
4 Correct 41 ms 2780 KB Output is correct
5 Correct 63 ms 4504 KB Output is correct
6 Correct 41 ms 3512 KB Output is correct
7 Correct 10 ms 1604 KB Output is correct
8 Correct 45 ms 3556 KB Output is correct
9 Correct 93 ms 5068 KB Output is correct
10 Correct 55 ms 4408 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 420 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 46 ms 2324 KB Output is correct
27 Correct 61 ms 4972 KB Output is correct
28 Correct 171 ms 7428 KB Output is correct
29 Correct 1154 ms 7248 KB Output is correct
30 Correct 1302 ms 7776 KB Output is correct
31 Correct 60 ms 6080 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 156 ms 4240 KB Output is correct
34 Correct 152 ms 8444 KB Output is correct
35 Correct 32 ms 1240 KB Output is correct
36 Correct 95 ms 4980 KB Output is correct
37 Correct 179 ms 7192 KB Output is correct
38 Correct 165 ms 8756 KB Output is correct
39 Correct 27 ms 3012 KB Output is correct
40 Correct 5 ms 588 KB Output is correct
41 Correct 1418 ms 11268 KB Output is correct
42 Correct 257 ms 11468 KB Output is correct
43 Correct 720 ms 11168 KB Output is correct
44 Correct 248 ms 11536 KB Output is correct
45 Correct 118 ms 10420 KB Output is correct
46 Correct 1595 ms 11796 KB Output is correct
47 Correct 104 ms 9908 KB Output is correct
48 Correct 498 ms 11060 KB Output is correct
49 Correct 222 ms 10844 KB Output is correct
50 Execution timed out 2081 ms 11612 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 76 ms 4796 KB Output is correct
10 Correct 18 ms 1608 KB Output is correct
11 Correct 55 ms 5172 KB Output is correct
12 Correct 41 ms 2780 KB Output is correct
13 Correct 63 ms 4504 KB Output is correct
14 Correct 41 ms 3512 KB Output is correct
15 Correct 10 ms 1604 KB Output is correct
16 Correct 45 ms 3556 KB Output is correct
17 Correct 93 ms 5068 KB Output is correct
18 Correct 55 ms 4408 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 3 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 420 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 46 ms 2324 KB Output is correct
35 Correct 61 ms 4972 KB Output is correct
36 Correct 171 ms 7428 KB Output is correct
37 Correct 1154 ms 7248 KB Output is correct
38 Correct 1302 ms 7776 KB Output is correct
39 Correct 60 ms 6080 KB Output is correct
40 Correct 4 ms 332 KB Output is correct
41 Correct 156 ms 4240 KB Output is correct
42 Correct 152 ms 8444 KB Output is correct
43 Correct 32 ms 1240 KB Output is correct
44 Correct 95 ms 4980 KB Output is correct
45 Correct 179 ms 7192 KB Output is correct
46 Correct 165 ms 8756 KB Output is correct
47 Correct 27 ms 3012 KB Output is correct
48 Correct 5 ms 588 KB Output is correct
49 Correct 1418 ms 11268 KB Output is correct
50 Correct 257 ms 11468 KB Output is correct
51 Correct 720 ms 11168 KB Output is correct
52 Correct 248 ms 11536 KB Output is correct
53 Correct 118 ms 10420 KB Output is correct
54 Correct 1595 ms 11796 KB Output is correct
55 Correct 104 ms 9908 KB Output is correct
56 Correct 498 ms 11060 KB Output is correct
57 Correct 222 ms 10844 KB Output is correct
58 Execution timed out 2081 ms 11612 KB Time limit exceeded
59 Halted 0 ms 0 KB -