比赛 contest by dark_moon 评测结果 AAAAAAAAAA
题目名称 ktt 最终得分 100
用户昵称 op_组撒头屯 运行时间 1.836 s
代码语言 C++ 内存使用 10.69 MiB
提交时间 2024-05-28 20:28:29
显示代码纯文本
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("Ofast","unroll-loops","inline")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define LL __int128
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define pb push_back
const int N=1e5+5;
int n,m;
ll a[N],b[N],tag[N];

int S,tot;
int L[N],R[N],bl[N];

int st[N],top[N];
int mxi[N],ord[N];
inline bool check(int x,int y,int z){return (LL)(b[z]-b[y])*(a[y]-a[x])>=(LL)(b[y]-b[x])*(a[z]-a[y]);}
inline ll calc(int x,ll w){return w*a[x]+b[x];}
void update(int p){
	ll w=tag[p];
	while(mxi[p]<top[p]&&calc(st[mxi[p]+1],w)>=calc(st[mxi[p]],w))mxi[p]++;
}
void rebuild(int p){
	top[p]=L[p]-1;
	for (int i=L[p];i<=R[p];i++){
		while(top[p]>L[p]&&check(st[top[p]-1],st[top[p]],ord[i]))top[p]--;
		st[++top[p]]=ord[i];
	}
	mxi[p]=L[p],update(p);
	return ;
}
void pushdown(int p){
	for (int i=L[p];i<=R[p];i++)b[i]+=a[i]*tag[p];
	tag[p]=0;
}
void init(){
	S=0.15*sqrt(n),tot=n/S;
	for (int i=1;i<=tot;i++)L[i]=R[i-1]+1,R[i]=i*S;
	if (R[tot]<n)tot++,L[tot]=R[tot-1]+1,R[tot]=n;
	for (int i=1;i<=tot;i++){
		for (int j=L[i];j<=R[i];j++)bl[j]=i,ord[j]=j;
		sort(ord+L[i],ord+R[i]+1,[&](int x,int y){return a[x]!=a[y]?a[x]<a[y]:b[x]<b[y];});
		tag[i]=0,rebuild(i);
	}
	return ;
}
void modify(int l,int r,int w){
	int pl=bl[l],pr=bl[r];
	if (pl==pr){
		pushdown(pl);
		for (int i=l;i<=r;i++)b[i]+=a[i]*w;
		return rebuild(pl);
	}
	pushdown(pl);
	for (int i=l;i<=R[pl];i++)b[i]+=a[i]*w;
	rebuild(pl);
	pushdown(pr);
	for (int i=L[pr];i<=r;i++)b[i]+=a[i]*w;
	rebuild(pr);
	for (int i=pl+1;i<=pr-1;i++){
		tag[i]+=w;
		if (mxi[i]<top[i])update(i);
	}
	return ;
}
ll query(int l,int r){
	int pl=bl[l],pr=bl[r],w;ll ans=0;
	if (pl==pr){
		w=tag[pl];
		for (int i=l;i<=r;i++)ans=max(ans,calc(i,w));
		return ans;
	}
	w=tag[pl];
	for (int i=l;i<=R[pl];i++)ans=max(ans,calc(i,w));
	w=tag[pr];
	for (int i=L[pr];i<=r;i++)ans=max(ans,calc(i,w));
	for (int i=pl+1;i<=pr-1;i++)ans=max(ans,calc(st[mxi[i]],tag[i]));
	return ans;
}

inline int read(){
	int ans=0;char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
inline void write(ll x){
	static int tmp[20],len;
	len=0;while(x)tmp[++len]=x%10,x/=10;
	while(len)putchar('0'+tmp[len--]);
	putchar('\n');
}
int main(){
	freopen ("ktt.in","r",stdin);
	freopen ("ktt.out","w",stdout);
	n=read(),m=read();
	for (int i=1;i<=n;i++)a[i]=read(),b[i]=read();
	init();
	for (int i=1;i<=m;i++){
		int opt=read(),l=read(),r=read(),w;
		if (opt==1)w=read(),modify(l,r,w);
		else write(query(l,r));
	}
	return 0;
}