답안 #378826

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
378826 2021-03-17T05:30:13 Z abc864197532 Chessboard (IZhO18_chessboard) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int, int>
#define pll pair<lli, lli>
#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define test(x) cout << #x << ' ' << x << endl
#define printv(x) {\
    for (auto a : x) cout << a << ' ';\
    cout << endl;\
}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int N = 2000000;

struct range {
    int l, r;
};

vector <int> p;
int sz;

struct Seg {
    int l, r, m;
    bool lz;
    int tag[128]{}, sum[128]{};
    Seg* ch[2];
    Seg (int _l, int _r) : l(_l), r(_r), m(l + r >> 1), lz(false) {
        if (r - l > 1) {
            ch[0] = new Seg(l, m);
            ch[1] = new Seg(m, r);
            for (int i = 0; i < sz; ++i) tag[i] = ch[0]->tag[i] + ch[1]->tag[i];
        } else {
            for (int i = 0; i < sz; ++i) tag[i] = (l / p[i]) & 1 ? -1 : 1;
        }
    }
    void pull() {
        for (int i = 0; i < sz; ++i) {
            if (lz) sum[i] = tag[i];
            else if (r - l == 1) sum[i] = 0;
            else sum[i] = ch[0]->sum[i] + ch[1]->sum[i];
        }
    }
    void modify(int a, int b, bool v) {
        if (a <= l && r <= b) lz = v;
        else {
            if (a < m) ch[0]->modify(a, b, v);
            if (m < b) ch[1]->modify(a, b, v);
        }
        pull();
    }
};

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i < n; ++i) if (n % i == 0) p.pb(i), sz++;
    vector <range> block[n + 1][2];
    for (int i = 0, x1, y1, x2, y2; i < m; ++i) {
        cin >> x1 >> y1 >> x2 >> y2, --x1, --y1;
        block[x1][1].pb({y1, y2});
        block[x2][0].pb({y1, y2});
    }
    lli ans = 1ll * n * n;
    vector <lli> cur(sz);
    for (int i = 0; i < sz; ++i) cur[i] = 1ll * p[i] * p[i] * (1ll * (n / p[i]) * (n / p[i]) / 2);
    Seg root(0, n);
    for (int i = 0; i <= n; ++i) {
        for (range &j : block[i][0]) root.modify(j.l, j.r, false);
        for (range &j : block[i][1]) root.modify(j.l, j.r, true);
        for (int j = 0; j < sz; ++j) {
            if ((i / p[j]) & 1) cur[j] -= root.sum[j];
            else cur[j] += root.sum[j];
        }
        ans = min({ans, cur[j], 1ll * n * n - cur[j]});
    }
    cout << ans << '\n';
}

/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
 */

Compilation message

chessboard.cpp: In constructor 'Seg::Seg(int, int)':
chessboard.cpp:32:46: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     Seg (int _l, int _r) : l(_l), r(_r), m(l + r >> 1), lz(false) {
      |                                            ~~^~~
chessboard.cpp: In function 'int main()':
chessboard.cpp:81:29: error: 'j' was not declared in this scope
   81 |         ans = min({ans, cur[j], 1ll * n * n - cur[j]});
      |                             ^
chessboard.cpp:81:54: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   81 |         ans = min({ans, cur[j], 1ll * n * n - cur[j]});
      |                                                      ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from chessboard.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
chessboard.cpp:81:54: note:   candidate expects 2 arguments, 1 provided
   81 |         ans = min({ans, cur[j], 1ll * n * n - cur[j]});
      |                                                      ^
In file included from /usr/include/c++/9/bits/specfun.h:45,
                 from /usr/include/c++/9/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:41,
                 from chessboard.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
chessboard.cpp:81:54: note:   candidate expects 3 arguments, 1 provided
   81 |         ans = min({ans, cur[j], 1ll * n * n - cur[j]});
      |                                                      ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from chessboard.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3444 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed: