当前位置:网站首页>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);
}
}
边栏推荐
- Authentication Encyclopedia (cookies, sessions, tokens, JWT, single sign on), in-depth understanding and understanding of authentication
- 理性认知教育机器人寓教于乐的辅助作用
- The difference between positive samples, negative samples, simple samples and difficult samples in deep learning (simple and easy to understand)
- Steam science education endows classroom teaching with creativity
- mongoDB为什么快
- data warehouse
- UE4 keyboard control switch light
- Low cost, fast and efficient construction of digital collection app and H5 system, professional development of scallop technology is more assured!
- Postman imports curl, exports curl, and exports corresponding language codes
- 三、@RequestMapping注解
猜你喜欢

Offline installation of idea plug-in (continuous update)

自动化测试框架该如何搭建?

机器学习之桑基图(用于用户行为分析)

Comprehensive evaluation and decision-making method

嵌入式实操----基于RT1170 FreeRTOS实现CPU使用率统计(二十四)

Spark Structured Streaming HelloWorld

Sangi diagram of machine learning (for user behavior analysis)

Steam科学教育赋予课堂教学的创造力

低成本、快速、高效搭建数字藏品APP、H5系统,扇贝科技专业开发更放心!

【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(八)
随机推荐
Steam科学教育赋予课堂教学的创造力
Dijikstra (preprocessing first) +dfs, relocation truncated to fit
2022 Henan Mengxin League game (3): Henan University L - synthetic game
Several methods of realizing high-low byte or high-low word exchange in TIA botu s7-1200
Authentication Encyclopedia (cookies, sessions, tokens, JWT, single sign on), in-depth understanding and understanding of authentication
Acwing_ 12. Find a specific solution for the knapsack problem_ dp
Comprehensive evaluation and decision-making method
Phaser(一):平台跳跃收集游戏
SwiftUI一日速成
How does win11 change the power mode? Win11 method of changing power mode
Spark Structured Streaming HelloWorld
Dijango learning
2022河南萌新联赛第(三)场:河南大学 L - 合成游戏
Analyzing the curriculum design evaluation system of steam Education
10、 Interceptor
Life related -- the heartfelt words of a graduate tutor of Huake (mainly applicable to science and Engineering)
UE4 获取玩家控制权的两种方式
【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(八)
[learning notes] agc041
解析Steam教育的课程设计测评体系