萌新求调内存利用
查看原帖
萌新求调内存利用
100325
peterwuyihong楼主2021/9/28 10:24

换成暴力开点,数组开 4e64e6 就过了,但是并不知道为什么写内存利用就炸了,而且还是九个点 MLE\text{MLE}

#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<' '<<x<<endl
/* --------------- fast io --------------- */ // begin
namespace Fread {
const int SIZE = 1 << 16;
char buf[SIZE], *S, *T;
inline char getchar() {
	if (S == T) {
		T = (S = buf) + fread(buf, 1, SIZE, stdin);
		if (S == T) return '\n';
	}
	return *S++;
}
} // namespace Fread
namespace Fwrite {
const int SIZE = 1 << 16;
char buf[SIZE], *S = buf, *T = buf + SIZE;
inline void flush() {
	fwrite(buf, 1, S - buf, stdout);
	S = buf;
}
inline void putchar(char c) {
	*S++ = c;
	if (S == T) flush();
}
struct NTR {
	~ NTR() { flush(); }
} ztr;
} // namespace Fwrite
#ifdef ONLINE_JUDGE
	#define getchar Fread :: getchar
	#define putchar Fwrite :: putchar
#endif
namespace Fastio {
struct Reader {
	template<typename T>
	Reader& operator >> (T& x) {
		char c = getchar();
		T f = 1;
		while (c < '0' || c > '9') {
			if (c == '-') f = -1;
			c = getchar();
		}
		x = 0;
		while (c >= '0' && c <= '9') {
			x = (x * 10 + (c - '0'));
			c = getchar();
		}
		x *= f;
		return *this;
	}
	Reader& operator >> (char& c) {
		c = getchar();
		while (c == '\n' || c == ' ') c = getchar();
		return *this;
	}
	Reader& operator >> (char* str) {
		int len = 0;
		char c = getchar();
		while (c == '\n' || c == ' ') c = getchar();
		while (c != '\n' && c != ' ') {
			str[len++] = c;
			c = getchar();
		}
		str[len] = '\0';
		return *this;
	}
	Reader(){}
} cin;
const char endl = '\n';
struct Writer {
	template<typename T>
	Writer& operator << (T x) {
		if (x == 0) { putchar('0'); return *this; }
		if (x < 0) { putchar('-'); x = -x; }
		static int sta[45];
		int top = 0;
		while (x) { sta[++top] = x % 10; x /= 10; }
		while (top) { putchar(sta[top] + '0'); --top; }
		return *this;
	}
	Writer& operator << (char c) {
		putchar(c);
		return *this;
	}
	Writer& operator << (char* str) {
		int cur = 0;
		while (str[cur]) putchar(str[cur++]);
		return *this;
	}
	Writer& operator << (const char* str) {
		int cur = 0;
		while (str[cur]) putchar(str[cur++]);
		return *this;
	}
	Writer(){}
} cout;
} // namespace Fastio
#define cin Fastio :: cin
#define cout Fastio :: cout
#define endl Fastio :: endl
/* --------------- fast io --------------- */ // end

