제출 #607405

#제출 시각아이디문제언어결과실행 시간메모리
607405yuto1115Teams (IOI15_teams)C++17
컴파일 에러
0 ms0 KiB
#include "teams.h"
#include "bits/stdc++.h"
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define SZ(a) int(a.size())
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class segtree {
    struct node {
        ll lrd;
        node *cl;
        node *cr;
        
        node(int l, int r, int d) : lrd((ll(l) << 40) + (ll(r) << 20) + d), cl(nullptr), cr(nullptr) {}
    };
    
    int n;
    node *root;
    
    node *build(int l, int r, const vi::iterator &a, const vi::iterator &b) {
        if (a == b) return nullptr;
        node *res = new node(l, r, b - a);
        if (r - l > 1) {
            int m = (l + r) / 2;
            auto c = lower_bound(a, b, m);
            res->cl = build(l, m, a, c);
            res->cr = build(m, r, c, b);
        }
        return res;
    }
    
    int count(int l, int r, node *nd) {
        if (nd == nullptr) return 0;
        int nl = nd->lrd >> 40;
        int nr = (nd->lrd >> 20) - (nl << 20);
        if (r <= nl or nr <= l) return 0;
        if (l <= nl and nr <= r) return nd->lrd - (nd->lrd >> 20 << 20);
        return count(l, r, nd->cl) + count(l, r, nd->cr);
    }

public:
    segtree(int _n, const vi::iterator &a, const vi::iterator &b) : n(_n) {
        root = build(0, n, a, b);
    }
    
    int count(int l, int r) {
        assert(0 <= l and l <= r and r <= n);
        return count(l, r, root);
    }
};

vector<segtree> st;

int sz = 1;

void merge(vi &v, const vi &a, const vi &b) {
    int ai = 0, bi = 0;
    v.reserve(SZ(a) + SZ(b));
    while (ai < SZ(a) or bi < SZ(b)) {
        if (ai < SZ(a) and bi < SZ(b)) {
            if (a[ai] < b[bi]) v.pb(a[ai++]);
            else v.pb(b[bi++]);
        } else if (ai < SZ(a)) {
            v.pb(a[ai++]);
        } else {
            v.pb(b[bi++]);
        }
    }
}

void build(const vvi &v) {
    vvi ls(2 * sz);
    rep(i, sz) ls[sz + i] = v[i];
    for (int i = sz - 1; i >= 1; --i) {
        merge(ls[i], ls[2 * i], ls[2 * i + 1]);
    }
    rep(i, 2 * sz) st.eb(sz, all(ls[i]));
}

int n;
vi a, b;

int count(int xl, int xr, int yl, int yr) {
    assert(0 <= xl and xl <= xr and xr <= sz);
    assert(0 <= yl and yl <= yr and yr <= sz);
//    cerr << xl << ' ' << xr << ' ' << yl << ' ' << yr << ' ';
    yl += sz, yr += sz;
    int res = 0;
    while (yl < yr) {
        if (yl & 1) res += st[yl++].count(xl, xr);
        if (yr & 1) res += st[--yr].count(xl, xr);
        yl >>= 1, yr >>= 1;
    }
//    cerr << res << endl;
//    int res = 0;
//    rep(i, n) if (xl <= a[i] and a[i] < xr and yl <= b[i] and b[i] < yr) ++res;
    return res;
}

void init(int N, int A[], int B[]) {
    n = N;
    a = vi(A, A + N);
    b = vi(B, B + N);
    for (int &i: b) ++i;
    while (sz <= n + 1) sz *= 2;
    vvi v(sz);
    rep(i, n) v[b[i]].pb(a[i]);
    rep(i, sz) sort(all(v[i]));
    build(v);
//    cerr << "init : " << N << endl;
}

int max_yr(int xl, int xr, int yl, int ub) {
    assert(0 <= xl and xl <= xr and xr <= sz);
    assert(0 <= yl and yl <= sz);
    assert(ub > 0);
    yl += sz;
    while (true) {
        if ((yl & -yl) == yl) return sz;
        while (~yl & 1) yl >>= 1;
        int now = st[yl].count(xl, xr);
        if (now < ub) {
            ub -= now;
            ++yl;
            continue;
        }
        while (yl < sz) {
            yl *= 2;
            now = st[yl].count(xl, xr);
            if (now < ub) {
                ub -= now;
                ++yl;
            }
        }
        return yl - sz;
    }
}

