Submission #39935

# Submission time Handle Problem Language Result Execution time Memory
39935 2018-01-24T12:59:28 Z krauch OGLEDALA (COI15_ogledala) C++14
Compilation error
0 ms 0 KB
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair < ll, int > PLI;


#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

#define fname ""

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 4e5 + 6;

int n, m;
ll L, ans[N];
PLL a[N];
PLI b[N];
map < PLL, ll > d;
set < PLI > st;

ll get(ll len, ll x) {
    if (x == 1) return max(len, 0);
    if (d.count(PLL(len, x))) return d[PLL(len, x)];
    if (len == x) return d[PLL(len, x)] = 1;
    if (len < x) return d[PLL(len, x)] = 0;
    return d[PLL(len, x)] = get((len - 1) / 2, x) + get(len / 2, x);
}

int main() {
    #ifdef krauch
        freopen("input.txt", "r", stdin);
    #else
        //freopen(fname".in", "r", stdin);
        //freopen(fname".out", "w", stdout);
    #endif

    scanf("%lld%d%d", &L, &n, &m);
    ll last = 0;
    forn(i, 1, n) {
        ll x;
        scanf("%lld", &x);
        a[i].F = last + 1;
        a[i].S = x - 1;
        if (last < x - 1) {
            st.insert(PLI(x - last - 1, n + 1 - i));
        }
        last = x;
    }
    a[n + 1].F = last + 1;
    a[n + 1].S = L;
    if (last < L) {
        st.insert(PLI(L - last, 0));
    }

    forn(i, 1, m) {
        scanf("%lld", &b[i].F);
        b[i].F -= n;
        b[i].S = i;
    }

    int ptr = 1;
    while (ptr <= m && b[ptr].F <= 0) {
        ans[b[ptr].S] = a[b[ptr].F + n].S + 1;
        ++ptr;
    }
    ll sum = 0;
    while (sz(st)) {
        int i = n + 1 - st.rbegin() -> S;
        ll len = st.rbegin() -> F;
        if (!len) break;
        st.erase(*st.rbegin());
        ll val = get(a[i].S - a[i].F + 1, len);
        while (ptr <= m && sum + val >= b[ptr].F) {
            ll pos = b[ptr].F - sum;
            ll l = a[i].F, r = a[i].S;
            while (r - l + 1 > len) {
                ll mid = (l + r) >> 1ll;
                ll res = get(mid - l, len);
                if (res >= pos) {
                    r = mid - 1;
                }
                else {
                    l = mid + 1;
                    pos -= res;
                }
            }
            if (r - l + 1 != len) assert(0);
            ans[b[ptr].S] = (l + r) >> 1ll;
            ++ptr;
        }
        if (ptr > m) break;
        sum += val;
        if ((len - 1) / 2) {
            st.insert(PLI((len - 1) / 2, n + 1 - i));
        }
        if (len / 2) {
            st.insert(PLI(len / 2, n + 1 - i));
        }
    }

    forn(i, 1, m) {
        printf("%lld\n", ans[i]);
    }

	return 0;
}

Compilation message

ogledala.cpp: In function 'll get(ll, ll)':
ogledala.cpp:52:34: error: no matching function for call to 'max(ll&, int)'
     if (x == 1) return max(len, 0);
                                  ^
In file included from /usr/include/c++/5/bits/char_traits.h:39:0,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/istream:38,
                 from /usr/include/c++/5/sstream:38,
                 from /usr/include/c++/5/complex:45,
                 from /usr/include/c++/5/ccomplex:38,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:52,
                 from ogledala.cpp:12:
/usr/include/c++/5/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^
/usr/include/c++/5/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
ogledala.cpp:52:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
     if (x == 1) return max(len, 0);
                                  ^
In file included from /usr/include/c++/5/bits/char_traits.h:39:0,
                 from /usr/include/c++/5/ios:40,
                 from /usr/include/c++/5/istream:38,
                 from /usr/include/c++/5/sstream:38,
                 from /usr/include/c++/5/complex:45,
                 from /usr/include/c++/5/ccomplex:38,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:52,
                 from ogledala.cpp:12:
/usr/include/c++/5/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^
/usr/include/c++/5/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
ogledala.cpp:52:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
     if (x == 1) return max(len, 0);
                                  ^
In file included from /usr/include/c++/5/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:64,
                 from ogledala.cpp:12:
/usr/include/c++/5/bits/stl_algo.h:3457:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^
/usr/include/c++/5/bits/stl_algo.h:3457:5: note:   template argument deduction/substitution failed:
ogledala.cpp:52:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     if (x == 1) return max(len, 0);
                                  ^
In file included from /usr/include/c++/5/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:64,
                 from ogledala.cpp:12:
/usr/include/c++/5/bits/stl_algo.h:3463:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^
/usr/include/c++/5/bits/stl_algo.h:3463:5: note:   template argument deduction/substitution failed:
ogledala.cpp:52:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
     if (x == 1) return max(len, 0);
                                  ^
ogledala.cpp: In function 'int main()':
ogledala.cpp:67:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%d%d", &L, &n, &m);
                                  ^
ogledala.cpp:71:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &x);
                          ^
ogledala.cpp:86:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &b[i].F);
                               ^