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. 【BZOJ3884】上帝与集合的正确用法 [欧拉定理]

    上帝与集合的正确用法 Time Limit: 5 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description Input 第一行一个T ...

  2. 【51NOD】1096 距离之和最小

    [算法]数学 [题解] 其实就是求中位数,奇数个点就是最中间的点,偶数个点就是最中间两个点和它们之间的区域皆可(所以偶数不必取到两点正中央,取两点任意一点即可). 我们可以想象现在x轴上有n个点,我们 ...

  3. 【bug】vue-cli 3.0报错的解决办法

    先上bug图片 bug说明:初装vue_cli3.0写了个组件,运行错误,显示如图, 代码提示:[Vue warn]: You are using the runtime-only build of ...

  4. 子div设置margin-top使得父div也跟着向下移动

    之前在写网页的时候,发现一个小问题,就是子div设置margin-top的时候,父的div也会跟着向下移动.我用代码和图描述一下问题: <span style="font-size:1 ...

  5. TensorFlow两种方式计算Cross Entropy

    sparse_softmax_cross_entropy_with_logits与softmax_cross_entropy_with_logits import tensorflow as tf y ...

  6. 刷新SqlServer数据库中所有的视图

    ALTER PROCEDURE sp_refallview AS --刷新所有视图 DECLARE @ViewName VARCHAR(MAX); DECLARE @i INT; ; DECLARE ...

  7. 用Python写个自动ssh登录远程服务器的小工具

    很多时候我们喜欢在自己电脑的终端直接ssh连接Linux服务器,而不喜欢使用那些有UI界面的工具区连接我们的服务器.可是在终端使用ssh我们每次都需要输入账号和密码,这也是一个烦恼,所以我们可以简单的 ...

  8. MD5加密学习

    MD5(Message Digest --消息摘要算法)算法是一种散列(hash)算法(摘要算法,指纹算法),不是一种加密算法(易错),任何长度的任意内容都可以用MD5计算出散列值.主要作用是[验明“ ...

  9. FineReport——函数

    1.VALUE(tableData,col,row)返回tableData中列号为col的值, 行号为row.备注:先从报表数据集中查找,然后再从服务器数据集中查找,返回的是tableData的行数. ...

  10. python库-urllib

    urllib库提供了一系列操作url的功能,是python处理爬虫的入门级工具,网上的学习资料也很多.我做爬虫是一开始就用了Scrapy框架,并不是一步步从urllib开始的,反而是在后来解决一些小问 ...