Submission #1112583

# Submission time Handle Problem Language Result Execution time Memory
1112583 2024-11-14T11:05:27 Z vjudge1 Chessboard (IZhO18_chessboard) C++17
16 / 100
56 ms 8016 KB
//Dost SEFEROĞLU
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " << 
#define vi vector<int>
#define all(xx) xx.begin(),xx.end()
#define ps(xxx) cout << (xxx) << endl;
const int N = 5e2+1,inf = 1e16,MOD = 1e9+7; 
 

int t[400001],lazy[400001];
struct ST {
    inline void push(const int& node,const int& l,const int& r) {
        if (!lazy[node]) return;
        t[node] = (r-l+1)-t[node];
        if (l != r) {
            lazy[2*node]^=1;
            lazy[2*node+1]^=1;
        }
        lazy[node] = 0;
    }

    void update(int node,int l,int r,int L,int R) {
        push(node,l,r);
        if (l > R || r < L) return;
        if (l >= L && r <= R) {
            lazy[node]^=1;
            push(node,l,r);
            return;
        }
        int m = (l+r) >> 1;
        update(2*node,l,m,L,R),update(2*node+1,m+1,r,L,R);
        t[node] = t[2*node]+t[2*node+1];
    }

    int query(int node,int l,int r,int L,int R) {
        push(node,l,r);
        if (l > R || r < L) return 0;
        if (l >= L && r <= R) return t[node];
        int m = (l+r) >> 1;
        return query(2*node,l,m,L,R)+query(2*node+1,m+1,r,L,R); 
    }
};

void solve() { 
    int n,k;
    cin >> n >> k;
    vector<pii> upds[n+2];
    for (int i=1;i<=k;i++) {
        int x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        upds[x1].push_back({y1,y2});
        upds[x2+1].push_back({y1,y2});
    }
    vi divs;
    for (int i=1;i<n;i++) if (n%i == 0) divs.push_back(i);
    int ans = inf;
    ST st1;
    for (int d : divs) {
        int cur = 1;
        int fl = 0;
        while (cur <= n) {
            if (!fl) st1.update(1,1,n,cur,cur+d-1);
            cur+=d;
            fl^=1;
        }
        int need = 0;
        for (int j = 1;j<=n;j++) {
            for (auto it : upds[j]) st1.update(1,1,n,it.ff,it.ss);
            if (((j-1)/d)%2 == 0) need+=st1.query(1,1,n,1,n);
            else need+=n-st1.query(1,1,n,1,n);
        }
        ans = min(ans,need);
        ans = min(ans,n*n-need);
        cur = 1;
        fl = 0;
        while (cur <= n) {
            if (!fl) st1.update(1,1,n,cur,cur+d-1);
            cur+=d;
            fl^=1;
        }
    }
    cout << ans << '\n';
}  
 
                
                            
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 6940 KB Output is correct
2 Correct 11 ms 2296 KB Output is correct
3 Correct 37 ms 8016 KB Output is correct
4 Correct 20 ms 3152 KB Output is correct
5 Correct 41 ms 6216 KB Output is correct
6 Correct 34 ms 5240 KB Output is correct
7 Correct 8 ms 2128 KB Output is correct
8 Correct 29 ms 5084 KB Output is correct
9 Correct 56 ms 6740 KB Output is correct
10 Correct 35 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 6940 KB Output is correct
2 Correct 11 ms 2296 KB Output is correct
3 Correct 37 ms 8016 KB Output is correct
4 Correct 20 ms 3152 KB Output is correct
5 Correct 41 ms 6216 KB Output is correct
6 Correct 34 ms 5240 KB Output is correct
7 Correct 8 ms 2128 KB Output is correct
8 Correct 29 ms 5084 KB Output is correct
9 Correct 56 ms 6740 KB Output is correct
10 Correct 35 ms 5712 KB Output is correct
11 Incorrect 1 ms 336 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 46 ms 6940 KB Output is correct
10 Correct 11 ms 2296 KB Output is correct
11 Correct 37 ms 8016 KB Output is correct
12 Correct 20 ms 3152 KB Output is correct
13 Correct 41 ms 6216 KB Output is correct
14 Correct 34 ms 5240 KB Output is correct
15 Correct 8 ms 2128 KB Output is correct
16 Correct 29 ms 5084 KB Output is correct
17 Correct 56 ms 6740 KB Output is correct
18 Correct 35 ms 5712 KB Output is correct
19 Incorrect 1 ms 336 KB Output isn't correct
20 Halted 0 ms 0 KB -