RE 0分 求调

题目链接

#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;
}
3 个赞

应该是 解析了空指针 但不知道哪里错了

3 个赞

题面发一下
@lhd

1 个赞

https://www.luogu.com.cn/problem/P1001

2 个赞

P1001 A+B Problem

1 个赞

YEs

2 个赞

你这……

1 个赞

复杂度算过了,过得去,不会TLE

2 个赞
∣a∣,∣b∣≤ 10^9
1 个赞

要开long long吗?

2 个赞

no

1 个赞

\Theta(n\sqrt{n}) 复杂度过得去 n = 2 的数据

2 个赞

我看看

1 个赞

给你个好东西

#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    cout << a+b << endl;
    return 0;
}
2 个赞

都知道
@陈亮

1 个赞

这么高深的思路我想不到

2 个赞

你去看一眼TJ(逃

2 个赞
#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;
};
inline void checks(np cur);
inline void checkm(np cur);
inline void split(np cur) {
	node _;
	np tmp = &_;
	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;
	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;
}

似乎可以删去一点不需要的函数

2 个赞

奆佬求调

2 个赞

你把这一部分删了
再把

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());	

改成

int a,b;
cin>>a>>b;
cout<<a+b<<endl;

就行了

3 个赞