题目链接:

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

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

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define ull unsigned long long
  5. #define mst(a,b) memset((a),(b),sizeof(a))
  6. #define mp(a,b) make_pair(a,b)
  7. #define pi acos(-1)
  8. #define pii pair<int,int>
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. const int INF = 0x3f3f3f3f;
  13. const double eps = 1e-;
  14. const int MAXN = 1e5 + ;
  15. const int MAXM = 1e7 + ;
  16. const ll mod = 1e9 + ;
  17.  
  18. ll x[MAXN],y[MAXN];
  19. int c[MAXN];
  20.  
  21. struct node {
  22. pair<ll,int> mxx[], mnx[];
  23. pair<ll,int> mxy[], mny[];
  24. }st[MAXN<<];
  25.  
  26. void pushup(int rt) {
  27. st[rt] = st[rt<<];
  28. if(st[rt].mxx[].se == -) st[rt].mxx[] = st[rt<<|].mxx[], st[rt].mxx[] = st[rt<<|].mxx[];
  29. else if(st[rt<<|].mxx[] >= st[rt].mxx[]) {
  30. if(st[rt<<|].mxx[].se != st[rt].mxx[].se) {
  31. st[rt].mxx[] = st[rt].mxx[], st[rt].mxx[] = st[rt<<|].mxx[];
  32. if(st[rt<<|].mxx[].se != - && st[rt<<|].mxx[].se != st[rt].mxx[].se && st[rt<<|].mxx[].fi >= st[rt].mxx[].fi)
  33. st[rt].mxx[] = st[rt<<|].mxx[];
  34. } else {
  35. st[rt].mxx[] = st[rt<<|].mxx[];
  36. if(st[rt<<|].mxx[].se != - && st[rt<<|].mxx[].se != st[rt].mxx[].se && st[rt<<|].mxx[].fi >= st[rt].mxx[].fi)
  37. st[rt].mxx[] = st[rt<<|].mxx[];
  38. }
  39. } else {
  40. if(st[rt<<|].mxx[].se != st[rt].mxx[].se && st[rt<<|].mxx[].fi >= st[rt].mxx[].fi)
  41. st[rt].mxx[] = st[rt<<|].mxx[];
  42. else if(st[rt<<|].mxx[].se != - && st[rt<<|].mxx[].se != st[rt].mxx[].se && st[rt<<|].mxx[].fi >= st[rt].mxx[].fi)
  43. st[rt].mxx[] = st[rt<<|].mxx[];
  44. }
  45. //mnx
  46. if(st[rt].mnx[].se == -) st[rt].mnx[] = st[rt<<|].mnx[], st[rt].mnx[] = st[rt<<|].mnx[];
  47. else if(st[rt<<|].mnx[] <= st[rt].mnx[]) {
  48. if(st[rt<<|].mnx[].se != st[rt].mnx[].se) {
  49. st[rt].mnx[] = st[rt].mnx[], st[rt].mnx[] = st[rt<<|].mnx[];
  50. if(st[rt<<|].mnx[].se != - && st[rt<<|].mnx[].se != st[rt].mnx[].se && st[rt<<|].mnx[].fi <= st[rt].mnx[].fi)
  51. st[rt].mnx[] = st[rt<<|].mnx[];
  52. } else {
  53. st[rt].mnx[] = st[rt<<|].mnx[];
  54. if(st[rt<<|].mnx[].se != - && st[rt<<|].mnx[].se != st[rt].mnx[].se && st[rt<<|].mnx[].fi <= st[rt].mnx[].fi)
  55. st[rt].mnx[] = st[rt<<|].mnx[];
  56. }
  57. } else {
  58. if(st[rt<<|].mnx[].se != st[rt].mnx[].se && st[rt<<|].mnx[].fi <= st[rt].mnx[].fi)
  59. st[rt].mnx[] = st[rt<<|].mnx[];
  60. else if(st[rt<<|].mnx[].se != - && st[rt<<|].mnx[].se != st[rt].mnx[].se && st[rt<<|].mnx[].fi <= st[rt].mnx[].fi)
  61. st[rt].mnx[] = st[rt<<|].mnx[];
  62. }
  63. //mxy
  64. if(st[rt].mxy[].se == -) st[rt].mxy[] = st[rt<<|].mxy[], st[rt].mxy[] = st[rt<<|].mxy[];
  65. else if(st[rt<<|].mxy[] >= st[rt].mxy[]) {
  66. if(st[rt<<|].mxy[].se != st[rt].mxy[].se) {
  67. st[rt].mxy[] = st[rt].mxy[], st[rt].mxy[] = st[rt<<|].mxy[];
  68. if(st[rt<<|].mxy[].se != - && st[rt<<|].mxy[].se != st[rt].mxy[].se && st[rt<<|].mxy[].fi >= st[rt].mxy[].fi)
  69. st[rt].mxy[] = st[rt<<|].mxy[];
  70. } else {
  71. st[rt].mxy[] = st[rt<<|].mxy[];
  72. if(st[rt<<|].mxy[].se != - && st[rt<<|].mxy[].se != st[rt].mxy[].se && st[rt<<|].mxy[].fi >= st[rt].mxy[].fi)
  73. st[rt].mxy[] = st[rt<<|].mxy[];
  74. }
  75. } else {
  76. if(st[rt<<|].mxy[].se != st[rt].mxy[].se && st[rt<<|].mxy[].fi >= st[rt].mxy[].fi)
  77. st[rt].mxy[] = st[rt<<|].mxy[];
  78. else if(st[rt<<|].mxy[].se != - && st[rt<<|].mxy[].se != st[rt].mxy[].se && st[rt<<|].mxy[].fi >= st[rt].mxy[].fi)
  79. st[rt].mxy[] = st[rt<<|].mxy[];
  80. }
  81. //mny
  82. if(st[rt].mny[].se == -) st[rt].mny[] = st[rt<<|].mny[], st[rt].mny[] = st[rt<<|].mny[];
  83. else if(st[rt<<|].mny[] <= st[rt].mny[]) {
  84. if(st[rt<<|].mny[].se != st[rt].mny[].se) {
  85. st[rt].mny[] = st[rt].mny[], st[rt].mny[] = st[rt<<|].mny[];
  86. if(st[rt<<|].mny[].se != - && st[rt<<|].mny[].se != st[rt].mny[].se && st[rt<<|].mny[].fi <= st[rt].mny[].fi)
  87. st[rt].mny[] = st[rt<<|].mny[];
  88. } else {
  89. st[rt].mny[] = st[rt<<|].mny[];
  90. if(st[rt<<|].mny[].se != - && st[rt<<|].mny[].se != st[rt].mny[].se && st[rt<<|].mny[].fi <= st[rt].mny[].fi)
  91. st[rt].mny[] = st[rt<<|].mny[];
  92. }
  93. } else {
  94. if(st[rt<<|].mny[].se != st[rt].mny[].se && st[rt<<|].mny[].fi <= st[rt].mny[].fi)
  95. st[rt].mny[] = st[rt<<|].mny[];
  96. else if(st[rt<<|].mny[].se != - && st[rt<<|].mny[].se != st[rt].mny[].se && st[rt<<|].mny[].fi <= st[rt].mny[].fi)
  97. st[rt].mny[] = st[rt<<|].mny[];
  98. }
  99. }
  100.  
  101. void build(int rt,int l,int r) {
  102. if(l == r) {
  103. st[rt].mxx[].fi = st[rt].mnx[].fi = x[l], st[rt].mxx[].se = st[rt].mnx[].se = c[l];
  104. st[rt].mxx[].se = st[rt].mnx[].se = -;
  105. st[rt].mxy[].fi = st[rt].mny[].fi = y[l], st[rt].mxy[].se = st[rt].mny[].se = c[l];
  106. st[rt].mxy[].se = st[rt].mny[].se = -;
  107. return ;
  108. }
  109. int mid = (l + r) >> ;
  110. build(rt<<,l,mid);
  111. build(rt<<|,mid + ,r);
  112. pushup(rt);
  113. }
  114.  
  115. void update(int rt,int l,int r,int pos) {
  116. if(l == r) {
  117. st[rt].mxx[].fi = st[rt].mnx[].fi = x[l], st[rt].mxx[].se = st[rt].mnx[].se = c[l];
  118. st[rt].mxx[].se = st[rt].mnx[].se = -;
  119. st[rt].mxy[].fi = st[rt].mny[].fi = y[l], st[rt].mxy[].se = st[rt].mny[].se = c[l];
  120. st[rt].mxy[].se = st[rt].mny[].se = -;
  121. return ;
  122. }
  123. int mid = (l + r) >> ;
  124. if(pos <= mid) update(rt<<,l,mid,pos);
  125. else update(rt<<|,mid + ,r,pos);
  126. pushup(rt);
  127. }
  128.  
  129. node ans;
  130.  
  131. void query(int rt,int l,int r,int ql,int qr) {
  132. if(ql <= l && qr >= r) {
  133. //mxx
  134. if(ans.mxx[].se == -) ans.mxx[] = st[rt].mxx[], ans.mxx[] = st[rt].mxx[];
  135. else if(st[rt].mxx[] >= ans.mxx[]) {
  136. if(st[rt].mxx[].se != ans.mxx[].se) {
  137. ans.mxx[] = ans.mxx[], ans.mxx[] = st[rt].mxx[];
  138. if(st[rt].mxx[].se != - && st[rt].mxx[].se != ans.mxx[].se && st[rt].mxx[].fi >= ans.mxx[].fi)
  139. ans.mxx[] = st[rt].mxx[];
  140. } else {
  141. ans.mxx[] = st[rt].mxx[];
  142. if(st[rt].mxx[].se != - && st[rt].mxx[].se != ans.mxx[].se && st[rt].mxx[].fi >= ans.mxx[].fi)
  143. ans.mxx[] = st[rt].mxx[];
  144. }
  145. } else {
  146. if(st[rt].mxx[].se != ans.mxx[].se && st[rt].mxx[].fi >= ans.mxx[].fi)
  147. ans.mxx[] = st[rt].mxx[];
  148. else if(st[rt].mxx[].se != - && st[rt].mxx[].se != ans.mxx[].se && st[rt].mxx[].fi >= ans.mxx[].fi)
  149. ans.mxx[] = st[rt].mxx[];
  150. }
  151. //mnx
  152. if(ans.mnx[].se == -) ans.mnx[] = st[rt].mnx[], ans.mnx[] = st[rt].mnx[];
  153. else if(st[rt].mnx[] <= ans.mnx[]) {
  154. if(st[rt].mnx[].se != ans.mnx[].se) {
  155. ans.mnx[] = ans.mnx[], ans.mnx[] = st[rt].mnx[];
  156. if(st[rt].mnx[].se != - && st[rt].mnx[].se != ans.mnx[].se && st[rt].mnx[].fi <= ans.mnx[].fi)
  157. ans.mnx[] = st[rt].mnx[];
  158. } else {
  159. ans.mnx[] = st[rt].mnx[];
  160. if(st[rt].mnx[].se != - && st[rt].mnx[].se != ans.mnx[].se && st[rt].mnx[].fi <= ans.mnx[].fi)
  161. ans.mnx[] = st[rt].mnx[];
  162. }
  163. } else {
  164. if(st[rt].mnx[].se != ans.mnx[].se && st[rt].mnx[].fi <= ans.mnx[].fi)
  165. ans.mnx[] = st[rt].mnx[];
  166. else if(st[rt].mnx[].se != - && st[rt].mnx[].se != ans.mnx[].se && st[rt].mnx[].fi <= ans.mnx[].fi)
  167. ans.mnx[] = st[rt].mnx[];
  168. }
  169. //mxy
  170. if(ans.mxy[].se == -) ans.mxy[] = st[rt].mxy[], ans.mxy[] = st[rt].mxy[];
  171. else if(st[rt].mxy[] >= ans.mxy[]) {
  172. if(st[rt].mxy[].se != ans.mxy[].se) {
  173. ans.mxy[] = ans.mxy[], ans.mxy[] = st[rt].mxy[];
  174. if(st[rt].mxy[].se != - && st[rt].mxy[].se != ans.mxy[].se && st[rt].mxy[].fi >= ans.mxy[].fi)
  175. ans.mxy[] = st[rt].mxy[];
  176. } else {
  177. ans.mxy[] = st[rt].mxy[];
  178. if(st[rt].mxy[].se != - && st[rt].mxy[].se != ans.mxy[].se && st[rt].mxy[].fi >= ans.mxy[].fi)
  179. ans.mxy[] = st[rt].mxy[];
  180. }
  181. } else {
  182. if(st[rt].mxy[].se != ans.mxy[].se && st[rt].mxy[].fi >= ans.mxy[].fi)
  183. ans.mxy[] = st[rt].mxy[];
  184. else if(st[rt].mxy[].se != - && st[rt].mxy[].se != ans.mxy[].se && st[rt].mxy[].fi >= ans.mxy[].fi)
  185. ans.mxy[] = st[rt].mxy[];
  186. }
  187. //mny
  188. if(ans.mny[].se == -) ans.mny[] = st[rt].mny[], ans.mny[] = st[rt].mny[];
  189. else if(st[rt].mny[] <= ans.mny[]) {
  190. if(st[rt].mny[].se != ans.mny[].se) {
  191. ans.mny[] = ans.mny[], ans.mny[] = st[rt].mny[];
  192. if(st[rt].mny[].se != - && st[rt].mny[].se != ans.mny[].se && st[rt].mny[].fi <= ans.mny[].fi)
  193. ans.mny[] = st[rt].mny[];
  194. } else {
  195. ans.mny[] = st[rt].mny[];
  196. if(st[rt].mny[].se != - && st[rt].mny[].se != ans.mny[].se && st[rt].mny[].fi <= ans.mny[].fi)
  197. ans.mny[] = st[rt].mny[];
  198. }
  199. } else {
  200. if(st[rt].mny[].se != ans.mny[].se && st[rt].mny[].fi <= ans.mny[].fi)
  201. ans.mny[] = st[rt].mny[];
  202. else if(st[rt].mny[].se != - && st[rt].mny[].se != ans.mny[].se && st[rt].mny[].fi <= ans.mny[].fi)
  203. ans.mny[] = st[rt].mny[];
  204. }
  205. return ;
  206. }
  207. int mid = (l + r) >> ;
  208. if(qr <= mid) query(rt<<,l,mid,ql,qr);
  209. else if(ql > mid) query(rt<<|,mid + ,r,ql,qr);
  210. else {
  211. query(rt<<,l,mid,ql,mid);
  212. query(rt<<|,mid + ,r,mid + ,qr);
  213. }
  214. }
  215.  
  216. int main() {
  217. #ifdef local
  218. freopen("data.txt", "r", stdin);
  219. // freopen("data.txt", "w", stdout);
  220. #endif
  221. int cas = ;
  222. int t;
  223. scanf("%d",&t);
  224. while(t--) {
  225. printf("Case #%d:\n",cas++);
  226. int n,m;
  227. scanf("%d%d",&n,&m);
  228. for(int i = ; i <= n; i++) {
  229. ll x0,y0;
  230. scanf("%lld%lld%d",&x0,&y0,&c[i]);
  231. x[i] = x0 + y0, y[i] = x0 - y0;
  232. }
  233. build(,,n);
  234. while(m--) {
  235. int op;
  236. scanf("%d",&op);
  237. if(op == ) {
  238. int k;
  239. ll x0,y0;
  240. scanf("%d%lld%lld",&k,&x0,&y0);
  241. x[k] += x0 + y0, y[k] += x0 - y0;
  242. update(,,n,k);
  243. } else if(op == ) {
  244. int k,col;
  245. scanf("%d%d",&k,&col);
  246. c[k] = col;
  247. update(,,n,k);
  248. } else if(op == ) {
  249. int l,r;
  250. scanf("%d%d",&l,&r);
  251.  
  252. for(int i = ; i < ; i++) {
  253. ans.mxx[i].se = ans.mnx[i].se = -;
  254. ans.mxy[i].se = ans.mny[i].se = -;
  255. }
  256. query(,,n,l,r);
  257. ll out = ;
  258. //x
  259. if(ans.mxx[].se != -) {
  260. if(ans.mxx[].se != - && ans.mxx[].se != ans.mxx[].se)
  261. out = max(out,abs(ans.mxx[].fi - ans.mxx[].fi));
  262. if(ans.mnx[].se != - && ans.mnx[].se != ans.mxx[].se)
  263. out = max(out,abs(ans.mxx[].fi - ans.mnx[].fi));
  264. if(ans.mnx[].se != - && ans.mnx[].se != ans.mxx[].se)
  265. out = max(out,abs(ans.mxx[].fi - ans.mnx[].fi));
  266. }
  267. if(ans.mxx[].se != -) {
  268. if(ans.mnx[].se != - && ans.mnx[].se != ans.mxx[].se)
  269. out = max(out,abs(ans.mxx[].fi - ans.mnx[].fi));
  270. if(ans.mnx[].se != - && ans.mnx[].se != ans.mxx[].se)
  271. out = max(out,abs(ans.mxx[].fi - ans.mnx[].fi));
  272. }
  273. if(ans.mnx[].se != - && ans.mnx[].se != -)
  274. out = max(out,abs(ans.mnx[].fi - ans.mnx[].fi));
  275. //y
  276. if(ans.mxy[].se != -) {
  277. if(ans.mxy[].se != - && ans.mxy[].se != ans.mxy[].se)
  278. out = max(out,abs(ans.mxy[].fi - ans.mxy[].fi));
  279. if(ans.mny[].se != - && ans.mny[].se != ans.mxy[].se)
  280. out = max(out,abs(ans.mxy[].fi - ans.mny[].fi));
  281. if(ans.mny[].se != - && ans.mny[].se != ans.mxy[].se)
  282. out = max(out,abs(ans.mxy[].fi - ans.mny[].fi));
  283. }
  284. if(ans.mxy[].se != -) {
  285. if(ans.mny[].se != - && ans.mny[].se != ans.mxy[].se)
  286. out = max(out,abs(ans.mxy[].fi - ans.mny[].fi));
  287. if(ans.mny[].se != - && ans.mny[].se != ans.mxy[].se)
  288. out = max(out,abs(ans.mxy[].fi - ans.mny[].fi));
  289. }
  290. if(ans.mny[].se != - && ans.mny[].se != -)
  291. out = max(out,abs(ans.mny[].fi - ans.mny[].fi));
  292. printf("%lld\n",out);
  293. }
  294. }
  295. }
  296. return ;
  297. }

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. javaIO -- File源码

    一.简介 文件和目录路径名的抽象表示. 用户界面和操作系统使用依赖于系统的路径名字符串命名文件和目录. 这个类提供了一个抽象的,独立于系统的层次化路径名的视图. 二.代码 (一).属性详情 //平台的 ...

  2. php文件操作类

    <?php /** *本类为文件操作类,实现了文件的建立,写入,删除,修改,复制,移动,创建目录,删除目录 * 列出目录里的文件等功能,路径后面别忘了加"/" */ clas ...

  3. 【计算几何】Water Testing

    Water Testing 题目描述 You just bought a large piece of agricultural land, but you noticed that – accord ...

  4. linux中的内核级防火墙(SELINUX)

    SElinux是基于内核开发出来的一种安全机制,被称之为内核级加强型防火墙,有力的提升了系统的安全性. SElinux的作用分为两方面:1.在服务上面加上标签: 2.在功能上面限制功能 在linux系 ...

  5. (十六)SpringBoot之使用 Caching- - EhCache

    一.案例 1.1 引入maven依赖 <!-- caching --> <dependency> <groupId>org.springframework.boot ...

  6. JAVA的转义字符

    一.常见的转义字符 转移字符对应的英文是escape character  , 转义字符串(Escape Sequence) 字母前面加上捺斜线"\"来表示常见的那些不能显示的AS ...

  7. js中 this 的指向

    js中 this的指向一共存在3种地方: 1.全局的this; 2.构造函数的this; 3.call/apply; 一.全局的this: function test(){ this.d = 3;// ...

  8. ubuntu装openssh-client和openssh-server

    1. 修改update源 进入/etc/apt/目录,首先用cp命令将sources.list备份成sources.list.bk,然后复制http://www.cnblogs.com/eastson ...

  9. Linq to sql之left join运用示例

    示例一: var l= from a in cardsBll.GetCards() join b in usersBll.GetAllUsers() on a.CardSn equals b.Card ...

  10. Navicat远程连接centos上mysql出错

    原因1:mysql账户是不允许远程连接 参考:centos安装mysql(for 小白) 打开远程连接 原因2:3306端口未开启 开启端口:iptables -I INPUT -p tcp --dp ...