传送门

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

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

 //Achen
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
#define Formylove return 0
const int N=1e5+;
typedef long long LL;
typedef double db;
using namespace std;
int n,q,a[][N],tpa[],mx; template<typename T> void read(T &x) {
char ch=getchar(); T f=; x=;
while(ch!='-'&&(ch<''||ch>'')) ch=getchar();
if(ch=='-') f=-,ch=getchar();
for(;ch>=''&&ch<='';ch=getchar()) x=x*+ch-''; x*=f;
} #define inf 1e15
LL dl[N<<][][],dr[N<<][][],dm[N<<][][];
void copyit(int x,int y) {
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];
}
void upd(int y,int ll,int rr) {
int x=mx+,lc=mx+,rc=mx+;
copyit(ll,lc); copyit(rr,rc);
For(i,,) For(j,,) For(k,,) {
dm[lc][i][j]=min(dm[lc][i][j],dm[lc][i][k]+dl[rc][k][j]);
dm[rc][i][j]=min(dm[rc][i][j],dm[rc][k][j]+dr[lc][k][i]);
}
For(i,,) For(j,,) {
dm[x][i][j]=inf;
For(k,,) dm[x][i][j]=min(dm[x][i][j],dm[lc][i][k]+dm[rc][k][j]);
}
For(i,,) For(j,,) {
dl[x][i][j]=dl[lc][i][j];
dr[x][i][j]=dr[rc][i][j];
For(k,,) dl[x][i][j]=min(dl[x][i][j],dm[lc][i][k]+dm[lc][j][k]);
For(k,,) dr[x][i][j]=min(dr[x][i][j],dm[rc][k][i]+dm[rc][k][j]);
}
copyit(x,y);
} #define lc (x<<1)
#define rc ((x<<1)|1)
#define mid ((l+r)>>1)
void updone(int x,int l) {
For(i,,) tpa[i]=(i?tpa[i-]:)+a[i][l];
For(i,,) For(j,,) {
LL ds=i>j?(tpa[i]-(j?tpa[j-]:)):(tpa[j]-(i?tpa[i-]:));
dl[x][i][j]=dr[x][i][j]=dm[x][i][j]=ds;
}
} void build(int x,int l,int r) {
if(l==r) { updone(x,l); return ; }
build(lc,l,mid); build(rc,mid+,r);
upd(x,lc,rc);
} void change(int x,int l,int r,int pos) {
if(l==r) { updone(x,l); return; }
if(pos<=mid) change(lc,l,mid,pos);
else change(rc,mid+,r,pos);
upd(x,lc,rc);
} int fl;
void qry(int x,int l,int r,int ql,int qr,int t) {
if(ql>qr) return ;
if(l>=ql&&r<=qr) {
if(!fl) copyit(x,t),fl=;
else upd(t,t,x); return ;
}
if(ql<=mid) qry(lc,l,mid,ql,qr,t);
if(qr>mid) qry(rc,mid+,r,ql,qr,t);
} int main() {
//freopen("2104.in","r",stdin);
//freopen("2104.out","w",stdout);
read(n); mx=(n<<);
For(i,,) For(j,,n) read(a[i][j]);
build(,,n);
read(q);
For(i,,q) {
int op,x,y,v,sx,sy,tx,ty;
read(op);
if(op==) {
read(x); read(y); read(v);
a[x-][y]=v; change(,,n,y);
}
else {
read(sx); read(sy); sx--;
read(tx); read(ty); tx--;
if(sy>ty) swap(sx,tx),swap(sy,ty);
fl=; qry(,,n,sy,ty,mx+);
fl=; qry(,,n,,sy-,mx+);
fl=; qry(,,n,ty+,n,mx+);
LL ans=dm[mx+][sx][tx];
if(sy!=) {
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]);
For(k,,) ans=min(ans,dl[mx+][sx][sx]+dr[mx+][sx][k]+dm[mx+][k][tx]);
}
if(ty!=n) {
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]);
For(k,,) ans=min(ans,dm[mx+][sx][k]+dl[mx+][k][tx]+dr[mx+][tx][tx]);
}
if(sy!=&&ty!=n) {
For(k,,) For(l,,)
ans=min(ans,dr[mx+][sx][k]+dm[mx+][k][l]+dl[mx+][l][tx]+dl[mx+][sx][sx]+dr[mx+][tx][tx]);
}
printf("%lld\n",ans);
}
}
Formylove;
}

[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. Git配置出现的问题

    git是代码版本同步工具,适用于团队开发,进公司第一堂课就是配置Git.接下来就把其中遇到的问题记录一下,与大家共享一下. 首先,在Bitbucket上注册账户,之后给管理员说一下,让他邀请你加入开发 ...

  2. $git学习总结系列(2)——远程仓库

    本文主要介绍git本地仓库和GitHub远程仓库之间的交互和数据传输. 注:首先需要到github.com上注册一个账号. 1. 添加本地SSH Key到GitHub 要向GitHub远程仓库推送代码 ...

  3. DNS 安装配置

    DNS 安装配置 实验环境 一台主机:Linux Centos 6.5 32位 安装包: DNS服务:bind.i686 DNS测试工具:bind-utils DNS 服务安装 1.yum安装DNS服 ...

  4. nodejs安装,配置环境,使用express建立一个新项目

    1.下载nodejs安装包 去nodejs官网下载最新版本就行,网址:http://nodejs.cn/download/,点击自己适用的系统,自动下载跟电脑操作系统位数符合的安装包, 下载下来安装包 ...

  5. pagination结合ajax

    function getContent(page,Id){ $.ajax({ type:'get', url:'www.baidu.com', dataType:'jsonp', data:{ }, ...

  6. Java 类及类的构造方法

    类 类是一个模子,确定对象将会拥有的特性(属性)和行为(方法). 类的特点 类时对象的类型 具有相同属性和方法的一组对象的集合 构造方法 作用就是对类进行初始化. 如果你没有定议任何构造方法的形式,J ...

  7. CentOS 7防火墙设置开放80端口

    在CentOS 6.x版本中,默认使用的是iptables防火墙.到了CentOS 7.x版本,默认防火墙变成了firewalld.本篇通过使用firewalld开启.关闭 HTTP(80)端口,来讲 ...

  8. 关于图片上传与下载(Java)

    图片的上传 package com.upload; import java.io.IOException;import java.io.PrintWriter; import javax.servle ...

  9. ssh框架整合意义

    一次次学习,一次次不一样的进一步理解. 一.Struts2.String.Hibernate框架的整合的意义: 1.需要将所有的对象进行统一管理(action动作类:sessionFactory) 2 ...

  10. ADO.Net连接Mysql

    首先下载一个mysql.data.dll拷贝到bin下面并引用一下 using MySql.Data.MySqlClient; class Program { static void Main(str ...