题目:http://codeforces.com/contest/1093/problem/G

只好看看题解:https://codeforces.com/blog/entry/63877

主要是把绝对值符号消掉,变成枚举正负。因为答案不会变差,所以不用管符号应该是什么,直接对应地取 max 、 min 即可。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ls Ls[cr]
#define rs Rs[cr]
using namespace std;
const int N=2e5+5,M=N<<1,K=10,tK=35,INF=5e6+5;
int n,k,lm,bin[K],Q,a[N][K],tot,Ls[M],Rs[M];
int Mx(int a,int b){return a>b?a:b;}
int Mn(int a,int b){return a<b?a:b;}
struct Node{
int mx[tK],mn[tK];
Node operator+ (const Node &b)const
{
Node c;
for(int i=0;i<lm;i++)
{
c.mx[i]=Mx(mx[i],b.mx[i]);
c.mn[i]=Mn(mn[i],b.mn[i]);
}
return c;
}
}sm[M];
int rdn()
{
int ret=0;bool fx=1;char ch=getchar();
while(ch>'9'||ch<'0'){if(ch=='-')fx=0;ch=getchar();}
while(ch>='0'&&ch<='9')ret=ret*10+ch-'0',ch=getchar();
return fx?ret:-ret;
}
void dfs(int cr,int lj,int s,int id,int bh)
{
if(cr>k)
{
sm[bh].mn[s]=sm[bh].mx[s]=lj;
return;
}
dfs(cr+1,lj+a[id][cr],s|bin[cr],id,bh);
dfs(cr+1,lj-a[id][cr],s,id,bh);
}
void build(int l,int r,int cr)
{
if(l==r){dfs(1,0,0,l,cr);return;}
int mid=l+r>>1;
ls=++tot;build(l,mid,ls);
rs=++tot;build(mid+1,r,rs);
sm[cr]=sm[ls]+sm[rs];
}
void updt(int l,int r,int cr,int p)
{
if(l==r){dfs(1,0,0,l,cr);return;}
int mid=l+r>>1;
if(p<=mid)updt(l,mid,ls,p);
else updt(mid+1,r,rs,p);
sm[cr]=sm[ls]+sm[rs];
}
Node query(int l,int r,int cr,int L,int R)
{
if(l>=L&&r<=R)return sm[cr];
int mid=l+r>>1;
if(L>mid)return query(mid+1,r,rs,L,R);
if(R<=mid)return query(l,mid,ls,L,R);
return query(l,mid,ls,L,R)+query(mid+1,r,rs,L,R);
}
int main()
{
n=rdn();k=rdn();lm=(1<<k);
bin[1]=1;for(int i=2;i<=k;i++)bin[i]=bin[i-1]<<1;
for(int i=1;i<=n;i++)
for(int j=1;j<=k;j++)a[i][j]=rdn();
tot=1;build(1,n,1);
Q=rdn();
for(int i=1,op,id,l,r;i<=Q;i++)
{
op=rdn();
if(op==1)
{
id=rdn();
for(int j=1;j<=k;j++)a[id][j]=rdn();
updt(1,n,1,id);
}
else
{
l=rdn();r=rdn();
Node d=query(1,n,1,l,r);int ans=-INF;
for(int i=0;i<lm;i++)
ans=Mx(ans,d.mx[i]-d.mn[i]);
printf("%d\n",ans);
}
}
return 0;
}

CF 1093G Multidimensional Queries——线段树(消去绝对值符号)的更多相关文章

  1. HDU 4027 Can you answer these queries? (线段树区间修改查询)

    描述 A lot of battleships of evil are arranged in a line before the battle. Our commander decides to u ...

  2. CF 1023D Array Restoration - 线段树

    题解 非常容易想到的线段树, 还可以用并查集来. 还有一位大神用了$O(n)$ 就过了Orz 要判断是否能染色出输入给出的序列,必须满足两个条件: 1. 序列中必须存在一个$q$ 2. 两个相同的数$ ...

  3. hdu 4027 Can you answer these queries? 线段树区间开根号,区间求和

    Can you answer these queries? Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/sho ...

  4. CF 787D Legacy(线段树思想构图+最短路)

    D. Legacy time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  5. Light OJ-1082 - Array Queries,线段树区间查询最大值,哈哈,水过~~

                                                                                                        ...

  6. HDU4027 Can you answer these queries? —— 线段树 区间修改

    题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...

  7. HDU-4027-Can you answer these queries?线段树+区间根号+剪枝

    传送门Can you answer these queries? 题意:线段树,只是区间修改变成 把每个点的值开根号: 思路:对[X,Y]的值开根号,由于最大为 263.可以观察到最多开根号7次即为1 ...

  8. Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)

    链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowerca ...

  9. HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)

    题目 线段树 简单题意: 区间(单点?)更新,区间求和  更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...

随机推荐

  1. Android实现布局控件自定义属性

    一.自定义ViewGroup 1.onMeasure 决定内部View(子View)的宽度和高度,以及自己的宽度和高度 2.onLayout 决定子View放置的位置 3.onTouchEvent 定 ...

  2. tcp/ip学习笔记-TCP

    tcp/ip学习笔记-TCP 彭会锋 报文发送采用的是tcp_output函数,

  3. [Tomcat 部署问题] Undeployment Failure could not be redeployed ...

    Tomcat 部署,在部署可能会出现以下问题: Deployment failure on Tomcat 6.x. Could not copy all resources to E:\apache- ...

  4. POJ-3659-最小支配集裸题/树形dp

    Cell Phone Network Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7127   Accepted: 254 ...

  5. guava学习--cache

    转载:http://outofmemory.cn/java/guava/cache/how-to-use-guava-cache   http://www.cnblogs.com/parryyang/ ...

  6. JS中,如何判断一个数是不是小数?如果是小数,如何判断它是几位小数??

    <script type="text/javascript">     var x = 4.23323;//测试的数字     var y = String(x).in ...

  7. [VS]VS快捷键

    VS快速跳到某一行:CTRL+G VS鼠标移动到下一个高亮处:Ctrl+Shift+上下箭头 VS转到定义后返回:Ctrl+- VS折叠全部代码:Ctrl.M+Ctrl.O VS代码格式化:Ctrl. ...

  8. RabbitMQ(1) 核心概念

    消息中间价 消息中间价,也称消息队列,是分布式式系统中常用的中间价. 通过消息中间价传递消息,使得各个子系统解耦,异步通信. 目前业界有许多消息队列的实现,如RabbitMQ.Kafka.Active ...

  9. WordCount-个人项目2

    我的这个WC程序实现了对txt文件中的数据的计数,算出程序中有多少单词.字符数.行数还有空格数.以及长度. 项目源代码参考:http://www.cnblogs.com/sunbuqiao/p/531 ...

  10. JSP里的<c:if>不起作用[待解答]

    JSP页面的部分代码如下: 下面的title作为请求参数,shoppingCart作为session范围域的属性. 问题1: 如果去掉<c:if>的判断条件,第一行打印:可以正常显示出来, ...