【题目链接】

点击打开链接

【算法】

建C棵线段树即可,注意要用前缀和优化

【代码】

这是标程

#include <bits/stdc++.h>
using namespace std; const int MAXR = , MAXC = , MAXN = * MAXR + ; int R, C, Q;
int am0[MAXC][MAXR];
char grid[MAXR][MAXC]; bool mark[MAXN];
int am[MAXN][MAXC];
int change[MAXN][MAXC]; inline void split(int at, int l, int r)
{
mark[at] = false;
for (int i = ; i <= C; ++i)
if (change[at][i] < )
{
int got = am0[i][r] - am0[i][l];
if (change[at][i] == )
got = r - l - got;
am[at][i] = got;
}
if (l + != r)
{
mark[at * + ] = true;
mark[at * + ] = true;
for (int i = ; i <= C; ++i)
if (change[at][i] < )
{
change[at * + ][i] = change[at][i];
change[at * + ][i] = change[at][i];
change[at][i] = ;
}
}
} void update(int at, int l, int r, int nl, int nr, int cols[])
{
if (mark[at])
split(at, l, r);
if (l == nl && r == nr)
{
mark[at] = true;
for (int i = ; i <= C; ++i)
if (cols[i] < )
change[at][i] = cols[i];
split(at, l, r);
return;
}
int m = (l + r) / ;
if (nr <= m)
update(at * + , l, m, nl, nr, cols);
else if (m <= nl)
update(at * + , m, r, nl, nr, cols);
else
{
update(at * + , l, m, nl, m, cols);
update(at * + , m, r, m, nr, cols);
}
if (mark[at * + ])
split(at * + , l, m);
if (mark[at * + ])
split(at * + , m, r);
for (int i = ; i <= C; ++i) // join
am[at][i] = am[at * + ][i] + am[at * + ][i];
} void read()
{
scanf("%d %d %d", &R, &C, &Q);
for (int i = ; i < R; ++i)
scanf("%s", grid[i]);
} void solve()
{
for (int i = ; i <= C; ++i)
for (int j = ; j <= R; ++j)
{
am0[i][j] = am0[i][j - ];
if (grid[j - ][i - ] == '')
++am0[i][j];
}
int cols[MAXC];
for (int i = ; i < MAXC; ++i)
cols[i] = ;
update(, , R, , R, cols);
int r1, r2, c1, c2, x;
if (mark[])
split(, , R);
for (int i = ; i < Q; ++i)
{
scanf("%d %d %d %d %d", &r1, &r2, &c1, &c2, &x);
for (int j = ; j <= C; ++j)
if (j >= c1 && j <= c2)
cols[j] = x;
else
cols[j] = ;
update(, , R, r1 - , r2, cols);
if (mark[])
split(, , R);
int ans = ;
for (int i = ; i <= C; ++i)
ans += am[][i];
printf("%d\n", ans);
}
} int main()
{
read();
solve();
return ;
}

这是我的程序

