bzoj 4822: [Cqoi2017]老C的任务
4822: [Cqoi2017]老C的任务
练手速...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e6+5;
inline int read() {
char c=getchar(); int x=0,f=1;
while(c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}
while(c>='0' && c<='9') {x=x*10+c-'0'; c=getchar();}
return x*f;
}
int n, Q, mp[N], tot, x1, y1, x2, y2; ll ans[N];
struct meow {
int x, y, type, qid; ll v;
bool operator <(const meow &a) const {return x == a.x ? type < a.type : x < a.x;}
} q[N];
namespace bit {
int n; ll c[N];
inline void add(int p, ll v) {for(; p<=n; p+=p&-p) c[p] += v;}
inline ll sum(int p) {ll ans = 0; for(; p; p-=p&-p) ans += c[p]; return ans;}
}
int main() {
freopen("in", "r", stdin);
n = read(); Q = read();
for(int i=1; i<=n; i++)
mp[++mp[0]] = q[i].x = read(), mp[++mp[0]] = q[i].y = read(), q[i].v = read(), q[i].type = 0;
tot = n;
for(int i=1; i<=Q; i++) {
mp[++mp[0]] = x1 = read()-1; mp[++mp[0]] = y1 = read()-1;
mp[++mp[0]] = x2 = read(); mp[++mp[0]] = y2 = read();
tot++; q[tot] = (meow){x1, y1, 1, i, 1LL};
tot++; q[tot] = (meow){x2, y2, 1, i, 1LL};
tot++; q[tot] = (meow){x2, y1, 1, i, -1LL};
tot++; q[tot] = (meow){x1, y2, 1, i, -1LL};
}
sort(mp+1, mp+1+mp[0]); mp[0] = unique(mp+1, mp+1+mp[0]) - mp - 1;
for(int i=1; i<=tot; i++) {
q[i].x = lower_bound(mp+1, mp+1+mp[0], q[i].x) - mp;
q[i].y = lower_bound(mp+1, mp+1+mp[0], q[i].y) - mp;
}
sort(q+1, q+1+tot);
bit::n = mp[0];
for(int i=1; i<=tot; i++) {
if(q[i].type) ans[q[i].qid] += q[i].v * bit::sum(q[i].y);
else bit::add(q[i].y, q[i].v);
}
for(int i=1; i<=Q; i++) printf("%lld\n", ans[i]);
}
bzoj 4822: [Cqoi2017]老C的任务的更多相关文章
- ●BZOJ 4822 [Cqoi2017]老C的任务
题链: https://www.luogu.org/problemnew/show/P3755 (洛谷上数据范围给全了的) 题解: 树状数组,离线询问 (本来想弄一个二维树状数组/二维RMQ,然后直接 ...
- BZOJ 4822 [Cqoi2017]老C的任务 ——树状数组
直接离散化之后用树状数组扫一遍. 把每一个询问拆成四个就可以做了. %Silvernebula 怒写KD-Tree #include <map> #include <cmath> ...
- bzoj 4822: [Cqoi2017]老C的任务【扫描线+树状数组+二维差分】
一个树状数组能解决的问题分要用树套树--还写错了我别是个傻子吧? 这种题还是挺多的,大概就是把每个矩形询问差分拆成四个点前缀和相加的形式(x1-1,y1-1,1)(x2.y2,1)(x1-1,y2,- ...
- bzoj 4823: [Cqoi2017]老C的方块 [最小割]
4823: [Cqoi2017]老C的方块 题意: 鬼畜方块游戏不解释... 有些特殊边,有些四个方块组成的图形,方块有代价,删掉一些方块使得没有图形,最小化代价. 比较明显的最小割,一个图形中必须删 ...
- bzoj 4824: [Cqoi2017]老C的键盘
Description 老 C 是个程序员. 作为一个优秀的程序员,老 C 拥有一个别具一格的键盘,据说这样可以大幅提升写程序的速度,还能让写出来的程序 在某种神奇力量的驱使之下跑得非常快.小 ...
- bzoj 4823 [Cqoi2017]老C的方块——网络流
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4823 一个不合法方案其实就是蓝线的两边格子一定选.剩下两部分四相邻格子里各选一个. 所以这个 ...
- BZOJ 4823: [Cqoi2017]老C的方块
分析: 我觉得我的网络流白学了...QAQ... 其实数据范围本是无法用网络流跑过去的,然而出题者想让他跑过去,也就跑过去了... 看到题目其实感觉很麻烦,不知道从哪里入手,那么仔细观察所给出的有用信 ...
- BZOJ 4823 [Cqoi2017]老C的方块 ——网络流
lrd的题解:http://www.cnblogs.com/liu-runda/p/6695139.html 我还是太菜了.以后遇到这种题目应该分析分析性质的. 网络流复杂度真是$O(玄学)$ #in ...
- BZOJ 4824 [Cqoi2017]老C的键盘 ——树形DP
每一个限制条件相当于一条有向边, 忽略边的方向,就成了一道裸的树形DP题 同BZOJ3167 唯一的区别就是这个$O(n^3)$能过 #include <map> #include < ...
随机推荐
- Linux系统上安装JDK和Tomcat服务器
一.安装JDK 1.查看当前Linux系统是否已经安装java 输入命令: rpm -qa | grep java 2.卸载两个openJDK 输入命令:rpm -e --nodeps 3.上传j ...
- 久未更 ~ 四之 —— Vsftpd出现 Failed to start Vsftpd ftp daemon错误
> > > > > 久未更 系列一:Failed to start Vsftpd ftp daemon错误 配置 vsftpd.conf文件后 重启ftp服务 出现 Fa ...
- 宝塔linux面板.txt
安装命令: yum -y install screen wget && screen -S bt wget -O install.sh http://103.224.251.79:58 ...
- thinkphp操作完提示信息该怎么弄成弹出层啊?
http://www.thinkphp.cn/topic/21929.html 浏览:11879 发布日期:2014/08/22 分类:求助交流 关键字: thinkphp success跳转 弹出层 ...
- Uva 1599 Ideal Path - 双向BFS
题目连接和描述以后再补 这题思路很简单但还真没少折腾,前后修改提交了七八次才AC...(也说明自己有多菜了).. 注意问题: 1.看清楚原题的输入输出要求,刚了书上的中文题目直接开撸,以为输入输出都是 ...
- Maven打包时去掉项目版本号
Maven打包后,jar或war文件名里带有版本号信息,如projectname0.0.1-SNAPSHOT.jar等,怎么去掉呢? 解决办法: 打开项目pom.xml文件,在<build> ...
- Eclipse报错An internal error occurred during: "J2EE Component Mapping Update". java.lang.NullPointerException
Eclipse每次打开.java文件时,报错信息如下: An internal error occurred during: "J2EE Component Mapping Update&q ...
- UITableViewCell滑动删除及移动
实现Cell的滑动删除, 需要实现UITableView的代理UITableViewDelegate中如下方法: //先要设Cell可编辑 - (BOOL)tableView:(UITableView ...
- Vue.js的坑
参考网址:http://cn.vuejs.org/v2/guide/components.html 1.camelCase vs. kebab-case HTML 特性不区分大小写.当使用非字符串模版 ...
- python正则表达式re模块详细介绍
转自:http://www.jb51.net/article/50511.htm 本模块提供了和Perl里的正则表达式类似的功能,不关是正则表达式本身还是被搜索的字符串,都可以是Unicode字符,这 ...