D - Conveyor Belts

思路:分块dp, 对于修改将对应的块再dp一次。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg
using namespace std; const int N = 1e5 + ;
const int M = 1e7 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
int n, m, q, block[N], L[N], R[N];
char s[N][], op[];
PII f[N][]; PII dp(int x, int y, char c, int B) {
if(x == L[B] - || y == || y == m + ) return mk(x, y);
if(f[x][y].fi || f[x][y].se) return f[x][y];
if(s[x][y] == '>' && c == '<') return f[x][y] = mk(-, -);
if(s[x][y] == '<' && c == '>') return f[x][y] = mk(-, -);
if(s[x][y] == '>') return f[x][y] = dp(x, y + , s[x][y], B);
if(s[x][y] == '<') return f[x][y] = dp(x, y - , s[x][y], B);
return f[x][y] = dp(x - , y, s[x][y], B);
} void update(int B) {
for(int i = L[B]; i <= R[B]; i++)
for(int j = ; j <= m; j++)
dp(i, j, '^', B);
} int main() {
memset(L, -, sizeof(L));
memset(R, -, sizeof(R)); scanf("%d%d%d", &n, &m, &q); for(int i = ; i <= n; i++) {
block[i] = i / ;
if(L[block[i]] == -) L[block[i]] = i;
R[block[i]] = i;
} for(int i = ; i <= n; i++) {
scanf("%s", s[i] + );
} for(int i = ; i <= n / ; i++) update(i); while(q--) {
int x, y;
scanf("%s%d%d", op, &x, &y);
if(op[] == 'C') {
scanf("%s", op);
s[x][y] = op[];
int p = x / ;
for(int i = L[p]; i <= R[p]; i++)
memset(f[i], , sizeof(f[i]));
update(p); } else {
while((x != -) && (x >= && x <= n && y >= && y <= m)) {
int ntx = f[x][y].fi;
int nty = f[x][y].se;
x = ntx;
y = nty;
}
printf("%d %d\n", x, y);
}
}
return ;
} /*
*/

Codeforces Round #278 (Div. 1) D - Conveyor Belts 分块+dp的更多相关文章

  1. Codeforces Round #278 (Div. 1) B. Strip multiset维护DP

    B. Strip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/B De ...

  2. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  3. Codeforces Round #278 (Div. 2)

    题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...

  4. Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)

    B. Candy Boxes Problem's Link:   http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...

  5. Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力

    A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...

  6. CodeForces Round #278 (Div.2) (待续)

    A 这么简单的题直接贴代码好了. #include <cstdio> #include <cmath> using namespace std; bool islucky(in ...

  7. Codeforces Round #278 (Div. 1)

    A A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang an ...

  8. codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)

    题意:打怪兽.可增加自己的属性,怎样在能打倒怪兽的情况下花费最少? 这题关键要找好二分的量.一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三 ...

  9. Codeforces Round #278 (Div. 2) D. Strip 线段树优化dp

    D. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

随机推荐

  1. laravel调试神器tinker

    一直以来,想调试框架中的某些东西,如想知道 Elpquent 的 create 方法返回值是个什么东西, 以前的话,应该就是在 create 方法调用之后,使用 dd 或者 var_dump 之类的函 ...

  2. c++构造是否要加大括号

    笔者被这个问题困扰良久,终于下决心看个究竟.废话不多说,先上结论: 如果对象是原生类型,加大括号会保证生成对象被初始化(一般是0) 如果对象非原生类型,加大括号或者不加,效果是一样的,都会执行该类的默 ...

  3. proc文件系统介绍

    (1)linux内核是一个非常庞大.非常复杂的一个单独的程序,对于这样的一个程序来说调试是非常复杂的.(2)项kernel这样庞大的项目,给里面添加/更改一个功能是非常麻烦的,因为你这添加的一个功能可 ...

  4. centos7通过yum安装MySQL

    一:去官网查看最新安装包 https://dev.mysql.com/downloads/repo/yum/ 二:下载MySQL源安装包 wget http://dev.mysql.com/get/m ...

  5. webapi + windows计划 + mshta 实现定时执行任务

    当然,实现定时任务有更好的操作方式,比如方式一:asp.net mvc+quartz.net +corn +webapi,asp.net mvc做任务管理的平台,使用CronTrigger做定时触发, ...

  6. python常用函数库及模块巧妙用法汇总

    在用python编写脚本或写程序过程中总要遇到一些对大文件或数据进行排序,计算,循环跌代等.我想下面这些函数库一定能用得到,总结如下:便于以后备查 列表去重(传说是列表去重最高效的方法): al = ...

  7. 你知道吗?衡量 Web 性能的几个关键指标

    自网站诞生以来,响应速度/响应时间一直都是大家关心的话题,而速度慢乃是网站的一个杀手,正当大家以为四核和宽带能力的提升能够解决这些问题时,Wi-Fi和移动设备为热点移动互联网又悄然兴起. 在2006年 ...

  8. 【BZOJ】3524: [Poi2014]Couriers

    [算法]主席树 [题解]例题,记录和,数字出现超过一半就递归查找. 主席树见[算法]数据结构 #include<cstdio> #include<algorithm> #inc ...

  9. js中字符串和json数组的相互转换

    //示例 var a={"name":"tom","sex":"男","age":"24& ...

  10. node连接数据库(express+mysql)

    操作是在ubuntu系统的下环境,简单记录一下过程. 首先用apt-get安装数据库,键入命令 sudo apt-get install mysql-server , 一路回车,然后在一个界面设置一下 ...