传送门

终于把这题过了,了了我两年前写堵塞的交通一晚上无果的心结

因为是6要注意蛇皮走位啊!!这种-> S

  1. //Achen
  2. #include<bits/stdc++.h>
  3. #define For(i,a,b) for(int i=(a);i<=(b);i++)
  4. #define Rep(i,a,b) for(int i=(a);i>=(b);i--)
  5. #define Formylove return 0
  6. const int N=1e5+;
  7. typedef long long LL;
  8. typedef double db;
  9. using namespace std;
  10. int n,q,a[][N],tpa[],mx;
  11.  
  12. template<typename T> void read(T &x) {
  13. char ch=getchar(); T f=; x=;
  14. while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
  15. if(ch=='-') f=-,ch=getchar();
  16. for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
  17. }
  18.  
  19. #define inf 1e15
  20. LL dl[N<<][][],dr[N<<][][],dm[N<<][][];
  21. void copyit(int x,int y) {
  22. For(i,,) For(j,,) dl[y][i][j]=dl[x][i][j],dr[y][i][j]=dr[x][i][j],dm[y][i][j]=dm[x][i][j];
  23. }
  24. void upd(int y,int ll,int rr) {
  25. int x=mx+,lc=mx+,rc=mx+;
  26. copyit(ll,lc); copyit(rr,rc);
  27. For(i,,) For(j,,) For(k,,) {
  28. dm[lc][i][j]=min(dm[lc][i][j],dm[lc][i][k]+dl[rc][k][j]);
  29. dm[rc][i][j]=min(dm[rc][i][j],dm[rc][k][j]+dr[lc][k][i]);
  30. }
  31. For(i,,) For(j,,) {
  32. dm[x][i][j]=inf;
  33. For(k,,) dm[x][i][j]=min(dm[x][i][j],dm[lc][i][k]+dm[rc][k][j]);
  34. }
  35. For(i,,) For(j,,) {
  36. dl[x][i][j]=dl[lc][i][j];
  37. dr[x][i][j]=dr[rc][i][j];
  38. For(k,,) dl[x][i][j]=min(dl[x][i][j],dm[lc][i][k]+dm[lc][j][k]);
  39. For(k,,) dr[x][i][j]=min(dr[x][i][j],dm[rc][k][i]+dm[rc][k][j]);
  40. }
  41. copyit(x,y);
  42. }
  43.  
  44. #define lc (x<<1)
  45. #define rc ((x<<1)|1)
  46. #define mid ((l+r)>>1)
  47. void updone(int x,int l) {
  48. For(i,,) tpa[i]=(i?tpa[i-]:)+a[i][l];
  49. For(i,,) For(j,,) {
  50. LL ds=i>j?(tpa[i]-(j?tpa[j-]:)):(tpa[j]-(i?tpa[i-]:));
  51. dl[x][i][j]=dr[x][i][j]=dm[x][i][j]=ds;
  52. }
  53. }
  54.  
  55. void build(int x,int l,int r) {
  56. if(l==r) { updone(x,l); return ; }
  57. build(lc,l,mid); build(rc,mid+,r);
  58. upd(x,lc,rc);
  59. }
  60.  
  61. void change(int x,int l,int r,int pos) {
  62. if(l==r) { updone(x,l); return; }
  63. if(pos<=mid) change(lc,l,mid,pos);
  64. else change(rc,mid+,r,pos);
  65. upd(x,lc,rc);
  66. }
  67.  
  68. int fl;
  69. void qry(int x,int l,int r,int ql,int qr,int t) {
  70. if(ql>qr) return ;
  71. if(l>=ql&&r<=qr) {
  72. if(!fl) copyit(x,t),fl=;
  73. else upd(t,t,x); return ;
  74. }
  75. if(ql<=mid) qry(lc,l,mid,ql,qr,t);
  76. if(qr>mid) qry(rc,mid+,r,ql,qr,t);
  77. }
  78.  
  79. int main() {
  80. //freopen("2104.in","r",stdin);
  81. //freopen("2104.out","w",stdout);
  82. read(n); mx=(n<<);
  83. For(i,,) For(j,,n) read(a[i][j]);
  84. build(,,n);
  85. read(q);
  86. For(i,,q) {
  87. int op,x,y,v,sx,sy,tx,ty;
  88. read(op);
  89. if(op==) {
  90. read(x); read(y); read(v);
  91. a[x-][y]=v; change(,,n,y);
  92. }
  93. else {
  94. read(sx); read(sy); sx--;
  95. read(tx); read(ty); tx--;
  96. if(sy>ty) swap(sx,tx),swap(sy,ty);
  97. fl=; qry(,,n,sy,ty,mx+);
  98. fl=; qry(,,n,,sy-,mx+);
  99. fl=; qry(,,n,ty+,n,mx+);
  100. LL ans=dm[mx+][sx][tx];
  101. if(sy!=) {
  102. For(j,,) For(k,,) dr[mx+][sx][j]=min(dr[mx+][sx][j],dl[mx+][sx][k]+dr[mx+][k][j]-dl[mx+][sx][sx]);
  103. For(k,,) ans=min(ans,dl[mx+][sx][sx]+dr[mx+][sx][k]+dm[mx+][k][tx]);
  104. }
  105. if(ty!=n) {
  106. For(j,,) For(k,,) dl[mx+][j][tx]=min(dl[mx+][j][tx],dr[mx+][k][tx]+dl[mx+][j][k]-dr[mx+][tx][tx]);
  107. For(k,,) ans=min(ans,dm[mx+][sx][k]+dl[mx+][k][tx]+dr[mx+][tx][tx]);
  108. }
  109. if(sy!=&&ty!=n) {
  110. For(k,,) For(l,,)
  111. ans=min(ans,dr[mx+][sx][k]+dm[mx+][k][l]+dl[mx+][l][tx]+dl[mx+][sx][sx]+dr[mx+][tx][tx]);
  112. }
  113. printf("%lld\n",ans);
  114. }
  115. }
  116. Formylove;
  117. }