#include<bits/stdc++.h>
using namespace std;
#define MAXR 50000
#define MAXC 15
#define MAXQ 1000 struct SegmentTree {
int l,r,opt,sum;
} tree[MAXC+][MAXR*+]; int i,j,R,C,Q,R1,R2,C1,C2,X,ans;
char ch;
int mat[MAXR+][MAXC+],sum[MAXR+][MAXC+]; template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = x * + c - '';
x *= f;
} template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
} template <typename T> inline void writeln(T x) {
write(x);
puts("");
} inline void build(int pos,int index,int l,int r) {
int mid;
tree[pos][index].l = l; tree[pos][index].r = r;
tree[pos][index].sum = r - l + - sum[r][pos] + sum[l-][pos];
tree[pos][index].opt = ;
if (l == r) return;
mid = (l + r) >> ;
build(pos,index*,l,mid); build(pos,index*+,mid+,r);
} inline void pushdown(int pos,int index) {
int l = tree[pos][index].l,
r = tree[pos][index].r;
if (l == r) return;
tree[pos][index*].opt = tree[pos][index].opt;
tree[pos][index*+].opt = tree[pos][index].opt;
l = tree[pos][index*].l,
r = tree[pos][index*].r;
if (!tree[pos][index].opt) tree[pos][index*].sum = r - l + - sum[r][pos] + sum[l-][pos];
else tree[pos][index*].sum = sum[r][pos] - sum[l-][pos];
l = tree[pos][index*+].l,
r = tree[pos][index*+].r;
if (!tree[pos][index].opt) tree[pos][index*+].sum = r - l + - sum[r][pos] + sum[l-][pos];
else tree[pos][index*+].sum = sum[r][pos] - sum[l-][pos];
} inline void pushup(int pos,int index) {
tree[pos][index].sum = tree[pos][index*].sum + tree[pos][index*+].sum;
if ((tree[pos][index*].opt == -) || (tree[pos][index*+].opt == -)) {
tree[pos][index].opt = -;
return;
}
if (tree[pos][index*].opt != tree[pos][index*+].opt) {
tree[pos][index].opt = -;
return;
}
tree[pos][index].opt = tree[pos][index*].opt;
} inline void modify(int pos,int index,int l,int r,int val) {
int mid;
if (tree[pos][index].opt != -) pushdown(pos,index);
if ((tree[pos][index].l == l) && (tree[pos][index].r == r)) {
tree[pos][index].opt = val;
if (!val) tree[pos][index].sum = r - l + - sum[r][pos] + sum[l-][pos];
else tree[pos][index].sum = sum[r][pos] - sum[l-][pos];
} else {
mid = (tree[pos][index].l + tree[pos][index].r) >> ;
if (mid >= r) modify(pos,index*,l,r,val);
else if (mid + <= l) modify(pos,index*+,l,r,val);
else {
modify(pos,index*,l,mid,val);
modify(pos,index*+,mid+,r,val);
}
pushup(pos,index);
}
} int main() { read(R); read(C); read(Q);
for (i = ; i <= R; i++) {
for (j = ; j <= C; j++) {
ch = getchar();
mat[i][j] = ch - '';
}
getchar();
} for (i = ; i <= C; i++) {
for (j = ; j <= R; j++) {
sum[j][i] = sum[j-][i] + mat[j][i];
}
} for (i = ; i <= C; i++) build(i,,,R); while (Q--) {
ans = ;
read(R1); read(R2); read(C1); read(C2); read(X);
for (i = C1; i <= C2; i++) modify(i,,R1,R2,X);
for (i = ; i <= C; i++) ans += tree[i][].sum;
writeln(ans);
} return ; }

【扬中集训 DAY4T3】holiday的更多相关文章

  1. 【扬中集训DAY2T2】 机智的AmyZhi

    [题目链接] 点击打开链接 [算法] 据说标算是暴力? 从N-200开始搜 不过我用了搜索+一些奇怪的剪枝,也A了.... [代码] 标程 #include<bits/stdc++.h> ...

  2. 【扬中集训 DAY4T1】跳马

    [题目链接] 点击打开链接 [算法] 数据范围很大,显然暴力是不能通过的 我们可以先打表,发现答案为 : 41 109 205 325 473 649 853 1085 1345 观察数列的差 68 ...

  3. 【扬中集训DAY1T1】 微信群

    [题目链接] 点击打开链接 [算法] 对问题稍加分析后,发现其实要求的就是 : C(N,K) + C(N,K+1) + C(N,K+2) + ... + C(N,N) 因为N最大10^9,K最大10^ ...

  4. 【扬中集训Day6T1】 白日梦

    [题目描述] 白日梦 (daydream.c/cpp/pas) 时间限制: 1 s  空间限制: 256 MB 题目描述 SR需要相当大的睡眠量 某日,他做了一个奇怪的梦,他梦见自己成为了怪物猎人,为 ...

  5. 【扬中集训DAY5T1】 交换矩阵

    [题目链接] 点击打开链接 [算法] 链表,对于每个点,存它的上,下,左,右分别是谁 [代码] #include<bits/stdc++.h> using namespace std; # ...

  6. [暑假集训Day4T3]曲线

    三分模板. 三分法求单峰函数最优值,之后每次取所有二次函数最优值即可 #pragma GCC optimize(3,"Ofast","inline") #inc ...

  7. 中南大学2019年ACM寒假集训前期训练题集(基础题)

    先写一部分,持续到更新完. A: 寒衣调 Description 男从戎,女守家.一夜,狼烟四起,男战死沙场.从此一道黄泉,两地离别.最后,女终于在等待中老去逝去.逝去的最后是换尽一生等到的相逢和团圆 ...

  8. QDEZ集训笔记【更新中】

    这是一个绝妙的比喻,如果青岛二中的台阶上每级站一只平度一中的猫,差不多站满了吧 自己的理解 [2016-12-31] [主席树] http://www.cnblogs.com/candy99/p/61 ...

  9. 【UOJ #29】【IOI 2014】holiday

    http://uoj.ac/problem/29 cdq四次处理出一直向左, 一直向右, 向左后回到起点, 向右后回到起点的dp数组,最后统计答案. 举例:\(fi\)表示一直向右走i天能参观的最多景 ...

