当前位置:网站首页>2022 Hangdian multi school DOS card (line segment tree)
2022 Hangdian multi school DOS card (line segment tree)
2022-07-26 04:32:00 【thusloop】
DOS Card
The answer will only exist + + - - or + - + -
Consider shifting
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define yesno if(fg)yes;else no;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=1e18;
const int maxn=2e5+100;
struct node
{
int l,r;
int s1100,s1010;
int s110,s100,s101,s010;
int s11,s10,s00,s01;
int s1,s0;
} t[maxn*4];
int a[maxn];
void push_up(node &u,const node &l,const node &r)
{
// if(u.l==u.r)return ;
// auto &u=t[k];
// auto &l=t[k<<1];
// auto &r=t[k<<1|1];
u.s0=max(l.s0,r.s0);
u.s1=max(l.s1,r.s1);
u.s11=max({
l.s11,r.s11,l.s1+r.s1});
u.s10=max({
l.s10,r.s10,l.s1+r.s0});
u.s00=max({
l.s00,r.s00,l.s0+r.s0});
u.s01=max({
l.s01,r.s01,l.s0+r.s1});
u.s110=max({
l.s110,r.s110,l.s1+r.s10,l.s11+r.s0});
u.s100=max({
l.s100,r.s100,l.s1+r.s00,l.s10+r.s0});
u.s101=max({
l.s101,r.s101,l.s1+r.s01,l.s10+r.s1});
u.s010=max({
l.s010,r.s010,l.s0+r.s10,l.s01+r.s0});
u.s1100=max({
l.s1100,r.s1100,l.s1+r.s100,l.s11+r.s00,l.s110+r.s0});
u.s1010=max({
l.s1010,r.s1010,l.s1+r.s010,l.s10+r.s10,l.s101+r.s0});
}
void build(int l,int r,int k)
{
t[k].l=l;
t[k].r=r;
t[k].s1100=t[k].s1010=t[k].s110=t[k].s100=t[k].s101=t[k].s010=t[k].s11=t[k].s10=t[k].s00=t[k].s01=t[k].s1=t[k].s0=-inf;
if(l==r)
{
t[k].s0=-a[l]*a[l];
t[k].s1=a[l]*a[l];
return ;
}
int mid=(l+r)>>1;
build(l,mid,k<<1);
build(mid+1,r,k<<1|1);
push_up(t[k],t[k<<1],t[k<<1|1]);
}
node query(int l,int r,int k)
{
if(r<t[k].l||l>t[k].r)return {
0,0,-inf,-inf,-inf,-inf,-inf,-inf,-inf,-inf,-inf,-inf,-inf,-inf};
if(l<=t[k].l&&t[k].r<=r)
{
return t[k];
}
node sl=query(l,r,k<<1);
node sr=query(l,r,k<<1|1);
node now;
now.l=sl.l,now.r=sr.r;
push_up(now,sl,sr);
return now;
}
signed main()
{
IOS
int tt;
cin>>tt;
while(tt--)
{
int n,m;
cin>>n>>m;
for(int i=1; i<=n; i++)
{
cin>>a[i];
}
build(1,n,1);
while(m--)
{
int l,r;
cin>>l>>r;
node ans=query(l,r,1);
cout<<max(ans.s1100,ans.s1010)<<"\n";
}
build(1,n,1);
}
}
边栏推荐
- 这种是我的vs没连上数据库吗
- Several methods of realizing high-low byte or high-low word exchange in TIA botu s7-1200
- 一个sql server查询截止某个日期最新的记录
- FFmpeg 视频添加水印
- 2022杭电多校第二场 A.Static Query on Tree(树剖)
- Function knowledge points
- SwiftUI一日速成
- Spark Structured Streaming HelloWorld
- 计算离散点的曲率(matlab)
- Solve the error string value: '\xf0\x9f\x98\xad',... 'for column' commentcontent 'at row 1
猜你喜欢

Optimization analysis and efficiency execution of MySQL

自动化测试框架该如何搭建?
远坂凛壁纸

1. Mx6u system migration-6-uboot graphical configuration

7、 Restful

UE4 靠近物体时显示文字,远离时文字消失

Sangi diagram of machine learning (for user behavior analysis)

Build a maker Education Laboratory for teenagers

Wu Enda's machine learning after class exercises - linear regression

A series of problems about the number of DP paths
随机推荐
Yuansaka Lin wallpaper
How is the launch of ros2 different?
UE4 靠近物体时显示文字,远离时文字消失
2022河南萌新联赛第(三)场:河南大学 B - 逆序对计数
计算离散点的曲率(matlab)
解决 Incorrect string value: ‘\xF0\x9F\x98\xAD“,...‘ for column ‘commentContent‘ at row 1 报错
Face database collection summary
UE4 keyboard control switch light
Solve the error string value: '\xf0\x9f\x98\xad',... 'for column' commentcontent 'at row 1
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)
Weights & Biases (二)
Rotate array minimum number
[C language foundation] 13 preprocessor
力扣每日一题-第42天-661. 图片平滑器
Array sort 2
九、文件上传和下载
How to write the introduction and conclusion of an overview paper?
第三篇如何使用SourceTree提交代码
How does win11 22h2 skip networking and Microsoft account login?
2022河南萌新联赛第(三)场:河南大学 A - 玉米大炮