Submission #39921

# Submission time Handle Problem Language Result Execution time Memory
39921 2018-01-24T11:46:52 Z krauch OGLEDALA (COI15_ogledala) C++14
0 / 100
4000 ms 53404 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;


#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 = 2e5 + 6;

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

ll get(ll len, ll x) {
    ++kek;
    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);
  	cin >> L >> n >> m;  
  ll last = 0;
    forn(i, 1, n) {
        ll x;
        cin >> x;//scanf("%lld", &x);
        a[i].F = last + 1;
        a[i].S = x - 1;
        if (last < x - 1) {
            cnt[i][x - last - 1]++;
            st.insert(mkp(x - last - 1, n + 1 - i));
        }
        last = x;
    }
    a[n + 1].F = last + 1;
    a[n + 1].S = L;
    if (last != L) {
        cnt[n + 1][L - last]++;
        st.insert(mkp(L - last, 0));
    }

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

    sort(b + 1, b + m + 1);

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

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

	return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4000 ms 19216 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4000 ms 19216 KB Execution timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4000 ms 53404 KB Execution timed out
2 Halted 0 ms 0 KB -