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的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  8. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

  9. 【HDU 4699】 Editor

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...

随机推荐

  1. UIPageControl---iOS-Apple苹果官方文档翻译

    本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/Ch ...

  2. John's trip(POJ1041+欧拉回路+打印路径)

    题目链接:http://poj.org/problem?id=1041 题目: 题意:给你n条街道,m个路口,每次输入以0 0结束,给你的u v t分别表示路口u和v由t这条街道连接,要输出从起点出发 ...

  3. 01背包入门 dp

    题目引入: 有n个重量和价值分别为Wi,Vi的物品.从这些物品中挑选出总重量不超过W的物品,求所有挑选方案中的价值总和的最大值. 分析: 首先,我们用最普通的方法,针对每个物品是否放入背包进行搜索. ...

  4. querySelector()与querySelectorAll()

    1.querySelector() 参数:css选择器 返回匹配指定css选择器元素的第一个子元素 2.querySelectorAll() 参数:css选择器 返回匹配指定css选择器的所有元素

  5. https 多路复用的理解~转载

    https://segmentfault.com/q/1010000005167289 这里面的http/2连接是指tcp/ip层的连接还是http应用层(也就是我们平常在chrome F12 net ...

  6. 网络设备之pci_driver

    每个pci驱动都有一个pci_driver实例,用以描述驱动名称,支持的设备信息,以及对应的操作函数: /* 描述一个pci设备,每个pci驱动必须创建一个pci_driver实例 */ struct ...

  7. python多进程处理数据

    当我们处理大规模数据如ImageNet的时候,单进程显得很吃力耗时,且不能充分利用多核CPU计算机的资源.因此需要使用多进程对数据进行并行处理,然后将结果合并即可.以下给出的是多进程处理的demo代码 ...

  8. Python爬虫之百度API调用

    调用百度API获取经纬度信息. import requests import json address = input('请输入地点:') par = {'address': address, 'ke ...

  9. MAC 'readonly' option is set (add ! to override)错误解决

    该错误为当前用户没有权限对文件作修改 输入 :w !sudo tee %

  10. HDU-5272

    Dylans loves numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/O ...