【HDU 5283】Senior's Fish
http://acm.hdu.edu.cn/showproblem.php?pid=5283
今天的互测题,又爆零了qwq
考虑每个点对答案的贡献。
对每个点能产生贡献的时间线上的左右端点整体二分。
最后扫一遍即可,\(O(n\log^2n)\)。
拍了好长时间,结果暴力标算都写错了,我不滚粗谁滚粗?
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 100003;
struct node {int op, l, r, d;} Q[N];
struct data {int x, y, lx, rx, ly, ry;} P[N];
int n, x1, y1, x2, y2, m, bits[N];
struct gagaga {int id, rest, ans;} B[N], A[N];
void add(int x, int num) {
for (; x <= n; x += (x & (-x)))
bits[x] += num;
}
int query(int x) {
int ret = 0; if (x < 0) return 0;
for (; x; x -= (x & (-x)))
ret += bits[x];
return ret;
}
void solve(int l, int r, int L, int R, int flag) {
if (L > R) return;
if (l == r) {
for (int i = L; i <= R; ++i)
B[i].ans = l;
return;
}
int mid = (l + r) >> 1;
for (int i = l; i <= mid; ++i)
if (Q[i].op == flag) {
add(Q[i].l, Q[i].d);
add(Q[i].r + 1, -Q[i].d);
}
int tmp1 = L, tmp2 = R, t;
for (int i = L; i <= R; ++i)
if ((t = query(B[i].id)) >= B[i].rest)
A[tmp1++] = B[i];
else {
B[i].rest -= t;
A[tmp2--] = B[i];
}
for (int i = L; i <= R; ++i) B[i] = A[i];
for (int i = l; i <= mid; ++i)
if (Q[i].op == flag) {
add(Q[i].l, -Q[i].d);
add(Q[i].r + 1, Q[i].d);
}
solve(l, mid, L, tmp2, flag);
solve(mid + 1, r, tmp1, R, flag);
}
void add_m(int x, int num) {
for (; x <= m + 1; x += (x & (-x)))
bits[x] += num;
}
struct hahaha {
int type, l, r, pos, delta;
bool operator < (const hahaha &A) const {
return pos == A.pos ? type < A.type : pos < A.pos;
}
} H[N << 2];
int main() {
int T; scanf("%d", &T);
while (T--) {
scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2);
for (int i = 1; i <= n; ++i) scanf("%d%d", &P[i].x, &P[i].y);
scanf("%d", &m);
for (int i = 1; i <= m; ++i) {
scanf("%d%d%d", &Q[i].op, &Q[i].l, &Q[i].r);
if (Q[i].op != 3) scanf("%d", &Q[i].d);
}
for (int i = 1; i <= n; ++i) B[i] = (gagaga) {i, x1 - P[i].x, 0};
solve(1, m + 1, 1, n, 1);
for (int i = 1; i <= n; ++i) P[B[i].id].lx = B[i].ans;
for (int i = 1; i <= n; ++i) B[i] = (gagaga) {i, x2 + 1 - P[i].x, m + 1};
solve(1, m + 1, 1, n, 1);
for (int i = 1; i <= n; ++i) P[B[i].id].rx = B[i].ans;
for (int i = 1; i <= n; ++i) B[i] = (gagaga) {i, y1 - P[i].y, 0};
solve(1, m + 1, 1, n, 2);
for (int i = 1; i <= n; ++i) P[B[i].id].ly = B[i].ans;
for (int i = 1; i <= n; ++i) B[i] = (gagaga) {i, y2 + 1 - P[i].y, m + 1};
solve(1, m + 1, 1, n, 2);
for (int i = 1; i <= n; ++i) P[B[i].id].ry = B[i].ans;
int cnt = 0;
for (int i = 1; i <= n; ++i) {
P[i].lx = max(P[i].lx, P[i].ly);
P[i].rx = min(P[i].rx, P[i].ry);
if (P[i].lx >= P[i].rx) continue;
H[++cnt] = (hahaha) {1, i, 0, P[i].lx, 1};
H[++cnt] = (hahaha) {1, i, 0, P[i].rx, -1};
}
for (int i = 1; i <= m; ++i)
if (Q[i].op == 3)
H[++cnt] = (hahaha) {2, Q[i].l, Q[i].r, i, 0};
stable_sort(H + 1, H + cnt + 1);
for (int i = 1; i <= cnt; ++i)
if (H[i].type == 1) add(H[i].l, H[i].delta);
else printf("%d\n", query(H[i].r) - query(H[i].l - 1));
}
return 0;
}
【HDU 5283】Senior's Fish的更多相关文章
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
- 【HDU 3068】 最长回文
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...
- 【HDU 4699】 Editor
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...
随机推荐
- 【Luogu】P3930 SAC E#1 - 一道大水题 Knight
[题目]洛谷10月月赛R1 提高组 [题意]给定n*n棋盘和<=16个棋子,给几个棋子种类和攻击范围,现我方只有一马,求能否吃王. [算法]状压+BFS [题解]16种棋子中,马不能吃马,直接处 ...
- 【BZOJ】1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
[算法]贪心&&堆 [题解]反过来看就是合并任意两块木板,花费为木板长度之和. 显然从最小的两块开始合并即可,用堆(优先队列)维护. 经典DP问题石子归并是只能合并相邻两堆石子,所以不 ...
- vsftp 服务的启动与问题
一般系统用户是可以直接登入的如果不可以可能是selinux的原因 执行一下: 更改selinux的配置文件将其设为disable,可我不想重启服务器,有以下解决办法:执行命令:setenforce 0 ...
- ES的优化布局
分词优化:IK Analyser Elastic Search 5.x官方提供的中文搜索并不友好,分词时经常将一句话分成很多单字,这时候可以使用IK Analyser插件进行优化,当然你在写java代 ...
- HDU 6183 Color it 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题意: 有四种操作: 0:清除所有点 1 x y c : 给点(x, y)添加一种颜色c(颜色不 ...
- Tensorflow项目实战一:MNIST手写数字识别
此模型中,输入是28*28*1的图片,经过两个卷积层(卷积+池化)层之后,尺寸变为7*7*64,将最后一个卷积层展成一个以为向量,然后接两个全连接层,第一个全连接层加一个dropout,最后一个全连接 ...
- python内建方法
abs all any apply basestring bin bool buffer bytearray bytes callable chr classmethod cmp coerce com ...
- 微信小程序宽高适配
小程序的宽任何机型都是750rpx,但是画布canvas的默认单位是px,可能会出现需要怪异的样式,我们可以用到 wx.getSystemInfoSync().windowWidth和 wx.getS ...
- java web 资源文件读取
前提:假设web应用test(工程名) webapps下面有一资源文件test.html 规则:在获取资源时一般使用的是相对路径,以符号/开头,而 / 代表什么取决于这个地址给谁使用.服务器使用时,/ ...
- redis之(十三)redis的三种启动方式
Part I. 直接启动 下载 官网下载 安装 tar zxvf redis-2.8.9.tar.gz cd redis-2.8.9 #直接make 编译 make #可使用root用户执行`make ...