被自己算法弄晕了……(玄关)

P1001 A+B Problem

zzy10124 @ 2024-07-21 11:05:27

#include<bits/stdc++.h>
using namespace std;
const int k = 700;
const int _nk = 1000;
const int _2k = 1400;
struct node;
using np = node*;
struct node {
    vector<int>*a;
    np pre, nxt;
};
np _Pl;
np _Pr;
queue<np>bin;
int _Cnt = 32;
inline void CreateNewPlace() {
    _Pr = (_Pl = (np)(malloc(sizeof(node) * _Cnt))) + _Cnt;
    _Cnt <<= 1;
}
inline np newnp() {
    if (bin.size()) {
        np tmp = bin.front();
        bin.pop();
        return tmp;
    }
    if (_Pl == _Pr)CreateNewPlace();
    return (_Pl++);
}
inline void delnp(np x) {
    bin.push(x);
    x->a->clear();
    x->a = nullptr;
    x->pre = x->nxt = nullptr;
}
inline void checks(np cur);
inline void checkm(np cur);
inline void split(np cur) {
    np tmp = newnp();
    int ts = cur->a->size() >> 1;
    vector<int> tv(cur->a->begin() + ts, cur->a->end());
    tmp->a = &tv;
    cur->a->erase(cur->a->begin() + ts, cur->a->end());
    tmp->nxt = cur->nxt;
    tmp->pre = cur;
    tmp->nxt->pre = tmp;
    tmp->pre->nxt = cur;
    checks(tmp);
    checks(cur);
    return;
}
inline void merge(np cur, np tmp) {
    cur->a->insert(cur->a->end(), tmp->a->begin(), tmp->a->end());
    cur->nxt = tmp->nxt;
    cur->nxt->pre = cur;
    delnp(tmp);
    checkm(cur);
    return;
}
inline void checks(np cur) {
    if (cur->a->size() >= _2k)split(cur);
    return;
}
inline void checkm(np cur) {
    if ((cur->a->size() + cur->nxt->a->size()) < _nk)merge(cur, cur->nxt);
    if ((cur->pre->a->size() + cur->a->size()) < _nk)merge(cur->pre, cur);
}
node head, tail;
inline void init() {
    head.pre = &head;
    head.nxt = &tail;
    tail.pre = &head;
    tail.nxt = &tail;
}
int main() {
    init();
    int a, b;
    cin >> a >> b;
    vector<int>veca(1, a);
    vector<int>vecb(1, b);
    node t1, t2;
    t1.a = &veca;
    t2.a = &vecb;
    merge(&t1,&t2);
    split(&t1);
    cout << *(head.nxt->a->begin()) + *(tail.pre->a->begin());
    return 0;
}

RE0 大佬求调


by yiyuhang123 @ 2024-07-21 21:45:37

666


by ruo_aqueous @ 2024-07-22 13:59:20

@Maisie586_ 当然是啦


by fzy2 @ 2024-07-26 14:31:14

需要要这么多代码吗?


上一页 |