[Wc2009]shortest
终于把这题过了,了了我两年前写堵塞的交通一晚上无果的心结
因为是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的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- [LeetCode] Encode String with Shortest Length 最短长度编码字符串
Given a non-empty string, encode the string such that its encoded length is the shortest. The encodi ...
- [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 ...
- [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 ...
- [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 ...
- [LeetCode] Shortest Word Distance 最短单词距离
Given a list of words and two words word1 and word2, return the shortest distance between these two ...
- [LeetCode] Shortest Palindrome 最短回文串
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. ...
- 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 ...
- LeetCode 214 Shortest Palindrome
214-Shortest Palindrome Given a string S, you are allowed to convert it to a palindrome by adding ch ...
随机推荐
- Loadrunder之脚本篇——关联
关联的原理 关联也属于一钟特殊的参数化.一般参数化的参数来源于一个文件.一个定义的table.通过sql写的一个结果集等,但关联所获得的参数是服务器响应请求所返回的一个符合条件的.动态的值. 例子:常 ...
- $ListView的优化机制和滑动时数据错乱的讨论
Refer:http://www.myexception.cn/mobile/1612364.html (一)Android ListView的基本用法 1.创建一个实体类Person,为其添加Get ...
- 028_MapReduce中的计数器Counter的使用
一.分析运行wordcount程序屏幕上打印信息 ##运行wordcount单词频率统计程序,基于输出输出路径. [hadoop@hadoop-master hadoop-1.2.1]$ hadoop ...
- qq 微信 微博 第三方分享
<html> <head> <meta charset="utf-8"> <meta name="viewport" ...
- Apache的order、allow、deny
Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directory, Location, Files等),用来控制目录和文件的访问授权. 所以,最常用的是:Or ...
- [RK3288][Android6.0] 调试笔记 --- user版本默认显示开发者选项【转】
本文转载自:https://blog.csdn.net/kris_fei/article/details/70157137 Platform: ROCKCHIPOS: Android 6.0Kerne ...
- maven setting.xml 存放位置导致deply失败,显示没有权限401错误
settings.xml存在于两个地方: 1.安装的地方:$M2_HOME/conf/settings.xml 2.用户的目录:${user.home}/.m2/settings.xml 我只在mav ...
- struts2数据类型转换详解
Web应用程序的交互都是建立在HTTP之上的,互相传递的都是字符串.也就是说服务器接收到的来自用户的数据只能是字符串或者是字符数组,而在Web应用的对象中,往往使用了多种不同的类型,如整数(int). ...
- PHP(Zend Studio)入门视频
视频地址: http://www.ev-get.com/article/2014/5/9/20962.html (去掉地址中的减号-:可以看视频) Zend Studio教学视频之Zend Studi ...
- QT 利用ListWidget 和 StackedLayout 配合实现 分页 选项
1. 如图, 左边为listwidget,右边为StackedLayout, 通过listwidget的不同选项,可以使右边的不同页显示出来. 2. dialog.h #ifndef DIALOG_H ...