当前位置:网站首页>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);
}
}
边栏推荐
- Dijango learning
- Credit card fraud detection based on machine learning
- Dijikstra (preprocessing first) +dfs, relocation truncated to fit
- egg-ts-sequelize-CLI
- Chapter 3 how to use sourcetree to submit code
- Postman imports curl, exports curl, and exports corresponding language codes
- What are the duplicate check rules for English papers?
- 人脸数据库收集总结
- The auxiliary role of rational cognitive educational robot in teaching and entertainment
- 解析Steam教育的课程设计测评体系
猜你喜欢
随机推荐
数组排序2
人脸数据库收集总结
Life related - ten years of career experience (turn)
UE4 获取玩家控制权的两种方式
Acwing brush questions
Apisex's exploration in the field of API and microservices
Comparison of the relationship between the number of partitions and the number of reducetask in MapReduce
How to write abstract in English thesis?
MySQL usage
Can literature | relationship research draw causal conclusions
Yadi started to slow down after high-end
生活相关——减少期待,更快乐
YAPI安装
Life related -- the heartfelt words of a graduate tutor of Huake (mainly applicable to science and Engineering)
理性认知教育机器人寓教于乐的辅助作用
FFmpeg 视频添加水印
I.MX6U-ALPHA开发板(主频和时钟配置实验)
青少年创客教育的创意设计原理
How to write the introduction and conclusion of an overview paper?
Firewall command simple operation








