块链 WA 求助
查看原帖
块链 WA 求助
826774
Little_Fox_Fairy楼主2024/9/28 10:20
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
#define int long long
#define max(a,b) (a>b?a:b)
using namespace std;
namespace fast_IO {
#define IOSIZE 100000
	char ibuf[IOSIZE], obuf[IOSIZE], *p1 = ibuf, *p2 = ibuf, *p3 = obuf;
#define getchar() ((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin),p1==p2)?(EOF):(*p1++))
#define putchar(x) ((p3==obuf+IOSIZE)&&(fwrite(obuf,p3-obuf,1,stdout),p3=obuf),*p3++=x)
#define isdigit(ch) (ch>47&&ch<58)
#define isspace(ch) (ch<33)
	template<typename T> inline T read() { T s = 0; int w = 1; char ch; while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar(); return s * w; }
	template<typename T> inline bool read(T &s) { s = 0; int w = 1; char ch; while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1; if (ch == EOF) return false; while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar(); return s *= w, true; }
	template<typename T> inline void print(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) print(x / 10); putchar(x % 10 + 48); }
	inline bool read(char &s) { while (s = getchar(), isspace(s)); return true; }
	inline bool read(char *s) { char ch; while (ch = getchar(), isspace(ch)); if (ch == EOF) return false; while (!isspace(ch)) *s++ = ch, ch = getchar(); *s = '\000'; return true; }
	inline void print(char x) { putchar(x); }
	inline void print(char *x) { while (*x) putchar(*x++); }
	inline void print(const char *x) { for (int i = 0; x[i]; i++) putchar(x[i]); }
	inline bool read(std::string& s) { s = ""; char ch; while (ch = getchar(), isspace(ch)); if (ch == EOF) return false; while (!isspace(ch)) s += ch, ch = getchar(); return true; }
	inline void print(std::string x) { for (int i = 0, n = x.size(); i < n; i++) putchar(x[i]); }
	inline bool read(bool &b) { char ch; while(ch=getchar(), isspace(ch)); b=ch^48; return true; }
	inline void print(bool b) { putchar(b+48); }
	template<typename T, typename... T1> inline int read(T& a, T1&... other) { return read(a) + read(other...); }
	template<typename T, typename... T1> inline void print(T a, T1... other) { print(a), print(other...); }
	struct Fast_IO { ~Fast_IO() { fwrite(obuf, p3 - obuf, 1, stdout); } } io;
	template<typename T> Fast_IO& operator >> (Fast_IO &io, T &b) { return read(b), io; }
	template<typename T> Fast_IO& operator << (Fast_IO &io, T b) { return print(b), io; }