[Wc2009]shortest的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  2. [LeetCode] Encode String with Shortest Length 最短长度编码字符串

    Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...

  3. [LeetCode] Shortest Distance from All Buildings 建筑物的最短距离

    You want to build a house on an empty land which reaches all buildings in the shortest amount of dis ...

  4. [LeetCode] Shortest Word Distance III 最短单词距离之三

    This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as ...

  5. [LeetCode] Shortest Word Distance II 最短单词距离之二

    This is a follow up of Shortest Word Distance. The only difference is now you are given the list of ...

  6. [LeetCode] Shortest Word Distance 最短单词距离

    Given a list of words and two words word1 and word2, return the shortest distance between these two ...

  7. [LeetCode] Shortest Palindrome 最短回文串

    Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...

  8. Leetcode: Encode String with Shortest Length && G面经

    Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...

  9. LeetCode 214 Shortest Palindrome

    214-Shortest Palindrome Given a string S, you are allowed to convert it to a palindrome by adding ch ...

随机推荐

  1. Kattis - pseudoprime 【快速幂】

    题意 给出两个数字 P 和 A 当p 不是素数 并且 满足a^p≡a(mod p) 就输出 yes 否则 输出 no 思路 因为 数据范围较大,用快速幂 AC代码 #include <cstdi ...

  2. iOS 快速遍历 效率分析 for loop for in enumerateBlock 适用条件

    test1 简单遍历 结论: 当数组数据量很小 时候 for loop 和 for in 效率不相上下,随着数据量增长for in 快速枚举的优势 明显 如果需要知道 索引可用 enumrateBlo ...

  3. 机器学习算法之:KNN

    基于实例的学习方法中,最近邻法和局部加权回归法用于逼近实值或离散目标函数,基于案例的推理已经被应用到很多任务中,比如,在咨询台上存储和复用过去的经验:根据以前的法律案件进行推理:通过复用以前求解的问题 ...

  4. 【HackerRank】Bus Station

    有n组好朋友在公交车站前排队.第i组有ai个人.还有一辆公交车在路线上行驶.公交车的容量大小为x,即它可以同时运载x个人. 当车站来车时(车总是空载过来),一些组从会队头开始走向公交车. 当然,同一组 ...

  5. 【HackerRank】Gem Stones

    Gem Stones John has discovered various rocks. Each rock is composed of various elements, and each el ...

  6. iMX6 yocto平台QT交叉编译环境搭建

    转:https://blog.csdn.net/morixinguan/article/details/79351909 . /opt/fsl-imx-fb/4.9.11-1.0.0/environm ...

  7. python:格式化输出 str.format()

    官网说明:https://docs.python.org/2/library/string.html#formatstrings python的格式输出有两种方法: 1.“ %s”.(variant) ...

  8. C#多线程学习之Thread

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. POI实现数据的导入

    1.POI技术的概述? POI技术:apache POI是可以对微软office文档进行读和写的工具. l HSSF:操作97格式的excel,扩展名:.xls 纯二进制,最大行数65535. l X ...

  10. 使用shell自动备份数据库

    全备份 #!/bin/sh #mysql地址 #检测用户是否手动输入了密码 mysql_host="" #mysql用户 mysql_user="" #mysq ...