随机推荐

  1. Windows下,RabbitMQ安装、卸载以及遇到的坑

    RabbitMQ是目前比较使用比较广泛的一个队列服务器,但是很多朋友在使用过程中,也遇到一些问题,这篇文章主要是做一个总结吧 本篇文章,虽然标题命名为“安装与卸载”,但是网上有很多类似的文章,我就简单 ...

  2. CODEVS_2800 送外卖 状态压缩+动态规划

    原题链接:http://codevs.cn/problem/2800/ 题目描述 Description 有一个送外卖的,他手上有n份订单,他要把n份东西,分别送达n个不同的客户的手上.n个不同的客户 ...

  3. 洛谷 P3865 【模板】ST表

    P3865 [模板]ST表 题目背景 这是一道ST表经典题——静态区间最大值 请注意最大数据时限只有0.8s,数据强度不低,请务必保证你的每次查询复杂度为 O(1)O(1) 题目描述 给定一个长度为  ...

  4. NBUT 1457 Sona (莫队算法)

    题目大意: 求一段区间内 出现的数字的次数的三次方的和 思路分析: 这要水过去的题目真是难,各种优化. 不能用map , 要离散化之后 先处理lowerbound. 优化输入. . . 时间卡的非常紧 ...

  5. SQL ORDER BY 关键字

    SQL ORDER BY 关键字 ORDER BY 关键字用于对结果集进行排序. SQL ORDER BY 关键字 ORDER BY 关键字用于对结果集按照一个列或者多个列进行排序. ORDER BY ...

  6. electron 开发拆坑总结

    electron 总结 前言 有一个web项目需要用客户端来包装一下 项目的主要业务都在服务器上 所以项目的大多数功能都用url 地址来访问: 客户端登陆界面在本地 打包客户端的本地登陆界面 做为登陆 ...

  7. UUID GUID

    http://baike.baidu.com/link?url=xkck9gR5bzOx0oBKP1qNJwGGq3IO56V4i8cg9zTSpSDMVBMA0F7jr0AdkQTGyk7F0FGj ...

  8. Intel CPU Microarchitecture

    http://en.wikipedia.org/wiki/Intel_Tick_Tock Atom Roadmap[16]   Fabrication process Microarchitectur ...

  9. Mac版的idea部分按钮失效的解决方案

    问题描述:调整了一下idea中jdk的路径,之后idea就无法打开新项目了,最好发现idea中的顶部菜单全部失效 解决过程: 1.把idea的jdk的路径调回去,无效 2.重启idea,无效 3.重启 ...

  10. 记一次OGG数据写入HBase的丢失数据原因分析

    一.现象二.原因排查2.1 SparkStreaming程序排查2.2 Kafka数据验证2.3 查看OGG源码2.3.1 生成Kafka消息类2.3.2 Kafka配置类2.3.3 Kafka 消息 ...