제출 #1206076

#제출 시각아이디문제언어결과실행 시간메모리
1206076countlessRectangles (IOI19_rect)C++20
컴파일 에러
0 ms0 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll MOD = 998244353; const ll INF = 1e18; const ld EPS = 1e-12; #define endl "\n" #define sp <<" "<< #define REP(i, a, b) for(ll i = a; i < b; i++) #define dbg(x) cout << #x << " = " << x << endl #define mp make_pair #define pb push_back #define fi first #define se second #define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template <typename Key, typename Value> using hash_map = unordered_map<Key, Value, custom_hash>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // uniform_int_distribution<int>(a, b)(rng); // shuffle(all(a), rng); struct Sparse { vector<vector<int>> table; int size, LOGN; Sparse(vector<int> &data, int n) { size = n; LOGN = log2(size) + 1; table = vector<vector<int>>(size, vector<int>(LOGN, 0)); build(data); } // handle merge here int merge(int left, int right) { return max(left, right); } void build(vector<int> &data) { for (int i = 0; i < size; i++) { table[i][0] = data[i]; } for (int j = 1; j < LOGN; j++) { for (int i = 0; i + (1 << j) - 1 < size; i++) { table[i][j] = merge(table[i][j-1], table[i+(1 << (j-1))][j-1]); } } } int query(int l, int r) { int sz = r - l + 1; int j = log2(sz); return merge(table[l][j], table[r-(1<<(j))+1][j]); } }; // giving up and turning in a brute force ll count_rectangles(vector<vector<int>> a) { ll n = a.size(), m = a[0].size(); ll ans = 0, curr; vector<Sparse> rows, cols; REP(i, 0, n) { rows.push_back(Sparse(a[i], m)); } REP(i, 0, m) { vector<int> col(n); REP(j, 0, n) { col[j] = a[j][i]; } cols.push_back(Sparse(col, n)); } auto in = [&](int x, int y) -> bool { return (0 < x and x < n-1 and 0 < y and y < m-1); }; hash_map<pair<pair<int, int>, pair<int, int>>, bool> vis; auto checkRect = [&](int x, int y, int xx, int yy) -> int { if (!in(x,y) or !in(xx, yy)) return 0; if (x > xx) swap(x, xx); if (y > yy) swap(y, yy); if (vis[{{x, y}, {xx, yy}}]) return 0; vis[{{x, y}, {xx, yy}}] = true; int cap; REP(i, x, xx+1) { cap = min(a[i][y-1], a[i][yy+1]); if (rows[i].query(y, yy) >= cap) { return 0; } } REP(i, y, yy+1) { cap = min(a[x-1][i], a[xx+1][i]); if (cols[i].query(x, xx) >= cap) { return 0; } } return 1; }; REP(i, 0, n*m) { int x = i / m, y = i % m; REP(j, i, n*m) { int xx = j / m, yy = j % m; ans += checkRect(x, y, xx, yy); } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

In file included from /usr/include/c++/11/bits/hashtable.h:35,
                 from /usr/include/c++/11/unordered_map:46,
                 from /usr/include/c++/11/functional:61,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from rect.cpp:2:
/usr/include/c++/11/bits/hashtable_policy.h: In instantiation of 'std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::__hash_code std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::_M_hash_code(const _Key&) const [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Value = std::pair<const std::pair<std::pair<int, int>, std::pair<int, int> >, bool>; _ExtractKey = std::__detail::_Select1st; _Hash = custom_hash; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; bool __cache_hash_code = true; std::__detail::_Hash_code_base<_Key, _Value, _ExtractKey, _Hash, _RangeHash, _Unused, __cache_hash_code>::__hash_code = long unsigned int]':
/usr/include/c++/11/bits/hashtable_policy.h:729:45:   required from 'std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>::mapped_type& std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>::operator[](std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>::key_type&&) [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Pair = std::pair<const std::pair<std::pair<int, int>, std::pair<int, int> >, bool>; _Alloc = std::allocator<std::pair<const std::pair<std::pair<int, int>, std::pair<int, int> >, bool> >; _Equal = std::equal_to<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Hash = custom_hash; _RangeHash = std::__detail::_Mod_range_hashing; _Unused = std::__detail::_Default_ranged_hash; _RehashPolicy = std::__detail::_Prime_rehash_policy; _Traits = std::__detail::_Hashtable_traits<true, false, true>; std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>::mapped_type = bool; std::__detail::_Map_base<_Key, _Pair, _Alloc, std::__detail::_Select1st, _Equal, _Hash, _RangeHash, _Unused, _RehashPolicy, _Traits, true>::key_type = std::pair<std::pair<int, int>, std::pair<int, int> >]'
/usr/include/c++/11/bits/unordered_map.h:984:20:   required from 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type&&) [with _Key = std::pair<std::pair<int, int>, std::pair<int, int> >; _Tp = bool; _Hash = custom_hash; _Pred = std::equal_to<std::pair<std::pair<int, int>, std::pair<int, int> > >; _Alloc = std::allocator<std::pair<const std::pair<std::pair<int, int>, std::pair<int, int> >, bool> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type = bool; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_type = std::pair<std::pair<int, int>, std::pair<int, int> >]'
rect.cpp:118:29:   required from here
/usr/include/c++/11/bits/hashtable_policy.h:1217:23: error: static assertion failed: hash function must be invocable with an argument of key type
 1217 |         static_assert(__is_invocable<const _Hash&, const _Key&>{},
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/11/bits/hashtable_policy.h:1217:23: note: 'std::__is_invocable<const custom_hash&, const std::pair<std::pair<int, int>, std::pair<int, int> >&>{}' evaluates to false
/usr/include/c++/11/bits/hashtable_policy.h:1219:25: error: no match for call to '(const custom_hash) (const std::pair<std::pair<int, int>, std::pair<int, int> >&)'
 1219 |         return _M_hash()(__k);
      |                ~~~~~~~~~^~~~~
rect.cpp:34:16: note: candidate: 'size_t custom_hash::operator()(uint64_t) const'
   34 |         size_t operator()(uint64_t x) const {
      |                ^~~~~~~~
rect.cpp:34:36: note:   no known conversion for argument 1 from 'const std::pair<std::pair<int, int>, std::pair<int, int> >' to 'uint64_t' {aka 'long unsigned int'}
   34 |         size_t operator()(uint64_t x) const {
      |                           ~~~~~~~~~^