当前位置:网站首页>22-07-16 personal training match 3 competition experience
22-07-16 personal training match 3 competition experience
2022-07-26 08:19:00 【Fanshui 682】
notes : Read what the senior wrote blog Just found that you can use the directory , It seems convenient for me , Take the time to fill in the directory of the previous blog .
The game went well ahead , The back was caught by three cows (doge)
I'm so happy to make up the question today , I passed a line segment tree ( Although it is still very stiff )
The intranet address is still posted
Catalog
N: The pain of Antarctica snails

A: violence map
B: routine BFS
C: Thinking greedy + bucket
D: Water problem
E: Complex simulation ( Simulation is not needed )
F: Water problem
G: Two points ( How can I forget sort wa+8)
J: Water problem
K: Thinking simulation
L: thinking
M: Sign in prime ( But I didn't see the question clearly and rushed over )
N: Line segment tree board variant
N: The pain of Antarctica snails
Questions that cannot be found

Ideas : Because ask and sum , So we must let ai*ki Maintain as a whole to add , Otherwise, if you separate , Interval fetching ai*ki And i The value obtained when maintaining an interval is incorrect . Because the value at this time should be al*kl+a(l+1)*k(l+2)+.......+ar*kr Instead of being maintained now (al+a(l+1)+...ar)*(kl+k(l+1)+...kr), Because separate maintenance will lead to a or k As a whole , instead of a*k.
So maintenance ai*ki, Define a... In the structure alone sum, We found that , When a Section +w When ,sum In fact, the change is +(k*w),k The same goes for interval addition , So as long as pushdown Add an extra pair in sum Just pass it on , See the code for details .
#include <bits/stdc++.h>
//#define int long long
#define CIO std::ios::sync_with_stdio(false)
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define nep(i, r, l) for (int i = r; i >= l; i--)
#define pii pair<int,int>
using namespace std;
const int N=2e5+5;
struct tree{
int a,k,sum;
}tr[4*N];
int num[N],laza[4*N],lazk[4*N];
void builda(int p,int l,int r){
if (l==r){
tr[p].a=num[l];
return;
}
int mid=l+r>>1;
builda(2*p,l,mid);
builda(2*p+1,mid+1,r);
tr[p].a=tr[2*p].a+tr[2*p+1].a;
}
void buildk(int p,int l,int r){
if (l==r){
tr[p].k=num[l];
tr[p].sum=tr[p].k*tr[p].a;
return;
}
int mid=l+r>>1;
buildk(2*p,l,mid);
buildk(2*p+1,mid+1,r);
tr[p].k=tr[2*p].k+tr[2*p+1].k;
tr[p].sum=tr[2*p].sum+tr[2*p+1].sum;
}
void pushdown(int p,int l,int r){
int mid=l+r>>1;
laza[2*p]+=laza[p];
laza[2*p+1]+=laza[p];
tr[2*p].sum+=laza[p]*tr[2*p].k;
tr[2*p+1].sum+=laza[p]*tr[2*p+1].k;
tr[2*p].a+=laza[p]*(mid-l+1);
tr[2*p+1].a+=laza[p]*(r-mid);
lazk[2*p]+=lazk[p];
lazk[2*p+1]+=lazk[p];
tr[2*p].sum+=lazk[p]*tr[2*p].a;
tr[2*p+1].sum+=lazk[p]*tr[2*p+1].a;
tr[2*p].k+=lazk[p]*(mid-l+1);
tr[2*p+1].k+=lazk[p]*(r-mid);
lazk[p]=0;
laza[p]=0;
}
int query(int p,int l,int r,int x,int y){
if (x<=l&&r<=y){
return tr[p].sum;
}
pushdown(p,l,r);
int mid=l+r>>1,ans=0;
if (x<=mid)ans+=query(2*p,l,mid,x,y);
if (mid<y)ans+=query(2*p+1,mid+1,r,x,y);
return ans;
}
void updatea(int p,int l,int r,int x,int y,int w){
if (x<=l&&r<=y){
tr[p].sum+=w*tr[p].k;
tr[p].a+=w*(r-l+1);
laza[p]+=w;
return;
}
pushdown(p,l,r);
int mid=l+r>>1;
if (x<=mid)updatea(2*p,l,mid,x,y,w);
if (mid<y)updatea(2*p+1,mid+1,r,x,y,w);
tr[p].a=tr[2*p].a+tr[2*p+1].a;
tr[p].sum=tr[2*p].sum+tr[2*p+1].sum;
}
void updatek(int p,int l,int r,int x,int y,int w){
if (x<=l&&r<=y){
tr[p].sum+=w*tr[p].a;
tr[p].k+=w*(r-l+1);
lazk[p]+=w;
return;
}
pushdown(p,l,r);
int mid=l+r>>1;
if (x<=mid)updatek(2*p,l,mid,x,y,w);
if (mid<y)updatek(2*p+1,mid+1,r,x,y,w);
tr[p].k=tr[2*p].k+tr[2*p+1].k;
tr[p].sum=tr[2*p].sum+tr[2*p+1].sum;
}
void work(){
int n,q;
cin>>n>>q;
rep(i,1,n){
cin>>num[i];
}
builda(1,1,n);
rep(i,1,n){
cin>>num[i];
}
buildk(1,1,n);
int op,l,r,w;
rep(i,1,q){
cin>>op;
if (op==1){
cin>>l>>r>>w;
updatea(1,1,n,l,r,w);
}
else if (op==2){
cin>>l>>r>>w;
updatek(1,1,n,l,r,w);
}
else{
cin>>l>>r;
cout<<query(1,1,n,l,r)<<endl;
}
}
}
signed main(){
CIO;
work();
return 0;
}
边栏推荐
- On some concepts involved in journal papers compilation + journal query methods
- 万字长文 | 深入理解 OpenFeign 的架构原理
- The idea of stack simulating queue
- BGP -- Border Gateway Protocol
- 要不你给我说说什么是长轮询吧?
- Burp Suite-第二章 Burp Suite代理和浏览器设置
- Burp Suite-第八章 如何使用Burp Intruder
- Bee guitar score high octave and low octave
- Common methods of string: construction method, other methods
- 外卖小哥,才是这个社会最大的托底
猜你喜欢

JSP implicit object servlet object

This is a picture

Software engineering -- dental clinic -- demand analysis

A little awesome, 130000 a month+

Guitar staff link Jasmine
Share high voltage ultra low noise LDO test results

BGP的基本配置

Traversal mode of list, set, map, queue, deque, stack

On some concepts involved in journal papers compilation + journal query methods

咱就是来聊聊并发编程的三大核心问题。
随机推荐
Strtus2历史漏洞复现
matplotlib学习笔记
mysql函数汇总之日期和时间函数
Kotlin中room数据库的使用
Software engineering -- dental clinic -- demand analysis
分享高压超低噪声LDO测试结果(High Voltage Ultra-low Noise LDO)
【时间复杂度空间复杂度】
Dev gridcontrol 捕获按键事件
Burp Suite-第三章 如何使用Burp Suite代理
Burp Suite-第五章 如何使用Burp Target
BGP的基本配置
VIM cross line matching search
【 fastjson1.2.24反序列化漏洞原理代码分析】
[xshell7 free download and installation]
A clear summary and configuration example of GPON has been highlighted
sed作业
Burp suite Chapter 8 how to use burp intruder
Pycharm code specification tool flake8
Storage of drawings (refined version)
This is a picture