当前位置:网站首页>2022杭电多校 DOS Card(线段树)
2022杭电多校 DOS Card(线段树)
2022-07-26 04:28:00 【thusloop】
DOS Card
答案只会存在情况 + + - - 或 + - + -
考虑转移
//#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);
}
}
边栏推荐
- Yadi started to slow down after high-end
- Comparison of the relationship between the number of partitions and the number of reducetask in MapReduce
- 数组排序3
- SEGGER Embedded Studio找不到xxx.c或者xxx.h文件
- 吴恩达机器学习课后习题——线性回归
- Swiftui one day crash
- Analyzing the curriculum design evaluation system of steam Education
- Under the high debt of Red Star Macalline, is it eyeing new energy?
- Recognized again | saining network security has been listed in the ccsip 2022 panorama of China's network security industry
- FFmpeg 视频编码
猜你喜欢

当你尝试删除程序中所有烂代码时 | 每日趣闻

Acwing刷题

建设面向青少年的创客教育实验室

1. Mx6u-alpha development board (main frequency and clock configuration experiment)

生活相关——十年的职业历程(转)

文献|关系研究能得出因果性结论吗

UE4 通过按键控制物体的旋转

Acwing_ 12. Find a specific solution for the knapsack problem_ dp

How does win11 change the power mode? Win11 method of changing power mode

What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep
随机推荐
机器学习之信用卡欺诈检测
1. If function of Excel
When you try to delete all bad code in the program | daily anecdotes
人脸数据库收集总结
Chapter 3 how to use sourcetree to submit code
UE4 靠近物体时显示文字,远离时文字消失
Huawei executives talk about the 35 year old crisis. How can programmers overcome the worry of age?
Use of anonymous functions
Page pull-up refresh and pull-down loading
数组排序2
Steam科学教育赋予课堂教学的创造力
makefile知识再整理(超详细)
UE4 获取玩家控制权的两种方式
生活相关——一个华科研究生导师的肺腑之言(主要适用于理工科)
吴恩达机器学习课后习题——逻辑回归
旋转数组最小数字
解决:RuntimeError: Expected object of scalar type Int but got scalar type Double
The difference between positive samples, negative samples, simple samples and difficult samples in deep learning (simple and easy to understand)
Authentication Encyclopedia (cookies, sessions, tokens, JWT, single sign on), in-depth understanding and understanding of authentication
Spark Structured Streaming HelloWorld