关于int
  • 板块P1471 方差
  • 楼主konyakest
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/8/7 16:20
  • 上次更新2023/10/27 16:36:41
查看原帖
关于int
482660
konyakest楼主2022/8/7 16:20

rt

我全篇除了数组下标,其他都是double啊?为什么不加 #define int long long 就70,加上就AC?

// Problem: P1471 方差
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1471
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define F(i,j,k) for (signed i=signed(j);i<=signed(k);i++)
#define endl '\n'
const int maxn=1e5+5;
// #define int long long

#define ls node*2
#define rs node*2+1
#define mid (l+r)/2
#define pkgl l,mid,ls
#define pkgr mid+1,r,rs

struct pt{double x,y;};
pt operator +(pt p1,pt p2){
	return {p1.x+p2.x,p1.y+p2.y};
}
struct Segment{
	double a[maxn],s[maxn*4],s2[maxn*4],tag[maxn*4];
	Segment(){memset(tag,0,sizeof tag);}
	void push_up(int node){
		s[node]=s[ls]+s[rs];
		s2[node]=s2[ls]+s2[rs];
	}
	void updtag(int l,int r,int node,double add){
		tag[node]+=add;
		tie(s[node],s2[node])=make_tuple(
			s[node]+(r-l+1)*add,
			s2[node]+2*s[node]*add+(r-l+1)*add*add
		);
	}
	void push_down(int l,int r,int node){
		updtag(pkgl,tag[node]);
		updtag(pkgr,tag[node]);
		tag[node]=0;
	}
	void build(int l,int r,int node){
		if(l==r){
			s[node]=a[l];
			s2[node]=a[l]*a[l];
			return;
		}
		build(pkgl),build(pkgr);
		push_up(node);
	}
	void update(int l,int r,int node,int x,int y,double add){
		if(x<=l&&r<=y){updtag(l,r,node,add);return;}
		push_down(l,r,node);
		if(mid>=x) update(pkgl,x,y,add);
		if(mid<y) update(pkgr,x,y,add);
		push_up(node);
	}
	pt query(int l,int r,int node,int x,int y){
		if(x<=l&&r<=y) return {s[node],s2[node]};
		push_down(l,r,node);
		pt ans={0,0};
		if(mid>=x) ans=ans+query(pkgl,x,y);
		if(mid<y) ans=ans+query(pkgr,x,y);
		return ans;
	}
}t;
double n,m,op,x,y,k;
main() { 
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	F(i,1,n) cin>>t.a[i];
	t.build(1,n,1);
	F(i,1,m){
		cin>>op>>x>>y;
		if(op==1) cin>>k,t.update(1,n,1,x,y,k);
		if(op==2) {
			pt ans=t.query(1,n,1,x,y);
			cout<<fixed<<setprecision(4)<<ans.x/(y-x+1)<<endl;
		}
		if(op==3){
			pt ans=t.query(1,n,1,x,y);
			int N=y-x+1;
			#define sqr(x) ((x)*(x))
			cout<<fixed<<setprecision(4)<<ans.y/N-sqr(ans.x)/sqr(N)<<endl;
		}
	}
	return 0; 
}
2022/8/7 16:20
加载中...