Submission #492358

# Submission time Handle Problem Language Result Execution time Memory
492358 2021-12-07T02:41:38 Z Rainbowbunny Chessboard (IZhO18_chessboard) C++17
47 / 100
2000 ms 6476 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++;
        }
        ans1 += ST[1];        
        if(i % id == 0)
        {
            Update(1, 1, n, 1, n);
        }
    }
    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';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 3948 KB Output is correct
2 Correct 18 ms 1480 KB Output is correct
3 Correct 62 ms 4060 KB Output is correct
4 Correct 46 ms 2652 KB Output is correct
5 Correct 58 ms 3648 KB Output is correct
6 Correct 37 ms 2868 KB Output is correct
7 Correct 8 ms 1292 KB Output is correct
8 Correct 42 ms 2936 KB Output is correct
9 Correct 92 ms 4940 KB Output is correct
10 Correct 55 ms 3344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 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 1 ms 332 KB Output is correct
8 Correct 1 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 332 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 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 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 1 ms 332 KB Output is correct
8 Correct 1 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 332 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 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 49 ms 1608 KB Output is correct
17 Correct 64 ms 4828 KB Output is correct
18 Correct 139 ms 5044 KB Output is correct
19 Correct 733 ms 4928 KB Output is correct
20 Correct 826 ms 5056 KB Output is correct
21 Correct 61 ms 4928 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 134 ms 2732 KB Output is correct
24 Correct 123 ms 5048 KB Output is correct
25 Correct 22 ms 1036 KB Output is correct
26 Correct 75 ms 3012 KB Output is correct
27 Correct 127 ms 4700 KB Output is correct
28 Correct 127 ms 5184 KB Output is correct
29 Correct 31 ms 2628 KB Output is correct
30 Correct 5 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 3948 KB Output is correct
2 Correct 18 ms 1480 KB Output is correct
3 Correct 62 ms 4060 KB Output is correct
4 Correct 46 ms 2652 KB Output is correct
5 Correct 58 ms 3648 KB Output is correct
6 Correct 37 ms 2868 KB Output is correct
7 Correct 8 ms 1292 KB Output is correct
8 Correct 42 ms 2936 KB Output is correct
9 Correct 92 ms 4940 KB Output is correct
10 Correct 55 ms 3344 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 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 1 ms 332 KB Output is correct
18 Correct 1 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 332 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 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 49 ms 1608 KB Output is correct
27 Correct 64 ms 4828 KB Output is correct
28 Correct 139 ms 5044 KB Output is correct
29 Correct 733 ms 4928 KB Output is correct
30 Correct 826 ms 5056 KB Output is correct
31 Correct 61 ms 4928 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 134 ms 2732 KB Output is correct
34 Correct 123 ms 5048 KB Output is correct
35 Correct 22 ms 1036 KB Output is correct
36 Correct 75 ms 3012 KB Output is correct
37 Correct 127 ms 4700 KB Output is correct
38 Correct 127 ms 5184 KB Output is correct
39 Correct 31 ms 2628 KB Output is correct
40 Correct 5 ms 588 KB Output is correct
41 Correct 1305 ms 5880 KB Output is correct
42 Correct 216 ms 6236 KB Output is correct
43 Correct 625 ms 6000 KB Output is correct
44 Correct 224 ms 6212 KB Output is correct
45 Correct 109 ms 6476 KB Output is correct
46 Correct 1373 ms 6156 KB Output is correct
47 Correct 104 ms 5908 KB Output is correct
48 Correct 441 ms 5944 KB Output is correct
49 Correct 216 ms 5820 KB Output is correct
50 Execution timed out 2074 ms 6184 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 67 ms 3948 KB Output is correct
10 Correct 18 ms 1480 KB Output is correct
11 Correct 62 ms 4060 KB Output is correct
12 Correct 46 ms 2652 KB Output is correct
13 Correct 58 ms 3648 KB Output is correct
14 Correct 37 ms 2868 KB Output is correct
15 Correct 8 ms 1292 KB Output is correct
16 Correct 42 ms 2936 KB Output is correct
17 Correct 92 ms 4940 KB Output is correct
18 Correct 55 ms 3344 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 332 KB Output is correct
22 Correct 2 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 1 ms 332 KB Output is correct
26 Correct 1 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 332 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 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 49 ms 1608 KB Output is correct
35 Correct 64 ms 4828 KB Output is correct
36 Correct 139 ms 5044 KB Output is correct
37 Correct 733 ms 4928 KB Output is correct
38 Correct 826 ms 5056 KB Output is correct
39 Correct 61 ms 4928 KB Output is correct
40 Correct 4 ms 332 KB Output is correct
41 Correct 134 ms 2732 KB Output is correct
42 Correct 123 ms 5048 KB Output is correct
43 Correct 22 ms 1036 KB Output is correct
44 Correct 75 ms 3012 KB Output is correct
45 Correct 127 ms 4700 KB Output is correct
46 Correct 127 ms 5184 KB Output is correct
47 Correct 31 ms 2628 KB Output is correct
48 Correct 5 ms 588 KB Output is correct
49 Correct 1305 ms 5880 KB Output is correct
50 Correct 216 ms 6236 KB Output is correct
51 Correct 625 ms 6000 KB Output is correct
52 Correct 224 ms 6212 KB Output is correct
53 Correct 109 ms 6476 KB Output is correct
54 Correct 1373 ms 6156 KB Output is correct
55 Correct 104 ms 5908 KB Output is correct
56 Correct 441 ms 5944 KB Output is correct
57 Correct 216 ms 5820 KB Output is correct
58 Execution timed out 2074 ms 6184 KB Time limit exceeded
59 Halted 0 ms 0 KB -