#define cout io
#define cin io
#define endl '\n'
} using namespace fast_IO;
const int N=5e5+10;
const int S=500;
const int INF=0x7fffffff;
struct Block 
{
	vector<int> a;
	int lmax,rmax,maxx,sum;
	int nex=-1,pre=-1;
	Block() {lmax=-INF,rmax=-INF,maxx=-INF,sum=0,nex=-1,pre=-1;};
};
int n,m,blo,sizz;
int f[N];
vector<Block> e;
inline void rebuild(int u)
{
	e[u].sum=e[u].lmax=e[u].rmax=e[u].maxx=0;
	int res=-INF,sum1=0,sum2=0,lmaxx=-INF,rmaxx=-INF,siz=e[u].a.size();
	for (int i=0;i<siz;i++)
	{
		e[u].sum+=e[u].a[i];
		if (!i) f[i]=e[u].a[i];
		else f[i]=max(f[i-1]+e[u].a[i],e[u].a[i]);
		res=max(res,f[i]);
		sum1+=e[u].a[i];lmaxx=max(lmaxx,sum1);
	}
	for (int i=siz-1;i>=0;i--) sum2+=e[u].a[i],rmaxx=max(rmaxx,sum2);
	e[u].maxx=res,e[u].lmax=lmaxx,e[u].rmax=rmaxx;
	fill(f,f+siz+1,0);
	return ;
}
inline void split(int loc)
{
	Block tmp=e[loc];
	e.emplace_back(tmp);blo++;
	if (e[loc].nex!=-1) e[e[loc].nex].pre=blo;
	e[blo].pre=loc,e[blo].nex=e[loc].nex,e[loc].nex=blo;
	e[loc].a.erase(e[loc].a.begin()+S+1,e[loc].a.end());
	e[blo].a.erase(e[blo].a.begin(),e[blo].a.begin()+S+1);
	rebuild(loc),rebuild(blo);
	return ;
}
inline int find(int &pos)
{
	int loc=0;
	while (e[loc].a.size()<pos)
	{
		pos-=e[loc].a.size();
		loc=e[loc].nex;
	}
	pos--;
	return loc;
}
inline void insert(int pos,int x)
{
	int loc=0,tag=0;
	while (e[loc].a.size()<pos)
	{
		pos-=e[loc].a.size();
		if (e[loc].nex==-1 and pos)
		{
			e[loc].a.emplace_back(x);
			tag=1;
			break;
		}
		loc=e[loc].nex;
	}
	if (!tag)
	{
		pos--;
		e[loc].a.emplace(e[loc].a.begin()+pos,x);
	}
	if (e[loc].a.size()>(S*1.5)) split(loc);
	else rebuild(loc);
	return ;
}
inline void Delete(int pos)
{
	int loc=find(pos);
	e[loc].a.erase(e[loc].a.begin()+pos);
	if (!e[loc].a.size())
	{
		if (e[loc].pre!=-1) e[e[loc].pre].nex=e[loc].nex;
		if (e[loc].nex!=-1) e[e[loc].nex].pre=e[loc].pre;
	}
	else rebuild(loc);
	return ;
}
inline void update(int pos,int x)
{
	int loc=find(pos);e[loc].a[pos]=x;
	rebuild(loc);
	return ;
}
inline int query(int l,int r)
{
	int bll=find(l),blr=find(r);
	if (bll==blr)
	{
		int res=-INF;
		for (int i=l;i<=r;i++) f[i]=max(f[i-1]+e[bll].a[i],e[bll].a[i]),res=max(res,f[i]);
		fill(f,f+r+1,0);
		return res;
	}
	Block tmp;int res=-INF,sum1=0,rmaxx=-INF;
	for (int i=l;i<e[bll].a.size();i++) tmp.sum+=e[bll].a[i],f[i]=max(f[i-1]+e[bll].a[i],e[bll].a[i]),res=max(res,f[i]);
	fill(f,f+e[bll].a.size()+1,0);
	for (int i=e[bll].a.size()-1;i>=l;i--) sum1+=e[bll].a[i],rmaxx=max(rmaxx,sum1);
	tmp.maxx=res,tmp.rmax=rmaxx;
	for (int i=bll+1;i<=blr-1;i++)
	{
		tmp.maxx=max(tmp.rmax+e[i].lmax,max(tmp.maxx,e[i].maxx));
		tmp.rmax=max(tmp.rmax+e[i].sum,e[i].rmax);
	}
	res=-INF,sum1=0,rmaxx=-INF;
	for (int i=0;i<=r;i++)
	{
		if (!i) f[i]=e[blr].a[i];
		else f[i]=max(f[i-1]+e[blr].a[i],e[blr].a[i]);
		res=max(f[i],res);
		sum1+=e[blr].a[i];
		rmaxx=max(rmaxx,sum1);
	}
	fill(f,f+r+1,0);
	tmp.maxx=max(tmp.maxx,max(res,rmaxx+tmp.rmax));
	return tmp.maxx;
}
signed main()
{
	cin>>n;e.emplace_back();
	int x;cin>>x;e.back().a.emplace_back(x);
	for (int i=2;i<=n;i++)
	{
		int x;cin>>x;
		insert(i,x);
	}
	cin>>m;
	while (m--)
	{
		char op;int l,r;
		cin>>op;
		if (op=='I')
		{
			cin>>l>>r;
			insert(l,r);
		}
		if (op=='D')
		{
			cin>>l;
			Delete(l);
		}
		if (op=='R')
		{
			cin>>l>>r;
			update(l,r);
		}
		if (op=='Q')
		{
			cin>>l>>r;
			cout<<query(l,r)<<endl;
		}
	}
	return (0-0);
}

vjudge 上显示过到了第 7 个点。

2024/9/28 10:20
加载中...