답안 #447818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447818 2021-07-27T15:11:52 Z blue 운세 보기 2 (JOI14_fortune_telling2) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxK = 200'000;
const int logN = 18;
const long long INF = 1'000'000'000'000'000'000LL;

int N, K;
vector<long long> T(1+maxK);

struct segtree
{
    int l;
    int r;
    vector<long long> v;

    segtree* left = NULL;
    segtree* right = NULL;

    segtree()
    {
        ;
    }

    segtree(int L, int R)
    {
        l = L;
        r = R;
        if(l == r)
        {
            v = vector<int>{T[l]};
        }
        else
        {
            int m = (l+r)/2;
            left = new segtree(l, m);
            right = new segtree(m+1, r);

            for(int x: left->v) v.push_back(x);
            for(int y: right->v) v.push_back(y);
            sort(v.begin(), v.end());
        }
    }

    int query(int L, int R, long long X, long long Y)
    {
        if(X > Y) return 0;

        if(R < l || r < L) return 0;
        else if(L <= l && r <= R)
        {
            int lo = -1;
            for(int bit = logN; bit >= 0; bit--)
            {
                if(lo + (1 << bit) >= v.size()) continue;
                if(v[lo + (1 << bit)] >= X) continue;
                lo += (1 << bit);
            }
            lo++;
            if(v[lo] < X || Y < v[lo]) return 0;

            int hi = -1;
            for(int bit = logN; bit >= 0; bit--)
            {
                if(hi + (1 << bit) >= v.size()) continue;
                if(v[hi + (1 << bit)] > Y) continue;
                hi += (1 << bit);
            }

            return hi-lo+1;
        }
        else return left->query(L, R, X, Y) + right->query(L, R, X, Y);
    }

    int get_last(long long A, long long B)
    {
        if(l == r) return l;
        else if(right->query(1, N, A, B) >= 1)
            return right->get_last(A, B);
        else
            return left->get_last(A, B);
    }
};

int main()
{
    cin >> N >> K;

    long long A[N+1], B[N+1];
    for(int i = 1; i <= N; i++) cin >> A[i] >> B[i];

    for(int j = 1; j <= K; j++) cin >> T[j];

    segtree S(0, N);

    long long res = 0;

    for(int i = 1; i <= N; i++)
    {
        if(A[i] == B[i])
        {
            res += A[i];
            continue;
        }


        int last_pos = S.get_last(min(A[i], B[i]),  max(A[i], B[i]) - 1);

        if(last_pos == 0)
        {
            int Q = S.query(1, N, max(A[i], B[i]), INF);

            if(Q % 2 == 0) res += A[i];
            else res += B[i];
        }
        else
        {
            int Q = S.query(last_pos + 1, N, max(A[i], B[i]), INF);

            if(Q % 2 == 0) res += max(A[i], B[i]);
            else res += min(A[i], B[i]);
        }
    }

    cout << res << '\n';
}

Compilation message

fortune_telling2.cpp: In constructor 'segtree::segtree(int, int)':
fortune_telling2.cpp:33:33: warning: narrowing conversion of 'T.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)((segtree*)this)->segtree::l))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   33 |             v = vector<int>{T[l]};
      |                                 ^
fortune_telling2.cpp:33:33: warning: narrowing conversion of 'T.std::vector<long long int>::operator[](((std::vector<long long int>::size_type)((segtree*)this)->segtree::l))' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
fortune_telling2.cpp:33:33: error: no match for 'operator=' (operand types are 'std::vector<long long int>' and 'std::vector<int>')
In file included from /usr/include/c++/10/vector:72,
                 from fortune_telling2.cpp:2:
/usr/include/c++/10/bits/vector.tcc:198:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  198 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/10/bits/vector.tcc:199:42: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const std::vector<long long int>&'
  199 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/10/vector:67,
                 from fortune_telling2.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:709:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:709:26: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::vector<long long int>&&'
  709 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:730:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = long long int; _Alloc = std::allocator<long long int>]'
  730 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:730:46: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::initializer_list<long long int>'
  730 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
fortune_telling2.cpp: In member function 'int segtree::query(int, int, long long int, long long int)':
fortune_telling2.cpp:57:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |                 if(lo + (1 << bit) >= v.size()) continue;
      |                    ~~~~~~~~~~~~~~~~^~~~~~~~~~~
fortune_telling2.cpp:67:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |                 if(hi + (1 << bit) >= v.size()) continue;
      |                    ~~~~~~~~~~~~~~~~^~~~~~~~~~~