题意:https://ac.nowcoder.com/acm/contest/882/E

给你01矩阵,有两种操作:1是把一个位置0变1、1变0,2是问你从第一行i开始,到最后一行j有几种走法。你只能不能向上走而且不能往回走。

思路:

01矩阵里每一行可以用一个矩阵表示向下有几种走法,i行到j行的的走法就是各行的矩阵的乘积。用线段树维护即可。

线段树seg【1】的【x】【y】就是答案。

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\Input.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr strcat
#include <string>
#include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
#include <cassert>
#include <iomanip>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
clock_t __STRAT,__END;
double __TOTALTIME;
void _MS(){__STRAT=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__STRAT)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
const double E=2.718281828;
const double PI=acos(-1.0);
const ll INF=(1LL<<);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int); int n,m,q;
char a[N][];
int fa[];
void init()
{
for(int i=;i<=;++i)
fa[i]=i;
}
int Find(int x)
{
return (x==fa[x])?x:(fa[x]=Find(fa[x]));
} void combine(int a,int b)
{
int temp_a,temp_b; temp_a=Find(a);
temp_b=Find(b); if(temp_a!=temp_b)
{
if(temp_a<temp_b)
fa[temp_b]=temp_a;
else
fa[temp_a]=temp_b;
}
} struct Mat
{
ll a[][];
}seg[N<<],e,n1;
Mat mul(Mat x,Mat y)
{
Mat c=Mat();
for(int i=;i<=;++i)
{
for(int j=;j<=;++j)
{
for(int k=;k<=;++k)
c.a[i][j]+=(x.a[i][k]*y.a[k][j])%mod,c.a[i][j]%=mod;
}
}
return c;
}
void up(int rt,int l,int r)
{
seg[rt]=mul(seg[ls],seg[rs]);
} void Build(int l,int r,int rt)
{
if(l==r)
{
init();
for(int j=;j<=m;++j)
{
if(j<m&&a[l][j]==''&&a[l][j+]=='')
combine(j,j+);
}
seg[rt]=Mat();
for(int j=;j<=m;++j)
for(int k=;k<=m;++k)
if(a[l][j]==''&&a[l][k]==''&&Find(j)==Find(k))
seg[rt].a[j][k]=;
return;
}
int mid=(l+r)>>; Build(l,mid,rt<<);
Build(mid+,r,rt<<|);
up(rt,l,r);
} void update_dot(int pos,Mat V,int l,int r,int rt)
{
if(l==r)
{
seg[rt]=V;
return;
} int mid=(l+r)>>;
if(pos<=mid)
update_dot(pos,V,l,mid,rt<<);
else
update_dot(pos,V,mid+,r,rt<<|);
up(rt,l,r);
} int main()
{
e=n1=Mat();
for(int i=;i<=;++i)
e.a[i][i]=,n1.a[][i]=;
sc("%d%d%d",&n,&m,&q);
for(int i=;i<=n;++i)
sc("%s",a[i]+);
Build(,n,);
for(int i=;i<=q;++i)
{
int op,x,y;
sc("%d%d%d",&op,&x,&y);
if(op==)
{
a[x][y]^=;
init();
for(int j=;j<=m;++j)
{
if(j<m&&a[x][j]==''&&a[x][j+]=='')
combine(j,j+);
}
Mat temp=Mat();
for(int j=;j<=m;++j)
for(int k=;k<=m;++k)
if(a[x][j]==''&&a[x][k]==''&&Find(j)==Find(k))
temp.a[j][k]=;
update_dot(x,temp,,n,);
}
else
pr("%lld\n",seg[].a[x][y]);
}
return ;
} /**************************************************************************************/

