题目链接:

题意:在二维平面上有 n 个人,每个人有一个位置(xi, yi)和门派 ci,m 个操作:①改变第 k 个人的位置;②改变第 k 个人的门派;③询问区间[l,r]之间不同门派的两个人的最大曼哈顿距离。

题解:首先需要将曼哈顿距离转化成切比雪夫距离(不懂戳https://www.cnblogs.com/zwfymqz/p/8253530.html),然后用线段树维护一个区间内两个不同门派 x 和 y 的最大最小和次大次小值即可。(维护次大/次小值是因为若区间内的最大值和最小值的人是同一个门派的话则不能进行比较)(代码写的很丑,建议理解做法后自己写一个...

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int MAXN = 1e5 + ;
const int MAXM = 1e7 + ;
const ll mod = 1e9 + ; ll x[MAXN],y[MAXN];
int c[MAXN]; struct node {
pair<ll,int> mxx[], mnx[];
pair<ll,int> mxy[], mny[];
}st[MAXN<<]; void pushup(int rt) {
st[rt] = st[rt<<];
if(st[rt].mxx[].se == -) st[rt].mxx[] = st[rt<<|].mxx[], st[rt].mxx[] = st[rt<<|].mxx[];
else if(st[rt<<|].mxx[] >= st[rt].mxx[]) {
if(st[rt<<|].mxx[].se != st[rt].mxx[].se) {
st[rt].mxx[] = st[rt].mxx[], st[rt].mxx[] = st[rt<<|].mxx[];
if(st[rt<<|].mxx[].se != - && st[rt<<|].mxx[].se != st[rt].mxx[].se && st[rt<<|].mxx[].fi >= st[rt].mxx[].fi)
st[rt].mxx[] = st[rt<<|].mxx[];
} else {
st[rt].mxx[] = st[rt<<|].mxx[];
if(st[rt<<|].mxx[].se != - && st[rt<<|].mxx[].se != st[rt].mxx[].se && st[rt<<|].mxx[].fi >= st[rt].mxx[].fi)
st[rt].mxx[] = st[rt<<|].mxx[];
}
} else {
if(st[rt<<|].mxx[].se != st[rt].mxx[].se && st[rt<<|].mxx[].fi >= st[rt].mxx[].fi)
st[rt].mxx[] = st[rt<<|].mxx[];
else if(st[rt<<|].mxx[].se != - && st[rt<<|].mxx[].se != st[rt].mxx[].se && st[rt<<|].mxx[].fi >= st[rt].mxx[].fi)
st[rt].mxx[] = st[rt<<|].mxx[];
}
//mnx
if(st[rt].mnx[].se == -) st[rt].mnx[] = st[rt<<|].mnx[], st[rt].mnx[] = st[rt<<|].mnx[];
else if(st[rt<<|].mnx[] <= st[rt].mnx[]) {
if(st[rt<<|].mnx[].se != st[rt].mnx[].se) {
st[rt].mnx[] = st[rt].mnx[], st[rt].mnx[] = st[rt<<|].mnx[];
if(st[rt<<|].mnx[].se != - && st[rt<<|].mnx[].se != st[rt].mnx[].se && st[rt<<|].mnx[].fi <= st[rt].mnx[].fi)
st[rt].mnx[] = st[rt<<|].mnx[];
} else {
st[rt].mnx[] = st[rt<<|].mnx[];
if(st[rt<<|].mnx[].se != - && st[rt<<|].mnx[].se != st[rt].mnx[].se && st[rt<<|].mnx[].fi <= st[rt].mnx[].fi)
st[rt].mnx[] = st[rt<<|].mnx[];
}
} else {
if(st[rt<<|].mnx[].se != st[rt].mnx[].se && st[rt<<|].mnx[].fi <= st[rt].mnx[].fi)
st[rt].mnx[] = st[rt<<|].mnx[];
else if(st[rt<<|].mnx[].se != - && st[rt<<|].mnx[].se != st[rt].mnx[].se && st[rt<<|].mnx[].fi <= st[rt].mnx[].fi)
st[rt].mnx[] = st[rt<<|].mnx[];
}
//mxy
if(st[rt].mxy[].se == -) st[rt].mxy[] = st[rt<<|].mxy[], st[rt].mxy[] = st[rt<<|].mxy[];
else if(st[rt<<|].mxy[] >= st[rt].mxy[]) {
if(st[rt<<|].mxy[].se != st[rt].mxy[].se) {
st[rt].mxy[] = st[rt].mxy[], st[rt].mxy[] = st[rt<<|].mxy[];
if(st[rt<<|].mxy[].se != - && st[rt<<|].mxy[].se != st[rt].mxy[].se && st[rt<<|].mxy[].fi >= st[rt].mxy[].fi)
st[rt].mxy[] = st[rt<<|].mxy[];
} else {
st[rt].mxy[] = st[rt<<|].mxy[];
if(st[rt<<|].mxy[].se != - && st[rt<<|].mxy[].se != st[rt].mxy[].se && st[rt<<|].mxy[].fi >= st[rt].mxy[].fi)
st[rt].mxy[] = st[rt<<|].mxy[];
}
} else {
if(st[rt<<|].mxy[].se != st[rt].mxy[].se && st[rt<<|].mxy[].fi >= st[rt].mxy[].fi)
st[rt].mxy[] = st[rt<<|].mxy[];
else if(st[rt<<|].mxy[].se != - && st[rt<<|].mxy[].se != st[rt].mxy[].se && st[rt<<|].mxy[].fi >= st[rt].mxy[].fi)
st[rt].mxy[] = st[rt<<|].mxy[];
}
//mny
if(st[rt].mny[].se == -) st[rt].mny[] = st[rt<<|].mny[], st[rt].mny[] = st[rt<<|].mny[];
else if(st[rt<<|].mny[] <= st[rt].mny[]) {
if(st[rt<<|].mny[].se != st[rt].mny[].se) {
st[rt].mny[] = st[rt].mny[], st[rt].mny[] = st[rt<<|].mny[];
if(st[rt<<|].mny[].se != - && st[rt<<|].mny[].se != st[rt].mny[].se && st[rt<<|].mny[].fi <= st[rt].mny[].fi)
st[rt].mny[] = st[rt<<|].mny[];
} else {
st[rt].mny[] = st[rt<<|].mny[];
if(st[rt<<|].mny[].se != - && st[rt<<|].mny[].se != st[rt].mny[].se && st[rt<<|].mny[].fi <= st[rt].mny[].fi)
st[rt].mny[] = st[rt<<|].mny[];
}
} else {
if(st[rt<<|].mny[].se != st[rt].mny[].se && st[rt<<|].mny[].fi <= st[rt].mny[].fi)
st[rt].mny[] = st[rt<<|].mny[];
else if(st[rt<<|].mny[].se != - && st[rt<<|].mny[].se != st[rt].mny[].se && st[rt<<|].mny[].fi <= st[rt].mny[].fi)
st[rt].mny[] = st[rt<<|].mny[];
}
} void build(int rt,int l,int r) {
if(l == r) {
st[rt].mxx[].fi = st[rt].mnx[].fi = x[l], st[rt].mxx[].se = st[rt].mnx[].se = c[l];
st[rt].mxx[].se = st[rt].mnx[].se = -;
st[rt].mxy[].fi = st[rt].mny[].fi = y[l], st[rt].mxy[].se = st[rt].mny[].se = c[l];
st[rt].mxy[].se = st[rt].mny[].se = -;
return ;
}
int mid = (l + r) >> ;
build(rt<<,l,mid);
build(rt<<|,mid + ,r);
pushup(rt);
} void update(int rt,int l,int r,int pos) {
if(l == r) {
st[rt].mxx[].fi = st[rt].mnx[].fi = x[l], st[rt].mxx[].se = st[rt].mnx[].se = c[l];
st[rt].mxx[].se = st[rt].mnx[].se = -;
st[rt].mxy[].fi = st[rt].mny[].fi = y[l], st[rt].mxy[].se = st[rt].mny[].se = c[l];
st[rt].mxy[].se = st[rt].mny[].se = -;
return ;
}
int mid = (l + r) >> ;
if(pos <= mid) update(rt<<,l,mid,pos);
else update(rt<<|,mid + ,r,pos);
pushup(rt);
} node ans; void query(int rt,int l,int r,int ql,int qr) {
if(ql <= l && qr >= r) {
//mxx
if(ans.mxx[].se == -) ans.mxx[] = st[rt].mxx[], ans.mxx[] = st[rt].mxx[];
else if(st[rt].mxx[] >= ans.mxx[]) {
if(st[rt].mxx[].se != ans.mxx[].se) {
ans.mxx[] = ans.mxx[], ans.mxx[] = st[rt].mxx[];
if(st[rt].mxx[].se != - && st[rt].mxx[].se != ans.mxx[].se && st[rt].mxx[].fi >= ans.mxx[].fi)
ans.mxx[] = st[rt].mxx[];
} else {
ans.mxx[] = st[rt].mxx[];
if(st[rt].mxx[].se != - && st[rt].mxx[].se != ans.mxx[].se && st[rt].mxx[].fi >= ans.mxx[].fi)
ans.mxx[] = st[rt].mxx[];
}
} else {
if(st[rt].mxx[].se != ans.mxx[].se && st[rt].mxx[].fi >= ans.mxx[].fi)
ans.mxx[] = st[rt].mxx[];
else if(st[rt].mxx[].se != - && st[rt].mxx[].se != ans.mxx[].se && st[rt].mxx[].fi >= ans.mxx[].fi)
ans.mxx[] = st[rt].mxx[];
}
//mnx
if(ans.mnx[].se == -) ans.mnx[] = st[rt].mnx[], ans.mnx[] = st[rt].mnx[];
else if(st[rt].mnx[] <= ans.mnx[]) {
if(st[rt].mnx[].se != ans.mnx[].se) {
ans.mnx[] = ans.mnx[], ans.mnx[] = st[rt].mnx[];
if(st[rt].mnx[].se != - && st[rt].mnx[].se != ans.mnx[].se && st[rt].mnx[].fi <= ans.mnx[].fi)
ans.mnx[] = st[rt].mnx[];
} else {
ans.mnx[] = st[rt].mnx[];
if(st[rt].mnx[].se != - && st[rt].mnx[].se != ans.mnx[].se && st[rt].mnx[].fi <= ans.mnx[].fi)
ans.mnx[] = st[rt].mnx[];
}
} else {
if(st[rt].mnx[].se != ans.mnx[].se && st[rt].mnx[].fi <= ans.mnx[].fi)
ans.mnx[] = st[rt].mnx[];
else if(st[rt].mnx[].se != - && st[rt].mnx[].se != ans.mnx[].se && st[rt].mnx[].fi <= ans.mnx[].fi)
ans.mnx[] = st[rt].mnx[];
}
//mxy
if(ans.mxy[].se == -) ans.mxy[] = st[rt].mxy[], ans.mxy[] = st[rt].mxy[];
else if(st[rt].mxy[] >= ans.mxy[]) {
if(st[rt].mxy[].se != ans.mxy[].se) {
ans.mxy[] = ans.mxy[], ans.mxy[] = st[rt].mxy[];
if(st[rt].mxy[].se != - && st[rt].mxy[].se != ans.mxy[].se && st[rt].mxy[].fi >= ans.mxy[].fi)
ans.mxy[] = st[rt].mxy[];
} else {
ans.mxy[] = st[rt].mxy[];
if(st[rt].mxy[].se != - && st[rt].mxy[].se != ans.mxy[].se && st[rt].mxy[].fi >= ans.mxy[].fi)
ans.mxy[] = st[rt].mxy[];
}
} else {
if(st[rt].mxy[].se != ans.mxy[].se && st[rt].mxy[].fi >= ans.mxy[].fi)
ans.mxy[] = st[rt].mxy[];
else if(st[rt].mxy[].se != - && st[rt].mxy[].se != ans.mxy[].se && st[rt].mxy[].fi >= ans.mxy[].fi)
ans.mxy[] = st[rt].mxy[];
}
//mny
if(ans.mny[].se == -) ans.mny[] = st[rt].mny[], ans.mny[] = st[rt].mny[];
else if(st[rt].mny[] <= ans.mny[]) {
if(st[rt].mny[].se != ans.mny[].se) {
ans.mny[] = ans.mny[], ans.mny[] = st[rt].mny[];
if(st[rt].mny[].se != - && st[rt].mny[].se != ans.mny[].se && st[rt].mny[].fi <= ans.mny[].fi)
ans.mny[] = st[rt].mny[];
} else {
ans.mny[] = st[rt].mny[];
if(st[rt].mny[].se != - && st[rt].mny[].se != ans.mny[].se && st[rt].mny[].fi <= ans.mny[].fi)
ans.mny[] = st[rt].mny[];
}
} else {
if(st[rt].mny[].se != ans.mny[].se && st[rt].mny[].fi <= ans.mny[].fi)
ans.mny[] = st[rt].mny[];
else if(st[rt].mny[].se != - && st[rt].mny[].se != ans.mny[].se && st[rt].mny[].fi <= ans.mny[].fi)
ans.mny[] = st[rt].mny[];
}
return ;
}
int mid = (l + r) >> ;
if(qr <= mid) query(rt<<,l,mid,ql,qr);
else if(ql > mid) query(rt<<|,mid + ,r,ql,qr);
else {
query(rt<<,l,mid,ql,mid);
query(rt<<|,mid + ,r,mid + ,qr);
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int cas = ;
int t;
scanf("%d",&t);
while(t--) {
printf("Case #%d:\n",cas++);
int n,m;
scanf("%d%d",&n,&m);
for(int i = ; i <= n; i++) {
ll x0,y0;
scanf("%lld%lld%d",&x0,&y0,&c[i]);
x[i] = x0 + y0, y[i] = x0 - y0;
}
build(,,n);
while(m--) {
int op;
scanf("%d",&op);
if(op == ) {
int k;
ll x0,y0;
scanf("%d%lld%lld",&k,&x0,&y0);
x[k] += x0 + y0, y[k] += x0 - y0;
update(,,n,k);
} else if(op == ) {
int k,col;
scanf("%d%d",&k,&col);
c[k] = col;
update(,,n,k);
} else if(op == ) {
int l,r;
scanf("%d%d",&l,&r); for(int i = ; i < ; i++) {
ans.mxx[i].se = ans.mnx[i].se = -;
ans.mxy[i].se = ans.mny[i].se = -;
}
query(,,n,l,r);
ll out = ;
//x
if(ans.mxx[].se != -) {
if(ans.mxx[].se != - && ans.mxx[].se != ans.mxx[].se)
out = max(out,abs(ans.mxx[].fi - ans.mxx[].fi));
if(ans.mnx[].se != - && ans.mnx[].se != ans.mxx[].se)
out = max(out,abs(ans.mxx[].fi - ans.mnx[].fi));
if(ans.mnx[].se != - && ans.mnx[].se != ans.mxx[].se)
out = max(out,abs(ans.mxx[].fi - ans.mnx[].fi));
}
if(ans.mxx[].se != -) {
if(ans.mnx[].se != - && ans.mnx[].se != ans.mxx[].se)
out = max(out,abs(ans.mxx[].fi - ans.mnx[].fi));
if(ans.mnx[].se != - && ans.mnx[].se != ans.mxx[].se)
out = max(out,abs(ans.mxx[].fi - ans.mnx[].fi));
}
if(ans.mnx[].se != - && ans.mnx[].se != -)
out = max(out,abs(ans.mnx[].fi - ans.mnx[].fi));
//y
if(ans.mxy[].se != -) {
if(ans.mxy[].se != - && ans.mxy[].se != ans.mxy[].se)
out = max(out,abs(ans.mxy[].fi - ans.mxy[].fi));
if(ans.mny[].se != - && ans.mny[].se != ans.mxy[].se)
out = max(out,abs(ans.mxy[].fi - ans.mny[].fi));
if(ans.mny[].se != - && ans.mny[].se != ans.mxy[].se)
out = max(out,abs(ans.mxy[].fi - ans.mny[].fi));
}
if(ans.mxy[].se != -) {
if(ans.mny[].se != - && ans.mny[].se != ans.mxy[].se)
out = max(out,abs(ans.mxy[].fi - ans.mny[].fi));
if(ans.mny[].se != - && ans.mny[].se != ans.mxy[].se)
out = max(out,abs(ans.mxy[].fi - ans.mny[].fi));
}
if(ans.mny[].se != - && ans.mny[].se != -)
out = max(out,abs(ans.mny[].fi - ans.mny[].fi));
printf("%lld\n",out);
}
}
}
return ;
}

ACM-ICPC 2018 沈阳赛区现场赛 E. The Kouga Ninja Scrolls (切比雪夫距离+线段树)的更多相关文章

  1. ACM-ICPC 2018 沈阳赛区现场赛 K. Let the Flames Begin (约瑟夫环问题)

    题目链接: 题意:有 n 个人围成一个圈,从 1 开始报到第 k 个人出环,问第 m 个出环的人是谁,n.m.k <= 1e18 且 min(m,k)<= 2e6. 题解:容易得出O(m) ...

  2. 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)

    摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...

  3. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  4. ACM-ICPC 2018 沈阳赛区(网络赛)

    D.Made In Heaven One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with he ...

  5. ICPC 2018 徐州赛区网络赛

    ACM-ICPC 2018 徐州赛区网络赛  去年博客记录过这场比赛经历:该死的水题  一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进.     D. Easy Math 题意:   ...

  6. ACM总结——2017ACM-ICPC北京赛区现场赛总结

    现在距离比赛结束已经过了一个多星期了,也是终于有时间写下心得了.回来就是被压着做项目,也是够够的. 这次比赛一样是我和两个学弟(虽然是学弟,但我的实力才是最弱的T_T)一起参加的,成绩的话打铁,算是情 ...

  7. ACM ICPC 2018 青岛赛区 部分金牌题题解(K,L,I,G)

     目录: K Airdrop I Soldier Game L Sub-cycle Graph G Repair the Artwork ———————————————————— ps:楼主脑残有点严 ...

  8. ACM-ICPC 2018 青岛赛区现场赛 K. Airdrop && ZOJ 4068 (暴力)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4068 题意:吃鸡游戏简化为二维平面上有 n 个人 (xi,yi) ...

  9. ACM-ICPC 2018 青岛赛区现场赛 D. Magic Multiplication && ZOJ 4061 (思维+构造)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4061 题意:定义一个长度为 n 的序列 a1,a2,..,an ...

随机推荐

  1. linux shell中的EOF

    关键词:EOF 在平时的运维工作中,我们经常会碰到这样一个场景:执行脚本的时候,需要往一个文件里自动输入N行内容.如果是少数的几行内容,还可以用echo追加方式,但如果是很多行,那么单纯用echo追加 ...

  2. Docker下搭建mongodb副本集

    背景 有需求需要对mongodb做一个容灾备份.根据官网,发现mongodb最新版本(4.0)已经抛弃了主从模式而采用副本集进行容灾.副本集的优势在于:"有自动故障转移和恢复特性,其任意节点 ...

  3. Spring Boot系列教程十二:Spring boot集成Redis

    一.创建项目 项目名称为 "springboot_redis",创建过程中勾选 "Web","Redis",第一次创建Maven需要下载依赖 ...

  4. Gossip协议

    Gossip数据传播协议: Fabric通过将工作负载划分到事务执行(背书和提交)对等节点和事务排序节点,优化了区块链网络性能.安全性和可伸缩性.这种网络操作的解耦需要一个安全.可靠和可伸缩的数据传播 ...

  5. hdu 6375 度度熊学队列 (链表模拟)

    度度熊正在学习双端队列,他对其翻转和合并产生了很大的兴趣.  初始时有 N 个空的双端队列(编号为 1 到 N ),你要支持度度熊的 Q 次操作. ①1 u w val 在编号为 u 的队列里加入一个 ...

  6. CSS定位以及z-index属性(层叠性)的详解(转)

    https://blog.csdn.net/weixin_41342585/article/details/79484879

  7. (四)Maven中的仓库

    一.分类 maven的仓库只有两大类: 1.本地仓库 2.远程仓库,在远程仓库中又分成了3种: 2.1 中央仓库 2.2 私服 2.3 其它公共库 二.本地仓库 本地仓库,顾名思义,就是Maven在本 ...

  8. office2016激活码 最新各个版本 激活

    office2016专业版激活密钥 Microsoft Office 2016 Pro Plus Retail 零售版序列号密钥: BHXN7-MQB36-MTHQ4-8MHKV-CYT97 Micr ...

  9. wstngfw中配置squid

    wstngfw中配置squid Squid是一个缓存 Internet 数据的软件,其接收用户的下载申请,并自动处理所下载的数据.当一个用户想要下载一个主页时,可以向 Squid 发出一个申请,要 S ...

  10. Mysql 更新时间

    Mysql时间加减函数为date_add().date_sub() 定义和用法DATE_ADD() 函数向日期添加指定的时间间隔.DATE_SUB() 函数向日期减少指定的时间间隔.语法DATE_AD ...