线段树水题,考虑到只有15列,所以我们对于每一列,我们都去维护一个线段树。

现在来考虑一下修改操作,因为每次修改的时候,我们都是将黑的改成白的,白的改成黑的,所以我们对线段树的每个节点维护当前这段区间和原来颜色相同的点的个数,所以每次改成白色我们只需要找原来是白色的总数,或者黑色,所以就特别简单了。

下面是代码。

//author Eterna
#define Hello the_cruel_world!
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#include<complex>
#include<numeric>
#include<unordered_map>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define Pi acos(-1.0)
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))
#define pb(x) push_back(x)
#define lowbit(x) (x & -x)
#define FRIN freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\in.txt", "r", stdin)
#define FROUT freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\out.txt", "w", stdout)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define outd(x) printf("%d\n", x)
#define outld(x) printf("%lld\n", x)
#define il inline
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 5e4;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
inline int read_int() {
char c;
int ret = 0, sgn = 1;
do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
if (c == '-') sgn = -1; else ret = c - '0';
while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
return sgn * ret;
}
inline ll read_ll() {
char c;
ll ret = 0, sgn = 1;
do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
if (c == '-') sgn = -1; else ret = c - '0';
while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
return sgn * ret;
}
int white[16][maxn + 5], black[16][maxn + 5];
int arr[16][4 * maxn + 5], lazy[16][4 * maxn + 5];
char s[20];
il void Push_Up(int id, int index) {
arr[id][index] = arr[id][2 * index] + arr[id][2 * index + 1];
}
il void Change(int id, int index, int L, int R, int color) {
if (color) {
int sum = black[id][R] - black[id][L - 1];
arr[id][index] = sum;
}
else {
int sum = white[id][R] - white[id][L - 1];
arr[id][index] = sum;
}
}
il void Push_Down(int id, int index, int L, int R) {
int mid = L + R >> 1;
Change(id, 2 * index, L, mid, lazy[id][index]);
Change(id, 2 * index + 1, mid + 1, R, lazy[id][index]);
lazy[id][2 * index] = lazy[id][2 * index + 1] = lazy[id][index];
lazy[id][index] = -1;
}
void Build(int id, int index, int L, int R) {
lazy[id][index] = -1;
if (L == R) {
arr[id][index] = white[id][L];
return;
}
int mid = L + R >> 1;
Build(id, 2 * index, L, mid);
Build(id, 2 * index + 1, mid + 1, R);
Push_Up(id, index);
}
void Update(int id, int index, int L, int R, int UL, int UR, int c) {
if (L >= UL && R <= UR) {
Change(id, index, L, R, c);
lazy[id][index] = c;
return;
}
if (lazy[id][index] != -1)Push_Down(id, index, L, R);
int mid = L + R >> 1;
if (mid >= UL)Update(id, 2 * index, L, mid, UL, UR, c);
if (UR > mid) Update(id, 2 * index + 1, mid + 1, R, UL, UR, c);
Push_Up(id, index);
}
il int Query(int m) {
int res = 0;
for (int i = 1; i <= m; ++i)res += arr[i][1];
return res;
}
int n, m, r1, r2, c1, c2, q, c, cnt;
int main()
{
n = read_int(), m = read_int(), q = read_int();
for (int i = 1; i <= n; ++i) {
scanf("%s", s + 1);
for (int j = 1; j <= m; ++j) {
if (s[j] == '1') black[j][i] = 1;
else white[j][i] = 1, ++cnt;
}
}
for (int i = 1; i <= m; ++i)Build(i, 1, 1, n);
for (int i = 1; i <= m; ++i)
for (int j = 1; j <= n; ++j) {
white[i][j] += white[i][j - 1];
black[i][j] += black[i][j - 1];
}
while (q--) {
r1 = read_int(), r2 = read_int(), c1 = read_int(), c2 = read_int(), c = read_int();
for (int i = c1; i <= c2; ++i)Update(i, 1, 1, n, r1, r2, c);
outd(Query(m));
}
//system("pause");
return 0;
}

  

