제출 #1103096

#제출 시각아이디문제언어결과실행 시간메모리
1103096underwaterkillerwhale캥거루 (CEOI16_kangaroo)C++17
컴파일 에러
0 ms0 KiB
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 ;
    }
};

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

kangaroo.cpp:2:97: error: 'vector' does not name a type
    2 |     using uint = unsigned int ; using ull = unsigned long long ; template < class T > using V = vector <T>; template < class T > using VV = V <V<T>>;
      |                                                                                                 ^~~~~~
kangaroo.cpp:2:141: error: 'V' does not name a type
    2 |     using uint = unsigned int ; using ull = unsigned long long ; template < class T > using V = vector <T>; template < class T > using VV = V <V<T>>;
      |                                                                                                                                             ^
kangaroo.cpp:9:5: error: 'VV' does not name a type
    9 |     VV<ull> seg;
      |     ^~
kangaroo.cpp: In constructor 'FastSet::FastSet(int)':
kangaroo.cpp:12:13: error: 'seg' was not declared in this scope; did you mean 'set'?
   12 |             seg.push_back(V<ull>((_n + B - 1 ) / B));
      |             ^~~
      |             set
kangaroo.cpp:12:27: error: 'V' was not declared in this scope
   12 |             seg.push_back(V<ull>((_n + B - 1 ) / B));
      |                           ^
kangaroo.cpp:12:32: error: expected primary-expression before '>' token
   12 |             seg.push_back(V<ull>((_n + B - 1 ) / B));
      |                                ^
kangaroo.cpp:15:14: error: 'seg' was not declared in this scope; did you mean 'set'?
   15 |         lg = seg.size();
      |              ^~~
      |              set
kangaroo.cpp: In member function 'bool FastSet::operator[](int) const':
kangaroo.cpp:19:17: error: 'seg' was not declared in this scope; did you mean 'set'?
   19 |         return (seg[ 0 ][i / B] >> (i % B) & 1 ) != 0 ;
      |                 ^~~
      |                 set
kangaroo.cpp: In member function 'void FastSet::set(int)':
kangaroo.cpp:23:13: error: 'seg' was not declared in this scope; did you mean 'set'?
   23 |             seg[h][i / B] |= 1ULL << (i % B); i /= B;
      |             ^~~
      |             set
kangaroo.cpp: In member function 'void FastSet::reset(int)':
kangaroo.cpp:28:13: error: 'seg' was not declared in this scope; did you mean 'set'?
   28 |             seg[h][i / B] &= ~( 1ULL << (i % B));
      |             ^~~
      |             set
kangaroo.cpp: In member function 'int FastSet::next(int)':
kangaroo.cpp:37:26: error: 'seg' was not declared in this scope; did you mean 'set'?
   37 |             if (i / B == seg[h].size()) break ;
      |                          ^~~
      |                          set
kangaroo.cpp:38:21: error: 'seg' was not declared in this scope; did you mean 'set'?
   38 |             ull d = seg[h][i / B] >> (i % B);
      |                     ^~~
      |                     set
kangaroo.cpp: In member function 'int FastSet::prev(int)':
kangaroo.cpp:57:21: error: 'seg' was not declared in this scope; did you mean 'set'?
   57 |             ull d = seg[h][i / B] << ( 63 - i % 64 );
      |                     ^~~
      |                     set