codeforces1093G Multidimensional Queries 【线段树】
题目分析:
搜索2^k种情况,线段树分别处理就行了,正确性明显。
代码:
#include<bits/stdc++.h>
using namespace std; const int maxn = ; int n,k;
struct node{int x[];}a[maxn]; int Tmax[<<][maxn*],Tmin[<<][maxn*]; void Modify(int now,int tl,int tr,int dt,int pos){
if(tl == tr){
int ans = ;
for(int i=;i<k;i++){
if(dt & (<<i))ans += a[tl].x[i];
else ans -= a[tl].x[i];
}
Tmax[dt][now] = Tmin[dt][now] = ans;
}else{
int mid = (tl+tr)/;
if(pos <= mid) Modify(now<<,tl,mid,dt,pos);
else Modify(now<<|,mid+,tr,dt,pos);
Tmax[dt][now] = max(Tmax[dt][now<<],Tmax[dt][now<<|]);
Tmin[dt][now] = min(Tmin[dt][now<<],Tmin[dt][now<<|]);
}
} void Modifydfs(int now,int dt,int pos){
if(now == k) Modify(,,n,dt,pos);
else{Modifydfs(now+,dt,pos); Modifydfs(now+,dt+(<<now),pos);}
} pair<int,int> query(int now,int tl,int tr,int l,int r,int dt){
if(tl >= l && tr <= r) return make_pair(Tmax[dt][now],Tmin[dt][now]);
if(tl > r || tr < l) return make_pair(-1e9,1e9);
int mid = (tl+tr)/;
pair<int,int> a1 = query(now<<,tl,mid,l,r,dt);
pair<int,int> a2 = query(now<<|,mid+,tr,l,r,dt);
return make_pair(max(a1.first,a2.first),min(a1.second,a2.second));
} int dfs2(int now,int dt,int l,int r){
if(now == k) {
pair<int,int> ans = query(,,n,l,r,dt);
return ans.first-ans.second;
}else{return max(dfs2(now+,dt,l,r),dfs2(now+,dt+(<<now),l,r));}
} void read(){
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
for(int j=;j<k;j++) scanf("%d",&a[i].x[j]);
}
for(int i=;i<=n;i++) Modifydfs(,,i);
} void work(){
int q; scanf("%d",&q);
for(int i=;i<=q;i++){
int cas; scanf("%d",&cas);
if(cas == ){
int now; scanf("%d",&now);
for(int j=;j<k;j++) scanf("%d",&a[now].x[j]);
Modifydfs(,,now);
}else{
int l,r; scanf("%d%d",&l,&r);
int maxmum = dfs2(,,l,r);
printf("%d\n",maxmum);
}
}
} int main(){
read();
work();
return ;
}
codeforces1093G Multidimensional Queries 【线段树】的更多相关文章
- CF 1093G Multidimensional Queries——线段树(消去绝对值符号)
题目:http://codeforces.com/contest/1093/problem/G 只好看看题解:https://codeforces.com/blog/entry/63877 主要是把绝 ...
- 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 ...
- 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 ...
- Light OJ-1082 - Array Queries,线段树区间查询最大值,哈哈,水过~~
...
- HDU4027 Can you answer these queries? —— 线段树 区间修改
题目链接:https://vjudge.net/problem/HDU-4027 A lot of battleships of evil are arranged in a line before ...
- HDU-4027-Can you answer these queries?线段树+区间根号+剪枝
传送门Can you answer these queries? 题意:线段树,只是区间修改变成 把每个点的值开根号: 思路:对[X,Y]的值开根号,由于最大为 263.可以观察到最多开根号7次即为1 ...
- 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 ...
- HDU 4027 Can you answer these queries?(线段树,区间更新,区间查询)
题目 线段树 简单题意: 区间(单点?)更新,区间求和 更新是区间内的数开根号并向下取整 这道题不用延迟操作 //注意: //1:查询时的区间端点可能前面的比后面的大: //2:优化:因为每次更新都 ...
- hdu 4027 Can you answer these queries? 线段树
线段树+剪枝优化!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #includ ...
随机推荐
- ESP8266的低功耗方案-睡眠模式
在某些时候我们设计的产品可能不具备持久供电的环境,那通常会采用锂电池.干电池一类的轻便型的非持久性电源.当遇到这种情况时,产品的续航能力可能就会成用户评估产品的一个重要指标,加大电池容量当然是最为直接 ...
- ReactJs移动端兼容问题汇总
汽车H5使用ReactJs问题汇总 Q:安卓4.4webview显示空白? A:初步怀疑是css属性没有加前缀引发的兼容问题,但添加后发现也不行,通过webview调试后控制台输出Set is und ...
- UnderWater+SDN论文之五
Underwater Sensor Networks with Mobile Agents: Experience from the Field Source: LNICST 2013 论文是来自两个 ...
- #Leetcode# 633. Sum of Square Numbers
https://leetcode.com/problems/sum-of-square-numbers/ Given a non-negative integer c, your task is to ...
- PHP之CLI模式
转载: http://www.cnblogs.com/zcy_soft/archive/2011/12/10/2283437.html 所有的PHP发行版,不论是编译自源代码的版本还是预创建的版本,都 ...
- vue处理异步数据踩过的坑
在开发时,由于数据是异步的导致页面在render 时data是空值 出现报错和警告. 我是这么处理的 把data先写出一个空的完整结构.暂时是这么处理 或者用三元表达式进行赋值监听.data ?myd ...
- Jquery 选择器 特殊字符 转义字符
1.Jquery 选择器 id包含特殊字符,加双斜线 \\ 例 <input type="text" id="dbo_HouseInfo.HouseResour ...
- Azure系列2.1.13 —— CloudBlockBlob
(小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...
- [转帖]Windows平台卸载Oracle的办法
1.首先打开服务:选中此电脑->点击右键->选择管理->选择服务和应用程序->服务 在右边查看并停止以 oracle开头的服务(选中正在运行的以oracle开头的服务-> ...
- js对字符串的一些操作方法
1.charCodeAt(index); 返回一个整数,代表下标位置上字符的Unicode的编码. 2.fromCharCode(code1,code2,code3,...); code1代表Unic ...