P2930 [USACO09HOL]假期绘画Holiday Painting的更多相关文章

  1. [USACO09HOL]假期绘画Holiday Painting

    观察到列数只有15,可以想到对于每一列维护一颗线段树 sum表示该区间与目标矩阵中该区间相同元素个数 lazy表示该区间应被修改成什么颜色 g即目标矩阵中该区间白色格子的个数 显然一个区间的sum=区 ...

  2. [bzoj1582][Usaco2009 Hol]Holiday Painting 节日画画_线段树

    Holiday Painting 节日画画 bzoj-1582 Usaco-2009 Hol 题目大意:给定两个n*m的01网格图.q次操作,每次将第二个网格图的子矩阵全部变成0或1,问每一次操作后两 ...

  3. [BZOJ1582] [Usaco2009 Hol]Holiday Painting 节日画画(线段树)

    传送门 线段树区间修改傻题 #include <cstdio> #include <cstring> #include <iostream> #define N 5 ...

  4. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  5. 关于图片的PNG与JPG、JIF格式

    一:GIF(Graphics Interchange Format) 简介 GIF图形交换格式是一种位图图形文件格式,以8位色(即256种颜色)重现真彩色的图像. 它实际上是一种压缩文档,采用LZW压 ...

  6. 前端进阶试题css(来自js高级前端开发---豪情)既然被发现了HOHO,那我就置顶了嘿嘿!觉得自己技术OK的可以把这套题目做完哦,然后加入高级前端的社区咯

    http://www.cnblogs.com/jikey/p/4426105.html js高级前端开发加群方法(此群很难进,里面纯技术,严禁广告,水群) 完整题目做完发邮箱(jikeytang@16 ...

  7. web前端图片极限优化策略

    随着web的发展,网站资源的流量也变得越来越大.据统计,60%的网站流量均来自网站图片,可见对图片合理优化可以大幅影响网站流量,减小带宽消耗和服务器压力. 一.现有web图片格式 我们先来看下现在常用 ...

  8. GIF/PNG/JPG和WEBP/base64/apng图片优点和缺点整理

    GIF/PNG/JPG/WEBP/APNG都是属于位图(位图 ,务必区别于矢量图): GIF/PNG和JPG这三种格式的图片被广泛应用在现今的互联网中,gif曾在过去互联网初期慢速的情况下几乎是做到了 ...

  9. cg tut

    Gesture Drawing with Alex Woo Gesture Drawing with Alex Woo and Louis Gonzales http://eisneim.com/?p ...

随机推荐

  1. 所有不同的序列串-----LCS算法的变种

    今天遇到LEETCODE的第115题: Distinct Subsequences Given a string S and a string T, count the number of disti ...

  2. MySQL 必知必会学习笔记(常用命令二)

    CREATE TABLE students(student_id INT UNSIGNED, name VARCHAR(30), sex CHAR(1), birth DATE, PRIMARY KE ...

  3. windows下启动和运行分布式消息中间件消息队列 kafka

    本文转载至:https://www.cnblogs.com/flower1990/p/7466882.html 一.安装JAVA JDK 1.下载安装包 http://www.oracle.com/t ...

  4. python中的内置函数getattr()介绍及示例

    在python的官方文档中:getattr()的解释如下: ? 1 2 3 getattr(object, name[, default])   Return the value of the nam ...

  5. SVN分支与合并【超详细的图文教程】(转载)

    SVN分支与合并 一. 分支与合并的概念 二. SVN分支的意义 三. 如何创建分支与合并分支 一.分支与合并的概念: 分支:版本控制系统的一个特性是能够把各种修改分离出来放在开发品的一个分割线上.这 ...

  6. Java泛型之自限定类型

    在<Java编程思想>中关于泛型的讲解中,提到了自限定类型: class SelfBounded<T extends SelfBounded<T>> 作者说道: 这 ...

  7. 常用的字符串函数-S

    header('content-type:text/html;charset=utf-f'); /* $var=addslashes($_GET['username']);//转义表单提交内容中的引号 ...

  8. topological sort

    A topological sortof a dag G  is a linear ordering of all its vertices such that if G contains anedg ...

  9. python--sort()和sorted()高级排序

    1.list中的sort()方法: def sort(self, key=None, reverse=False): # real signature unknown; restored from _ ...

  10. Linux下忘记MySQL密码的解决方法和输入mysqld_safe --skip-grant-tables &后无法进入MySQL的解决方法

    在Linux下忘记MySQL密码后我们可以通过一个mysql的参数--skip-grant-tables &轻松解决这个问题 亲测在CentOS有效 其中 --skip-grant-table ...