답안 #39985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39985 2018-01-25T05:57:14 Z krauch OGLEDALA (COI15_ogledala) C++14
100 / 100
1149 ms 304516 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 = 1e5 + 6;

int n, m;
ll L, ans[N];
PLL a[N];
PLI b[N];
vector < PLI > vec3;
vector < pair < PLI, ll > > st;
//map < ll, ll > cnt[N];
vector < PLL > vec, vec2;

void calc(ll len1, ll len2, ll x) {
    if (!len1 && !len2) return;
    calc((len1 - 1) / 2, len2 / 2, x);
    vec.eb(0, 0);
    vec2.eb(len1, len2);

    if (len1 < x) vec.back().F = 0;
    else if (len1 == x) vec.back().F = 1;
    else if (len1 & 1) vec.back().F = vec[sz(vec) - 2].F * 2;
    else vec.back().F = vec[sz(vec) - 2].F + vec[sz(vec) - 2].S;

    if (len2 < x) vec.back().S = 0;
    else if (len2 == x) vec.back().S = 1;
    else if (len2 & 1) vec.back().S = vec[sz(vec) - 2].S * 2;
    else vec.back().S = vec[sz(vec) - 2].F + vec[sz(vec) - 2].S;
    return;
}

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

    /*calc(40, 40, 1);
    cout << vec[sz(vec) - 3].F << " " << vec[sz(vec) - 3].S << "\n";
    return 0;*/

    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) {
            vec3.eb(PLI(x - last - 1, n + 1 - i));
        }
        last = x;
    }
    a[n + 1].F = last + 1;
    a[n + 1].S = L;
    if (last < L) {
        vec3.eb(PLI(L - last, 0));
    }

    for (auto it : vec3) {
        ll len1 = it.F, len2 = it.F;
        ll val1 = 1, val2 = 1;
        bool ok = 0;
        while (len1 || len2) {
            if (len1 != len2) ok = 1;
//            cerr << len1 << " " << len2 << " " << val1 << " " << val2 << " " << ok << "\n";
            if (len2) {
                if (sz(st) && st.back().F == PLI(len2, it.S)) st.back().S += val2;
                else st.eb(mkp(PLI(len2, it.S), val2));
            }
            if (len1 && ok) st.eb(mkp(PLI(len1, it.S), val1));
            ll nval1 = 0, nval2 = 0;
            if (!ok) {
                if (len1 % 2 == 0) nval1 = nval2 = val1;
                else nval1 = nval2 = val1 * 2;
            }
            else {
                if (len1 % 2 == 0) nval1 += val1, nval2 += val1 + 2 * val2;
                else nval1 += val1 * 2 + val2, nval2 += val2;
            }
            len1 = (len1 - 1) / 2;
            len2 /= 2;
            val1 = nval1;
            val2 = nval2;
        }
    }

    sort(all(st));
    unique(all(st));
    reverse(all(st));

    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;
    for (auto it : st) {
        int i = n + 1 - it.F.S;
        ll len = it.F.F;
        if (!len) break;
        ll val = it.S;
        while (ptr <= m && sum + val >= b[ptr].F) {
            ll pos = b[ptr].F - sum;
            ll l = a[i].F, r = a[i].S, lvl = 2;
            vec.clear();
            vec2.clear();
            calc(a[i].S - a[i].F + 1, a[i].S - a[i].F + 1, len);
            while (r - l + 1 > len) {
                ll mid = (l + r) >> 1ll;
                ll res = (vec2[sz(vec) - lvl].F == mid - l ? vec[sz(vec) - lvl].F : vec[sz(vec) - lvl].S);
                if (res >= pos) {
                    r = mid - 1;
                }
                else {
                    l = mid + 1;
                    pos -= res;
                }
                ++lvl;
            }
            if (r - l + 1 != len) assert(0);
            ans[b[ptr].S] = (l + r) >> 1ll;
            ++ptr;
        }
        if (ptr > m) break;
        sum += val;
    }
    assert(ptr > m);

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

	return 0;
}

Compilation message

ogledala.cpp: In function 'int main()':
ogledala.cpp:83: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:87:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &x);
                          ^
ogledala.cpp:134:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &b[i].F);
                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5932 KB Output is correct
2 Correct 0 ms 5932 KB Output is correct
3 Correct 29 ms 8580 KB Output is correct
4 Correct 28 ms 8580 KB Output is correct
5 Correct 58 ms 18820 KB Output is correct
6 Correct 60 ms 18820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6304 KB Output is correct
2 Correct 4 ms 6304 KB Output is correct
3 Correct 985 ms 304516 KB Output is correct
4 Correct 909 ms 304516 KB Output is correct
5 Correct 986 ms 304516 KB Output is correct
6 Correct 1071 ms 304516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 623 ms 157060 KB Output is correct
2 Correct 677 ms 157060 KB Output is correct
3 Correct 907 ms 304516 KB Output is correct
4 Correct 914 ms 304516 KB Output is correct
5 Correct 1104 ms 304516 KB Output is correct
6 Correct 1149 ms 304516 KB Output is correct