牛客暑假多校第二场J-farm
一、题意
White Cloud wants to help White Rabbit fertilize plants, but the i-th plant can only adapt to the i-th fertilizer. If the j-th fertilizer is applied to the i-th plant (i!=j), the plant will immediately die.
Now White Cloud plans to apply fertilizers T times. In the i-th plan, White Cloud will use k[i]-th fertilizer to fertilize all the plants in a rectangle [x1[i]...x2[i]][y1[i]...y2[i]].
White rabbits wants to know how many plants would eventually die if they were to be fertilized according to the expected schedule of White Cloud.
二、解题思路
要求使用一种数据结构进行批量染色操作,且要求后面可以检测是否被"其他颜色污染"。
则看了题解很容易想到,使用某种数据结构做批量增加的操作,之后检测增加后的值是否能够整除原来的元素。
考虑如果直接按照1、2、3、4进行赋值就会有:同样是染色2次,有3+3 = 6和2+2+2 = 6,无法有效判断整除。考虑加一个操作:增加染色次数的判定,但是同样也会有3+3 = 6 = 2+4的问题,因此对数组进行重新设计,则直觉告诉我们,1,2,4,7,......an,an+n这个数列可以完美解决这个问题——不存在第2种组合可以使用相同数目的数列元素相加得到数列的某个其他元素。
因此,使用一位数组开足够大的数组之后,动态的按照二维数组的方式进行寻址,即可完成上述操作。
#include<bits/stdc++.h>
using namespace std; #define ll intmax_t const int MAXN=; ll mapp[MAXN];
ll farm[MAXN];
ll times[MAXN];
ll color[MAXN]; int maxx_numebr = ;
int add_number = ; int m,n,k; void insert_mex(ll *v,int a,int b,ll key)
{
a+=;
b+=;
while(a<n+)
{
int num = a*(m+);
int pos = b;
while(pos<m+)
{
v[num+pos] += key;
pos+= pos&(-pos);
}a+=a&(-a); }
}
ll find_mex(ll *v,int a,int b)
{
a+=;
b+=;
ll cntt = ;
while(a)
{
int num = a*(m+);
int pos = b;
while(pos)
{
cntt += v[num+pos];
pos -= pos&(-pos);
}
a-=a&(-a);
}
return cntt;
} void insert(ll *v,int a,int b,int c,int d,ll key)
{
// cout<<"coor :"<<a<<" "<<b<<endl;
// cout<<"coor :"<<a<<" "<<d<<endl;
// cout<<"coor :"<<c<<" "<<b<<endl;
// cout<<"coor :"<<c<<" "<<d<<endl; insert_mex(v,a,b,key);
insert_mex(v,c,d,key);
insert_mex(v,a,d,-key);
insert_mex(v,c,b,-key);
} ll find(ll *v,int a,int b)
{
ll cntt = ;
cntt += find_mex(v,a,b);
return cntt;
} void init()
{
memset(color,-,sizeof(color));
for(int i=;i<n;++i)
{
int pos = i*m;
for(int j=;j<m;++j)
{
// int ppos = pos +j;
scanf("%d",&mapp[pos]);
if(color[pos] == -)color[mapp[pos]] = (maxx_numebr += (add_number++));
pos++;
}
}
for(int i=;i<k;++i)
{
int a,b,c,d,kk;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&kk);
if(color[kk] == -)color[kk] = (maxx_numebr += add_number++ );
ll key = color[kk];
a--;b--;
insert(farm,a,b,c,d,key);
insert(times,a,b,c,d,);
}
int cntt = n*m;
int pos = ;
for(int i=;i<n;++i)
{
for(int j=;j<m;++j)
{
// int pos = i*(m+23)+j;
ll kk = color[mapp[pos]];
int time_now = find(times,i,j);
ll res = find(farm,i,j);
// cout<<"check: "<<i<<" "<<j<<" times: "<<time_now<<" color "<<mapp[pos]<<endl;
if(time_now == || res == time_now*kk)cntt--;
pos++;
}
}
cout<<cntt<<endl; } int main()
{
cin>>n>>m>>k;
init(); return ;
}
牛客暑假多校第二场J-farm的更多相关文章
- 牛客暑假多校第二场 F trade
题意: 白兔有n个仓库,每个仓库有啊ai个货物,在每个仓库白兔可以装上任意数量的货物,也可以卸下任意数量的货物,现在有k个圆形信号阻隔器,然后有m个顾客下个一个订单,每个顾客的收货量有一个上限, 在每 ...
- 牛客暑假多校第二场 K carpet
题意:给你一个n*m的矩阵 ,每个位置都有一个字符并且都有一个值,现在需要找到一个p*q的子矩阵, 原来的矩阵可以由现在这个矩阵无限复制然后截取其中的一部分得到,并且要求 子矩阵里最大的值 * (p+ ...
- 牛客暑假多校第一场 J Different Integers
题意:给你一个数组, q次询问, 每次询问都会有1个[l, r] 求 区间[1,l] 和 [r, n] 中 数字的种类是多少. 解法1, 莫队暴力: 代码: #include<bits/stdc ...
- 2019 牛客暑期多校 第二场 H Second Large Rectangle (单调栈)
题目:https://ac.nowcoder.com/acm/contest/882/H 题意:一个大的01矩阵,然后现在要求第二大的全一矩阵是多少 思路:在这里我们首先学习一下另一个东西,怎么求直方 ...
- 2019牛客暑期多校第二场题解FH
F.Partition problem 传送门 题意:有2n个人,分两组,每组n个,要求sum(vij)最大值. 题解:n并不大我们可以枚举每个人是在1组还是2组爆搜. 代码: #include &l ...
- 牛客暑假多校第一场J-Different Integers
一.题目描述: 链接:https://www.nowcoder.com/acm/contest/139/JGiven a sequence of integers a1, a2, ..., an an ...
- 2021牛客暑期多校训练营3 J 思维
传送门 J-Counting Triangles_2021牛客暑期多校训练营3 (nowcoder.com) 题目 Goodeat finds an undirected complete graph ...
- 2019牛客暑假多校赛(第二场) F和H(单调栈)
F-Partition problem https://ac.nowcoder.com/acm/contest/882/F 题意:输入一个数n,代表总共有2n个人,然后每个人对所有人有个贡献值,然后问 ...
- 牛客网暑期ACM多校训练营(第二场)J farm (二维树状数组)
题目链接: https://www.nowcoder.com/acm/contest/140/J 思路: 都写在代码注释里了,非常好懂.. for_each函数可以去看一下,遍历起vector数组比较 ...
随机推荐
- textarea存起来的数据把空格也存起来
textarea的属性wrap="hard"可以把换行的内容也存起来. <html> <head> <title>这是一个小测试</tit ...
- Android TextView之空格占位法
在Android布局中进行使用到空格,为了实现文字的对齐.具体要怎么使用了? •请忽视文中‘& #160’中&和#之间的空格 空格: & #160; 窄空格: & #8 ...
- 《ArcGIS Runtime SDK for Android开发笔记》——(9)、空间数据的容器-地图MapView
1.前言 在上一篇内容里介绍了 关于ArcGIS Android开发的未来(“Quartz”版Beta)相关内容,期间也提到了关于API接口的重构,开发思路的调整,根据2015UC资料也可以知道新版预 ...
- Android - 常见的控件布局,左中右,左右等
这里汇总的是自己在工作过程中,使用过的常见空间布局,记录在这里.详情如下: 1. 三个控件,分别处于左,中,右 要点:使用RelativeLayout <RelativeLayout andro ...
- HUE安装与使用
HUE安装与使用 1.介绍 HUE是一个开源的Apache Hadoop UI系统,早期由Cloudera开发,后来贡献给开源社区.它是基于Python Web框架Django实现的.通过使用Hue我 ...
- 如何通过C#实现网页信息采集的方法总结
Internet上有着极其庞大的资源信息,各行各业的信息无所不有.网页的信息搜集就是获取网页的数据,然后通过程序分析,将有用的数据提取分离出来.搜索引擎工作的一部分就是网页数据抽取.比如编制程序抽取新 ...
- c++中explicit关键字用法
C++ explicit关键字用来修饰类的构造函数,表明该构造函数是显式的,既然有"显式"那么必然就有"隐式",那么什么是显示而什么又是隐式的呢? 如果c++类 ...
- 【CCPC-Wannafly Winter Camp Day3 (Div1) I】石头剪刀布(按秩合并并查集)
点此看题面 大致题意: 有\(n\)个人,第\(i\)个人坐在编号为\(i\)的座位上,每个人等概率有石头.剪刀.布中的一张卡片.有两种操作:第一种是第\(y\)个人挑战第\(x\)个人,如果胜利则\ ...
- 虚方法(virsual method)
虚方法(virsual method)挺起来玄乎其玄,向从未听说过这个概念的人解释清楚是一件相当困难的事情. 因为这是一个很不容易理解的概念,但它在比较抽象的代码里边是不可少的. 那么既然用枯燥的文字 ...
- Linux 关于动态链接库以及静态链接库的一些概念
库有动态与静态两种,动态通常用.so为后缀,静态用.a为后缀.例如:libhello.so libhello.a 为了在同一系统中使用不同版本的库,可以在库文件名后加上版本号为后缀,例如: libhe ...