数据过水
查看原帖
数据过水
361965
K2Cr2O7楼主2023/10/17 20:47

为了检查我维护的信息有没有问题,我交了一发暴力,结果直接过了,还跑到了最优解前几。

code

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int n,m,k,a,v,x,cur,cnt,tag; 
multiset< pair<int,int> > s;

signed main(){
	scanf("%lld %lld %lld",&n,&m,&k);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a);
		cur+=a;
		s.insert(make_pair(a,1));
		++cnt;
	}
	while(m--){
		scanf("%lld %lld",&x,&v);
		tag+=x;
		if(x<0&&s.size()){
			int tot=0;
			while((*s.begin()).first+tag<=0){
				auto it=*s.begin();
				tot=(tot+((it.first+tag-x+mod*2)%mod)*it.second%mod)%mod;
				cnt=(cnt-it.second+mod*2)%mod;
				s.erase(s.begin());
				if(!s.size())
					break;
			}
			cur=(cur+cnt*x%mod+v-tot+mod*2)%mod;
		}
		if(x>0&&s.size()){
			cur=(cur+cnt*x+v)%mod;
			int cntdel=0,tot1=0,tot2=0;
			auto it=s.end();--it;
			while((*it).first+tag>k){
				tot1=(tot1+(*it).second)%mod;
				tot2=(tot2+(*it).second*((*it).first+tag-k+mod*2)%mod)%mod;
				s.erase(it);
				++cntdel;
				if(!s.size())
					break;
				it=s.end();
				it--;
			}
			if(cntdel){
				s.insert(make_pair(1-tag,tot2));
				s.insert(make_pair(k-tag,tot1));
			}
			cnt=(cnt+tot2)%mod;
		}	
		if(v){
			s.insert(make_pair(v-tag,1));
			++cnt;
		}
		cnt=0;
		cur=0;
		for(auto i:s){
//			printf("|%d %d|",i.first,i.second);
			cnt=(cnt+i.second)%mod;
			cur=(cur+(i.first+tag)*i.second%mod)%mod;
		}
		puts("");
		printf("%d ",cnt);
		printf("%lld\n",cur);
	}
	return 0;
}

link

https://www.luogu.com.cn/record/130002342

2023/10/17 20:47
加载中...