int can(int m, int K[]) {
    vi k = vi(K, K + m);
    sort(all(k));
    // {x, max_y, rem in max_y}
    vvi v;
    v.pb({0, n + 1, 0});
    for (int i: k) {
//        cerr << "i : " << i << endl;
//        for (auto t: v) cerr << "v : " << t[0] << ' ' << t[1] << ' ' << t[2] << endl;
        while (v.back()[1] < i + 1) v.pop_back();
        int now = i + 1;
        int rem = i;
        while (true) {
            if (now > n + 1) return 0;
            assert(v.back()[1] >= now);
            int sum = count(v.back()[0] + 1, i + 1, now, v.back()[1] + 1) + v.back()[2];
            if (sum < rem) {
                rem -= sum;
                now = v.back()[1] + 1;
                v.pop_back();
                continue;
            }
            int psum = count(v.back()[0] + 1, i + 1, now, v.back()[1]);
            if (psum < rem) {
                v.back()[0] = i;
                v.back()[2] = sum - rem;
            } else {
                v.eb(vi{i, max_yr(v.back()[0] + 1, i + 1, now, rem), count(v.back()[0] + 1, i + 1, now, ok) - rem});
            }
            break;
        }
    }
//    cerr << "i : end" << endl;
//    for (auto t: v) cerr << "v : " << t[0] << ' ' << t[1] << ' ' << t[2] << endl;
    return 1;
}

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

teams.cpp: In member function 'segtree::node* segtree::build(int, int, const iterator&, const iterator&)':
teams.cpp:57:38: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   57 |         node *res = new node(l, r, b - a);
      |                                    ~~^~~
teams.cpp: In member function 'int segtree::count(int, int, segtree::node*)':
teams.cpp:69:26: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   69 |         int nl = nd->lrd >> 40;
      |                  ~~~~~~~~^~~~~
teams.cpp:70:34: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   70 |         int nr = (nd->lrd >> 20) - (nl << 20);
      |                  ~~~~~~~~~~~~~~~~^~~~~~~~~~~~
teams.cpp: In function 'int can(int, int*)':
teams.cpp:201:105: error: 'ok' was not declared in this scope; did you mean 'k'?
  201 |                 v.eb(vi{i, max_yr(v.back()[0] + 1, i + 1, now, rem), count(v.back()[0] + 1, i + 1, now, ok) - rem});
      |                                                                                                         ^~
      |                                                                                                         k
teams.cpp:201:114: error: no matching function for call to 'std::vector<int>::vector(<brace-enclosed initializer list>)'
  201 |                 v.eb(vi{i, max_yr(v.back()[0] + 1, i + 1, now, rem), count(v.back()[0] + 1, i + 1, now, ok) - rem});
      |                                                                                                                  ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from teams.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:653:2: note: candidate: 'template<class _InputIterator, class> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = int; _Alloc = std::allocator<int>]'
  653 |  vector(_InputIterator __first, _InputIterator __last,
      |  ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:653:2: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_vector.h:625:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::initializer_list<_Tp>, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  625 |       vector(initializer_list<value_type> __l,
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:625:7: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/10/bits/stl_vector.h:607:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  607 |       vector(vector&& __rv, const allocator_type& __m)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:607:7: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/10/bits/stl_vector.h:589:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::false_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>; std::false_type = std::integral_constant<bool, false>]'
  589 |       vector(vector&& __rv, const allocator_type& __m, false_type)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:589:23: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
  589 |       vector(vector&& __rv, const allocator_type& __m, false_type)
      |              ~~~~~~~~~^~~~
/usr/include/c++/10/bits/stl_vector.h:585:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&, const allocator_type&, std::true_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>; std::true_type = std::integral_constant<bool, true>]'
  585 |       vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:585:23: note:   no known conversion for argument 1 from 'int' to 'std::vector<int>&&'
  585 |       vector(vector&& __rv, const allocator_type& __m, true_type) noexcept
      |              ~~~~~~~~~^~~~
/usr/include/c++/10/bits/stl_vector.h:575:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  575 |       vector(const vector& __x, const allocator_type& __a)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:575:7: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/10/bits/stl_vector.h:572:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  572 |       vector(vector&&) noexcept = default;
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:572:7: note:   candidate expects 1 argument, 3 provided
/usr/include/c++/10/bits/stl_vector.h:553:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  553 |       vector(const vector& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:553:7: note:   candidate expects 1 argument, 3 provided
/usr/include/c++/10/bits/stl_vector.h:522:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const value_type&, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  522 |       vector(size_type __n, const value_type& __value,
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:522:7: note:   conversion of argument 3 would be ill-formed:
/usr/include/c++/10/bits/stl_vector.h:510:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>::size_type, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  510 |       vector(size_type __n, const allocator_type& __a = allocator_type())
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:510:7: note:   candidate expects 2 arguments, 3 provided
/usr/include/c++/10/bits/stl_vector.h:497:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::allocator_type = std::allocator<int>]'
  497 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:497:7: note:   candidate expects 1 argument, 3 provided
/usr/include/c++/10/bits/stl_vector.h:487:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = int; _Alloc = std::allocator<int>]'
  487 |       vector() = default;
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:487:7: note:   candidate expects 0 arguments, 3 provided