# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1103096 | underwaterkillerwhale | Kangaroo (CEOI16_kangaroo) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
struct FastSet {
using uint = unsigned int ; using ull = unsigned long long ; template < class T > using V = vector <T>; template < class T > using VV = V <V<T>>;
int popcnt ( uint x ) { return __builtin_popcount(x); } int popcnt ( ull x ) { return __builtin_popcountll(x); } int bsr ( uint x ) { return 31 - __builtin_clz(x); } int bsr ( ull x ) { return 63 - __builtin_clzll(x); } int bsf ( uint x ) { return __builtin_ctz(x); } int bsf ( ull x ) { return __builtin_ctzll(x); }
static constexpr uint B = 64 ;
int n, lg;
int idx[(int)1e5 + 7]; ///size
VV<ull> seg;
FastSet( int _n) : n(_n) {
do {
seg.push_back(V<ull>((_n + B - 1 ) / B));
_n = (_n + B - 1 ) / B;
}while (_n > 1 );
lg = seg.size();
}
bool operator []( int i) const {
return (seg[ 0 ][i / B] >> (i % B) & 1 ) != 0 ;
}
void set ( int i) {
for ( int h = 0 ; h < lg; h++) {
seg[h][i / B] |= 1ULL << (i % B); i /= B;
}
}
void reset ( int i) {
for ( int h = 0 ; h < lg; h++) {
seg[h][i / B] &= ~( 1ULL << (i % B));
if (seg[h][i / B]) break ;
i /= B;
}
}
int next ( int i) {
if (i < 0) i = 0;
if (i > n) i = n;
for ( int h = 0 ; h < lg; h++) {
if (i / B == seg[h].size()) break ;
ull d = seg[h][i / B] >> (i % B);
if (!d) {
i = i / B + 1 ;
continue ;
}
i += bsf(d);
for ( int g = h - 1 ; g >= 0 ; g--) {
i *= B; i += bsf(seg[g][i / B]);
}
return i;
}
return n;
}
int prev ( int i) {
if (i < 0) i = 0;
if (i > n) i = n;
i--;
for ( int h = 0 ; h < lg; h++) {
if (i == -1 ) break ;
ull d = seg[h][i / B] << ( 63 - i % 64 );
if (!d) {
i = i / B - 1 ;
continue ;
}
i += bsr(d) - (B - 1 );
for ( int g = h - 1 ; g >= 0 ; g--) {
i *= B;
i += bsr(seg[g][i / B]);
}
return i;
}
return -1 ;
}
};