QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#587683#5653. Library gameNananiTL 0ms0kbC++203.3kb2024-09-24 21:04:442024-09-24 21:04:44

Judging History

你现在查看的是最新测评结果

  • [2024-09-24 21:04:44]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-09-24 21:04:44]
  • 提交

answer

//by 72
#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define Fd(i, a, b) for(int i = a; i >= b; i --)
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define int long long
using namespace std;

const int mod = 998244353;
const int N = 2e5 + 10;
const int inf = 1e18;
typedef array<int, 3> a3; 
typedef long long ll;

int n, m, x[N], vst[N];

void query(int l, int r) {
    F(i, l, r) if(vst[i]) {
        cout << i << endl;
        return;
    }

}

void sol() {
    cin >> n >> m;
    F(i, 1, n) cin >> x[i];
    sort(x + 1, x + 1 + n);
    reverse(x + 1, x + 1 + n);
    int ok = 1;
    {
        set<pii> s;
        s.insert({n, 1});
        F(i, 1, n) {
            pii now = {-1, -1};
            for(auto [len, l] : s) {
                if(len >= x[i]) {
                    now = {l, l + len - 1};
                    break;
                }
            }
            if(now.fi == -1) {
                ok = 0;
                break;
            }
            auto [l, r] = now;
            int mid = l + r >> 1;
            if(mid - l + 1 > x[i]) mid = l + x[i] - 1;
            s.erase(s.find({r - l + 1, l}));
            if(l >= mid - 1) s.insert({mid - l, l});
            if(mid + 1 >= r) s.insert({r - mid, mid + 1});
        }
    }
    set<pii> s;
    s.insert({n, 1});
    if(ok) {
        cout << "Alessia" << endl;
        cout << flush;
        F(i, 1, n) {
            pii now = {-1, -1};
            bool ok = false;
            for(auto [len, l] : s) {
                if(len >= x[i]) {
                    cout << x[i] << " " << l << endl;
                    cout << flush;
                    int y; cin >> y;
                    ok = true;
                    int r = l + len - 1;
                    s.erase(s.find({len, l}));
                    if(l >= y - 1) s.insert({y - l, l});
                    if(y + 1 >= r) s.insert({r - y, y + 1});
                    break;
                }
            }
            assert(ok);
        }
    } else {
        cout << "Bernardo" << endl;
        cout << flush;
        F(i, 1, n) {
            int len, l, r; cin >> len >> l;
            r = l + len - 1;
            int res = -1;
            F(i, l, r) if(vst[i]) {
                res = i;
                break;
            }
            if(res != -1) {
                cout << res << endl;
                cout << flush;
                continue;
            }
            for(auto [w, ll] : s) {
                int rr = ll + w - 1;
                if(ll <= l && rr >= l) {
                    int mid = ll + rr >> 1;
                    if(mid >= l && mid <= r) res = mid;
                    else if(r < mid) res = r;
                    else res = l;
                    cout << res << endl;
                    cout << flush;
                    s.erase(s.find({w, ll}));
                    if(ll >= res - 1) s.insert({res - ll, ll});
                    if(res + 1 >= rr) s.insert({rr - res, res + 1});
                    vst[res] = 1;
                    break;
                }
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    F(i, 1, t) sol();
    return 0;
}
//sldl

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

5 14
3 7 2 3 10
10 1
7 4

output:

Bernardo
3

result: