Submission #726772

#TimeUsernameProblemLanguageResultExecution timeMemory
726772NeltRarest Insects (IOI22_insects)C++17
Compilation error
0 ms0 KiB
#include "insects.h" #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> /* DEFINES */ #define S second #define F first #define ll long long #define ull unsigned long long #define ld long double #define npos ULLONG_MAX #define INF LLONG_MAX #define vv(a) vector<a> #define pp(a, b) pair<a, b> #define pq(a) priority_queue<a> #define qq(a) queue<a> #define ss(a) set<a> #define mm(a, b) map<a, b> #define ump(a, b) unordered_map<a, b> #define sync \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define elif else if #define endl "\n" #define allc(a) begin(a), end(a) #define all(a) a, a + sizeof(a) / sizeof(a[0]) #define pb push_back #define logi(a) __lg(a) #define sqrt(a) sqrtl(a) #define mpr make_pair #define ins insert using namespace std; using namespace __gnu_pbds; using namespace __cxx11; typedef char chr; typedef basic_string<chr> str; template <typename T, typename key = less<T>> using ordered_set = tree<T, null_type, key, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int min_cardinality(int n) { if (n == 1) return 1; vv(ll) eq, uni; for (ll i = 0; i < n; i++) { move_inside(i); if (press_button() == 2) eq.pb(i), move_outside(i); else uni.pb(i); } ll l = 2, cntdiff = n - eq.size(), r = n / cntdiff, cur = cntdiff, ans = 1; if (cntdiff == 1) return n; if (cntdiff > (n >> 1)) return 1; bool us[n]; memset(us, 0, sizeof(us)); ll deactive[n]; memset(deactive, 0, sizeof(deactive)); vv(ll) erase, tmp; for (ll i = 0; i < min((ll)eq.size(), ((l + r) >> 1) - cntdiff); i++) move_inside(eq[i]), cur++, us[eq[i]] = 1, erase.pb(eq[i]); if (eq.size() < ((l + r) >> 1) - cntdiff) erase.clear(); random_shuffle(allc(eq), rng); while (l <= r) { ll mid = (l + r) >> 1; for (ll i : eq) { if (cur >= mid * cntdiff) { l = mid + 1; break; } if (us[i]) continue; us[i] = 1; if (deactive[i] > mid) { tmp.pb(i), deactive[i] = max(deactive[i], mid + 1); continue; } move_inside(i); if (press_button() > mid) move_outside(i), tmp.pb(i), deactive[i] = max(deactive[i], mid + 1); else cur++, erase.pb(i); if (cur >= mid * cntdiff) { l = mid + 1; break; } } if (cur >= mid * cntdiff) { l = mid + 1, ans = mid; if (l > r) break; for (ll j : tmp) us[j] = 0; erase.clear(); for (ll j = 0; j < min((ll)tmp.size(), ((l + r) >> 1) - mid); j++) move_inside(tmp[j]), cur++, us[tmp[j]] = 1, erase.pb(tmp[j]); if (tmp.size() <= ((l + r) >> 1) - mid) erase.clear(); tmp.clear(); } else { r = mid - 1; if (l > r) break; if (erase.size() < mid - ((l + r) >> 1)) erase.clear(); while (erase.size() >= mid - ((l + r) >> 1)) move_outside(erase.back()), us[erase.back()] = 0, cur--, erase.pop_back(); tmp.clear(); } } return ans; }

Compilation message (stderr)

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:72:19: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   72 |     if (eq.size() < ((l + r) >> 1) - cntdiff)
      |         ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
insects.cpp:114:28: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  114 |             if (tmp.size() <= ((l + r) >> 1) - mid)
      |                 ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
insects.cpp:123:30: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  123 |             if (erase.size() < mid - ((l + r) >> 1))
      |                 ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
insects.cpp:125:33: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  125 |             while (erase.size() >= mid - ((l + r) >> 1))
      |                    ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from insects.cpp:6:
/usr/include/c++/10/bits/stl_algo.h: In instantiation of 'void std::random_shuffle(_RAIter, _RAIter, _Generator&&) [with _RAIter = __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >; _Generator = std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>&]':
insects.cpp:74:33:   required from here
/usr/include/c++/10/bits/stl_algo.h:4636:48: error: no match for call to '(std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>) (__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
 4636 |    _RandomAccessIterator __j = __first + __rand((__i - __first) + 1);
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/random:49,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:108,
                 from insects.cpp:6:
/usr/include/c++/10/bits/random.h:563:7: note: candidate: 'std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::operator()() [with _UIntType = long unsigned int; long unsigned int __w = 32; long unsigned int __n = 624; long unsigned int __m = 397; long unsigned int __r = 31; _UIntType __a = 2567483615; long unsigned int __u = 11; _UIntType __d = 4294967295; long unsigned int __s = 7; _UIntType __b = 2636928640; long unsigned int __t = 15; _UIntType __c = 4022730752; long unsigned int __l = 18; _UIntType __f = 1812433253; std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type = long unsigned int]'
  563 |       operator()();
      |       ^~~~~~~~
/usr/include/c++/10/bits/random.h:563:7: note:   candidate expects 0 arguments, 1 provided