传送门:QAQQAQ

题意:给一个01矩阵A,他的相反矩阵为B,每一次变换都会将原矩阵面积乘4成为:

AB

BA

矩阵的左上角固定,变换无限次,现有q个询问,即求一个矩阵内的1的个数。

思路:因为反转,所以A,B矩阵拼起来刚好是一个全都为1的矩阵,所以答案就是匹配的A,B矩阵总点数/2和右下角1的个数之和

注意点:

1.因为数据较大,要用前缀和思想

2.要开longlong

3.注意询问时各个变量的重置

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
 
int A[][],B[][],a[][],b[][];
int sa[][],sb[][];
ll n,m,q,t[];
void init()
{
t[]=;
for(int i=;i<=;i++) t[i]=t[i-]*;
memset(sa,,sizeof(sa));
memset(sb,,sizeof(sb));
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
sa[i][j]=sa[i-][j]+sa[i][j-]-sa[i-][j-]+A[i][j];
sb[i][j]=sb[i-][j]+sb[i][j-]-sb[i-][j-]+B[i][j];
}
}
}
 
 
int s=;
void judge(ll x)//even->A odd->B
{
for(int i=;i>=;i--)
{
if(t[i]<x) x-=t[i],s++;
}
}
 
ll solve(ll x,ll y)
{
s=;
ll ret=;
if(x==||y==) return ;
ret+=(x*y-(x%(*n))*(y%(*m)))/;//n,m写错
ll xx=x-x%(*n)+;
ll yy=y-y%(*m)+;
ll tx=(xx-)/n+;
ll ty=(yy-)/m+;
judge(tx); judge(ty);
ll dx=x-xx+,dy=y-yy+;
if(s%==)
{
if(dx<=n&&dy<=m) ret+=sb[dx][dy];
if(dx<=n&&dy>m) ret+=sa[dx][dy-m]+sb[dx][m];
if(dx>n&&dy<=m) ret+=sb[n][dy]+sa[dx-n][dy];
if(dx>n&&dy>m) ret+=sb[n][m]+sa[n][dy-m]+sa[dx-n][m]+sb[dx-n][dy-m];
}
else
{
if(dx<=n&&dy<=m) ret+=sa[dx][dy];
if(dx<=n&&dy>m) ret+=sb[dx][dy-m]+sa[dx][m];
if(dx>n&&dy<=m) ret+=sa[n][dy]+sb[dx-n][dy];
if(dx>n&&dy>m) ret+=sa[n][m]+sb[n][dy-m]+sb[dx-n][m]+sa[dx-n][dy-m];
}
return ret;
}
 
int main()
{
scanf("%lld%lld%lld",&n,&m,&q);
for(int i=;i<=n;i++)
{
char str[];
scanf("%s",str+);
for(int j=;j<=m;j++)
{
A[i][j]=str[j]-'';
B[i][j]=(str[j]-'')^;
}
}
init();
while(q--)
{
ll x1,y1,x2,y2;//开ll
scanf("%lld%lld%lld%lld",&x1,&y1,&x2,&y2);//s不在这里重置
ll ans=solve(x2,y2)-solve(x1-,y2)-solve(x2,y1-)+solve(x1-,y1-);
printf("%lld\n",ans);
}
}