#define maxn 500010
int n,m;
struct prpr{
	int l,r;
	int sm,dat,val;
	bool tag,col;
	int siz,lmx,rmx,ans;
}a[maxn];
int rt;
int sta[maxn],top;
mt19937 rnd(time(NULL));
inline int Build(int x){
	int g=sta[top--];
	a[g].dat=rnd();
	a[g].siz=1;
	a[g].ans=a[g].val=a[g].sm=x;
	a[g].lmx=a[g].rmx=max(x,0);
	return g;
}
inline void Pushup(int x){
	if(!x)return;
	a[x].sm=a[a[x].l].sm+a[x].val+a[a[x].r].sm;
	a[x].siz=a[a[x].l].siz+1+a[a[x].r].siz;
	a[x].lmx=max(a[a[x].r].lmx+a[a[x].l].sm+a[x].val,a[a[x].l].lmx);
	a[x].lmx=max(a[x].lmx,0);
	a[x].rmx=max(a[a[x].l].rmx+a[a[x].r].sm+a[x].val,a[a[x].r].rmx);
	a[x].rmx=max(a[x].rmx,0);
	a[x].ans=a[a[x].l].rmx+a[a[x].r].lmx+a[x].val;
	if(a[x].l)a[x].ans=max(a[x].ans,a[a[x].l].ans);
	if(a[x].r)a[x].ans=max(a[x].ans,a[a[x].r].ans);
}
inline void pr(int x){
	if(!x)return;
	a[x].tag^=1;
	swap(a[x].lmx,a[x].rmx);
	swap(a[x].l,a[x].r);
}
inline void pt(int x,int y){
	if(!x)return;
	a[x].val=y;
	a[x].sm=a[x].siz*y;
	a[x].lmx=a[x].rmx=max(0,a[x].sm);
	a[x].ans=max(y,a[x].sm);
	a[x].col=1;
}
inline void Pushdown(int x){
	if(a[x].tag){
		if(a[x].l)pr(a[x].l);
		if(a[x].r)pr(a[x].r);
		a[x].tag=0;
	}
	if(a[x].col){
		if(a[x].l)pt(a[x].l,a[x].val);
		if(a[x].r)pt(a[x].r,a[x].val);
		a[x].col=0;
	}
}
inline void Split(int rt,int k,int &x,int &y){
	if(!rt)x=y=0;
	else{
		Pushdown(rt);
		if(a[a[rt].l].siz+1<=k)x=rt,Split(a[x].r,k-a[a[rt].l].siz-1,a[x].r,y);
		else y=rt,Split(a[y].l,k,x,a[y].l);
		Pushup(rt);
	}
}
inline int Merge(int x,int y){
	if(!x||!y)return x^y;
	if(a[x].dat<a[y].dat){
		Pushdown(x);
		a[x].r=Merge(a[x].r,y);
		Pushup(x);return x;
	}else{
		Pushdown(y);
		a[y].l=Merge(x,a[y].l);
		Pushup(y);return y;
	}
}
char op[15];
int R,x,y,z,c,k,d;
void dfs(int x,int u=0){
	if(!x)return;
	Pushdown(x);
	dfs(a[x].l,u+1);
	for(int i=1;i<=u;i++)cout<<"  ";
	cout<<a[x].val<<' '<<a[x].lmx<<' '<<a[x].rmx<<' '<<a[x].sm<<' '<<a[x].ans<<endl;
	dfs(a[x].r,u+1);
}
void del(int x){
	if(!x)return;
	sta[++top]=x;
	assert(x<=500000);
	del(a[x].l);
	del(a[x].r);
}
int G(int l,int r){
	if(l==r)return cin>>d,Build(d);
	int mid=(l+r)>>1;
	return Merge(G(l,mid),G(mid+1,r));
}
signed main(){
#ifndef ONLINE_JUDGE
	freopen("testdata.in","r",stdin);
#endif
	cin>>n>>m;
	for(int i=1;i<=500000;i++)sta[++top]=i;
	while(n--){
		cin>>x;
		rt=Merge(rt,Build(x));
	}
	while(m--){
		cin>>op;
		if(op[2]=='S'){//insert
			cin>>k>>c;
			Split(rt,k,x,y);
			R=0;
			while(c--)cin>>z,R=Merge(R,Build(z));
			rt=Merge(Merge(x,R),y);
		}
		if(op[2]=='L'){//delete
			cin>>k>>c;
			Split(rt,k-1,x,y);
			Split(y,c,y,z);
			del(y);
			rt=Merge(x,z);
		}
		if(op[2]=='K'){//make-same
			cin>>k>>c>>d;
			Split(rt,k-1,x,y);
			Split(y,c,y,z);
			pt(y,d);
			rt=Merge(x,Merge(y,z));
		}
		if(op[2]=='V'){//reverse
			cin>>k>>c;
			Split(rt,k-1,x,y);
			Split(y,c,y,z);
			pr(y);
			rt=Merge(x,Merge(y,z));
		}
		if(op[2]=='T'){//get-sum
			cin>>k>>c;
			Split(rt,k-1,x,y);
			Split(y,c,y,z);
			cout<<a[y].sm<<endl;
			rt=Merge(x,Merge(y,z));
		}
		if(op[2]=='X'){//max-sum
			cout<<a[rt].ans<<endl;
		}
	}
#ifndef ONLINE_JUDGE
	cerr<<endl<<(double)clock()/CLOCKS_PER_SEC;
#endif
}
2021/9/28 10:24
加载中...