DP+线段树维护矩阵(2019牛客暑期多校训练营(第二场))--MAZE的更多相关文章

  1. 2019牛客暑期多校训练营(第二场) H-Second Large Rectangle(单调栈)

    题意:给出由01组成的矩阵,求求全是1的次大子矩阵. 思路: 单调栈 全是1的最大子矩阵的变形,不能直接把所有的面积存起来然后排序取第二大的,因为次大子矩阵可能在最大子矩阵里面,比如: 1 0 0 1 ...

  2. 2019牛客暑期多校训练营(第九场) D Knapsack Cryptosystem

    题目 题意: 给你n(最大36)个数,让你从这n个数里面找出来一些数,使这些数的和等于s(题目输入),用到的数输出1,没有用到的数输出0 例如:3  4 2 3 4 输出:0 0 1 题解: 认真想一 ...

  3. 2020牛客暑期多校训练营 第二场 C Cover the Tree 构造 贪心

    LINK:Cover the Tree 最受挫的是这道题,以为很简单 当时什么都想不清楚. 先胡了一个树的直径乱搞的贪心 一直过不去.后来意识到这类似于最经典长链剖分优化贪心的做法 然后那个是求最大值 ...

  4. 2020牛客暑期多校训练营 第二场 B Boundary 计算几何 圆 已知三点求圆心

    LINK:Boundary 计算几何确实是弱项 因为好多东西都不太会求 没有到很精通的地步. 做法很多,先说官方题解 其实就是枚举一个点 P 然后可以发现 再枚举一个点 然后再判断有多少个点在圆上显然 ...

  5. 2020牛客暑期多校训练营 第二场 A All with Pairs 字符串hash KMP

    LINK:All with Pairs 那天下午打这个东西的时候状态极差 推这个东西都推了1个多小时 (比赛是中午考试的我很困 没睡觉直接开肝果然不爽 一开始看错匹配的位置了 以为是\(1-l\)和\ ...

  6. 2020牛客暑期多校训练营 第二场 K Keyboard Free 积分 期望 数学

    LINK:Keyboard Free 我要是会正经的做法 就有鬼了. 我的数学水平没那么高. 三个同心圆 三个动点 求围成三角形面积的期望. 不会告辞. 其实可以\(n^2\)枚举角度然后算出面积 近 ...

  7. 2020牛客暑期多校训练营 第二场 J Just Shuffle 置换 群论

    LINK:Just Shuffle 比较怂群论 因为没怎么学过 置换也是刚理解. 这道题是 已知一个置换\(A\)求一个置换P 两个置换的关键为\(P^k=A\) 且k是一个大质数. 做法是李指导教我 ...

  8. 2020牛客暑期多校训练营 第二场 I Interval 最大流 最小割 平面图对偶图转最短路

    LINK:Interval 赛时连题目都没看. 观察n的范围不大不小 而且建图明显 考虑跑最大流最小割. 图有点稠密dinic不太行. 一个常见的trick就是对偶图转最短路. 建图有点复杂 不过建完 ...

  9. 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题)

    layout: post title: 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题) author: "luowentaoaa" c ...

  10. 2019牛客暑期多校训练营(第二场)-E MAZE

    题目链接:https://ac.nowcoder.com/acm/contest/882/E 题意:n×m的矩阵,0表示可以走,1表示墙,不能通过.有q中操作,一种是改变坐标(x,y)的状态,一种是询 ...

随机推荐

  1. ansible-cmdb 解析(ansible all -m setup )收集过来的信息并以html方式显示。

    首先安装 ansible-cmdb 直接pip install ansible-cmdb 安装 然后执行收集信息命令 ansible all -m setup >/tmp/out/ 修改下ans ...

  2. 1635:【例 5】Strange Way to Express Integers

    #include<bits/stdc++.h> #define ll long long using namespace std; ll n,m,a,lcm,now; bool flag; ...

  3. HDU 1160 FatMouse's Speed ——(DP)

    又是那个lis变形的题目. 但是不好定义严格的比较符号,因此只能n^2去做.值得注意的一个是要先排序,因为可能可以先选后面的再选前面的,先排序的话就能够避免这个问题.但是要注意,因为要输出路径,所以要 ...

  4. storm滑动窗口

    Window滑动方式: 没有数据不滑动windowLength:窗口的时间长度/tuple个数slidingInterval:滑动的时间间隔/tuple个数 withWindow(Duration w ...

  5. python定时任务实现

    安装 pip install schedule 示例代码 import schedule import time def job(): print("I'm working..." ...

  6. asp.net core spa应用(angular) 部署同一网站下

    需求:现在一个应用是前后端开发分离,前端使用angular,后端使用 asp.net core 提供api ,开发完成后,现在需要把两个程序部署在同一个网站下,应该怎么处理? 首先可以参考微软的官方文 ...

  7. hystrix(一) 简单使用, 以及动态配置更新

    本文转载自https://my.oschina.net/u/1169457/blog/1787414 hystrix 简单使用, 以及动态配置更新 概述 只介绍同步模式下简单的使用, 有助于快速接入, ...

  8. impdp导入报错ORA-39070:无法打开日志文件

    >impdp test/123456@orcl directory=expnc_dir dumpfile=TEST.DMP full=y ORA-39002:操作无效 ORA39070:无法打开 ...

  9. mac 设置 MySQL 数据库默认编码(字符集)为 UTF-8

    mac 设置 MySQL 数据库默认编码(字符集)为 UTF-8   原文链接:https://juejin.im/post/5bbdca76e51d45021147de44 鉴于有些刚接触 MySQ ...

  10. 前端js保存页面为图片下载到本地

    前端js保存页面为图片下载到本地 手机端点击下载按钮将页面保存成图片到本地 前端js保存页面为图片下载到本地的坑 html2canvas 识别 svg 解决方案 方案 html2canvas.js:可 ...