codeforces 1186E- Vus the Cossack and a Field的更多相关文章

  1. E. Vus the Cossack and a Field (求一有规律矩形区域值) (有一结论待证)

    E. Vus the Cossack and a Field (求一有规律矩形区域值) 题意:给出一个原01矩阵,它按照以下规则拓展:向右和下拓展一个相同大小的 0 1 分别和原矩阵对应位置相反的矩阵 ...

  2. Codeforces F. Vus the Cossack and Numbers(贪心)

    题目描述: D. Vus the Cossack and Numbers Vus the Cossack has nn real numbers aiai. It is known that the ...

  3. 『Codeforces 1186E 』Vus the Cossack and a Field (性质+大力讨论)

    Description 给出一个$n\times m$的$01$矩阵$A$. 记矩阵$X$每一个元素取反以后的矩阵为$X'$,(每一个cell 都01倒置) 定义对$n \times m$的矩阵$A$ ...

  4. codeforces 1186C Vus the Cossack and Strings

    题目链接:https://codeforc.es/contest/1186/problem/C 题目大意:xxxxx(自认为讲不清.for instance) 例如:a="01100010& ...

  5. Codeforces 1186F - Vus the Cossack and a Graph 模拟乱搞/欧拉回路

    题意:给你一张无向图,要求对这张图进行删边操作,要求删边之后的图的总边数 >= ceil((n + m) / 2), 每个点的度数 >= ceil(deg[i] / 2).(deg[i]是 ...

  6. @codeforces - 1186F@ Vus the Cossack and a Graph

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 点 m 边的图(n, m<=10^6),记第 ...

  7. CodeForces - 1186 C. Vus the Cossack and Strings (异或)

    Vus the Cossack has two binary strings, that is, strings that consist only of "0" and &quo ...

  8. Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)

    C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...

  9. Codeforces Round #571 (Div. 2)-D. Vus the Cossack and Numbers

    Vus the Cossack has nn real numbers aiai. It is known that the sum of all numbers is equal to 00. He ...

随机推荐

  1. scrapy不抓取重复的网页解决办法

    1.scrapy爬虫遇到一个问题,有时候会对一个网页重复爬取提取不同的数据,这时候会发现,后面的那个重复爬取scrapy直接终止了. 原因: scrapy 的request逻辑里面  dont_fil ...

  2. 将sparkStreaming的结果保存到S3

    将spark解析的结果保存到S3 这个和保存到本地的区别在于,你需要配置aws的key和密码,以及它的region,代码如下 package com.alo7.spark import java.ut ...

  3. CF774L Bars

    题意:给你一个二进制表示是否可以吃巧克力.一共有k个巧克力,第一天和最后一天必须吃.最小化每两次吃巧克力的最大间隔? 标程: #include<bits/stdc++.h> using n ...

  4. 简单的 js手写轮播图

    html: <div class="na1">   <div class="pp">    <div class="na ...

  5. CSS——背景渐变

    在线性渐变过程中,颜色沿着一条直线过渡:从左侧到右侧.从右侧到左侧.从顶部到底部.从底部到顶部或着沿任何任意轴.如果你曾使用过制作图件,比如说Photoshop,你对线性渐变并不会陌生. 兼容性问题很 ...

  6. (转载)js引擎的执行过程(一)

    概述 js是一种非常灵活的语言,理解js引擎的执行过程对我们学习javascript非常重要,但是网上讲解js引擎的文章也大多是浅尝辄止或者只局部分析,例如只分析事件循环(Event Loop)或者变 ...

  7. day13 python-001 简介及循环、判断、复制等

    Python之路,Day1 = Python基础1 本节内容 1.Python历史简介以及安装.环境变量的配置: 2.Pycharm的简单设置: 3.变量的使用及定义: 4.获取键盘输入及打印: 5. ...

  8. thinkphp 跳转和重定向

    页面跳转 在应用开发中,经常会遇到一些带有提示信息的跳转页面,例如操作成功或者操作错误页面,并且自动跳转到另外一个目标页面.系统的\Think\Controller类内置了两个跳转方法success和 ...

  9. python相关软件安装流程图解——虚拟机安装——CentOS-7-x86_64-DVD-1810——CentOS-01下载——CentOS-02安装——CentOS-03配置操作

    http://www.xitongzhijia.net/soft/24315.html http://www.downxia.com/downinfo/4574.html     .

  10. Docker系列(三):Docker自定义容器镜像

    将容器编程镜像: docker commit [repo:tag] 网上有这句话:当我们在制作自己的镜像的时候,会在container中安装一些工具.修改配置,如果不做commit保存 起来,那么co ...