题意: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. Foundation-常用结构体

    复习 void test(){ struct Date{ int year; int month; int day; }; struct Date d={2015,5,14}; d.day=6; } ...

  2. Ubuntu14.04 gzip failed file too large

    使用gzip解压一个oracle rman备份集时报错:File too large.gizp -d cosp_db_full.tar.gzgzip: cosp_db_full.tar:File to ...

  3. Java中的集合Collection

    集合是什么? Java集合类存放于 java.util 包中,是一个用来存放对象的容器. 注意:①.集合只能存放对象.比如你存一个 int 型数据 1放入集合中,其实它是自动转换成 Integer 类 ...

  4. k8s Ipvs 内部网络自动分配和内部网络一致ip地址,导致ip冲突

    [链接]Linux负载均衡--LVS(IPVS)https://www.jianshu.com/p/36880b085265 [链接]kube-proxyipvsmodecreateunnecessa ...

  5. Node.js与VUE安装及环境配置之Windows篇

    Node.js安装及环境配置之Windows篇 https://www.cnblogs.com/zhouyu2017/p/6485265.html Node.js安装及环境配置之Windows篇htt ...

  6. 如何使用git cherry-pick将同一个仓库的某个分支的某些commit合并到当前分支?

    答: git cherry-pick <another-branch's commit-id>

  7. openpose关节图

  8. (翻译) Poor misunderstood 'var'

    It seems most programmers coming to JavaScript from C, C++, Java, and the like equate the var statem ...

  9. Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test

    解决方法: 打包跳过测试有两种方法 一是命令行 mvn clean package -Dmaven.test.skip=true 二是写入pom文件 <plugin> <groupI ...

  10. 修改ssh端口

    centos7.5修改默认SSH端口 linux SSH默认端口是22,不修改的话存在一定的风险,要么是被人恶意扫描,要么会被人破解或者攻击,所以我们需要修改默认的SSH端口 1.修改22端口为620 ...