性感代码,在线求调
查看原帖
性感代码,在线求调
502983
jhhh楼主2024/10/22 20:05
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,q,W;
template <typename T>
class seg {
		vector<T>tree;//树
		vector<T>busy;//懒标记
		vector<T> *arr;
		T n,n4,root,endd;
		void mantain(int cl,int cr,int p) {
//		if(busy[p*2])mantain(l,r,2*p,busy[p*2]);
//		if(busy[p*2+1])mantain(l,r,2*p+1,busy[p*2+1]);
//		busy[p]+=v;
//		tree[p]+=(r-l+1)*v;
			int cm=cl+((cr-cl)>>1);
			if(cl!=cr&&busy[p]!=0) {
				busy[2*p]+=busy[p];
				busy[2*p+1]+=busy[p];
				tree[2*p]+=(cm-cl+1)*busy[p];
				tree[2*p+1]+=(cr-cm)*busy[p];
				busy[p]=0;
			}
		}
		void build(int s,int t,int p) {
			if(s==t) {
				tree[p]=(*arr)[s];
				return;
			}
			int m=s+((t-s)>>1);
			build(s,m,p*2);
			build(m+1,t,p*2+1);
			tree[p]=tree[2*p]+tree[2*p+1];
		}
		void add(int l,int r,int cl,int cr,int v,int p) {
			if(l<=cl&&cr<=r) {
				//mantain(cl,cr,p);
				tree[p]+=(cr-cl+1)*v;
				busy[p]+=v;
				return;
			}
			int m=cl+((cr-cl)>>1);
			mantain(cl,cr,p);
			if(l<=m)add(l,r,cl,m,v,2*p);
			if(r>m)add(l,r,m+1,cr,v,2*p+1);
			tree[p] = tree[p * 2] + tree[p * 2 + 1];
			return;
		}
		int summ(int l,int r,int cl,int cr,int p) {
			if(l<=cl&&cr<=r) {
				//mantain(cl,cr,p);
				return tree[p];
			}
//		if(busy[p]!=0)mantain(cl,cr,p);
			mantain(cl,cr,p);
			int sum=0,m=cl+((cr-cl)>>1);
			if(l<=m)sum+=summ(l,r,cl,m,2*p);
			if(r>m)sum+=summ(l,r,m+1,cr,2*p+1);
			return sum;
		}
	public:
		explicit seg<T>(vector <T> v) {
			n=v.size();
			n4=4*n;
			tree=vector<T>(n4,0);
			busy=vector<T>(n4,0);
			arr=&v;
			endd = n - 1;
			root = 1;
			build(0,endd,1);
			arr=nullptr;
		}
		T summ(int l,int r) {
			return summ(l,r,0,endd,root);
		}
		void add(int l,int r,int v) {
			add(l,r,0,endd,v,root);
		}
};
signed main(){
	freopen("wxyt2.in","r",stdin);
	int poww[21];
	poww[0]=1;
	for(int i=1;i<=20;i++)poww[i]=poww[i-1]*2;
	cin>>n>>q>>W;
	vector <int> lj(n+1,0);
	for(int i=0;i<n;i++)scanf("%lld",&lj[i]);
	seg<int>s(lj);
	
	for(int i=1;i<=q;i++){
		int l,r,d;
		scanf("%lld%lld%lld",&l,&r,&d);
		s.add(l-1,r-1,d);
//		cout<<s.summ(0,n-1)<<endl;
		int t=0,ans=0,j=0;
		for(;;j++){
			int temp=s.summ(0,n-1)*poww[j];
			if(t+temp>=W){
				//会死 
				break;
			}else{
				t+=temp;
				ans+=n;
			}
//			cout<<"jihjfi:"<<t<<endl;
			
		}
		//二分
		int lll=0,rrr=n-1;
		while(lll<rrr){
			int mid=lll+((rrr-lll)>>1);
			int temp=s.summ(0,mid)*poww[j];
			if(temp+t>=W){
//				被KO
				rrr=mid;
			}else{
				lll=mid+1;
			}
		}
		ans+=rrr;
		printf("%lld:%lld\n",i,ans);
	}
	return 0;
}
2024/10/22 20:05
加载中...