文章

35

粉丝

599

获赞

6

访问

294.4k

头像
用线段树板子会超时啊 40%
P1604
发布于2020年5月11日 17:09
阅读数 6.6k

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=2e5+1;
#define lson x<<1
#define rson (x<<1)+1
ll tree[maxn<<2];
ll lazy[maxn<<2];
int arr[maxn];
ll ans;
int n,m;
void push_up(int x){
	tree[x]=tree[lson]+tree[rson];
}
void push_down(int x,int l,int r){//向下传递标记
	int mid=(l+r)/2;
	if(lazy[x]){
		lazy[lson]+=lazy[x];
		lazy[rson]+=lazy[x];
		tree[lson]+=(mid-l+1)*lazy[x];
		tree[rson]+=(r-mid)*lazy[x];
		lazy[x]=0;//取消本层标记		
	}
}
void create(int x,int l,int r){
	lazy[x]=0;
	if(l==r){
		tree[x]=arr[l];
		return;
	}
	int mid=(l+r)/2;
	create(lson, l, mid);
	create(rson, mid+1, r);
	push_up(x);
}
void add(int x,int l,int r,int L,int R, int val){
	if(L<=l&&R>=r){
		tree[x]+=(r-l+1)*val;
		lazy[x]+=val;
		return;
	}
	push_down(x, l, r);
	int mid=(l...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发