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

  1. ●BZOJ 4822 [Cqoi2017]老C的任务

    题链: https://www.luogu.org/problemnew/show/P3755 (洛谷上数据范围给全了的) 题解: 树状数组,离线询问 (本来想弄一个二维树状数组/二维RMQ,然后直接 ...

  2. BZOJ 4822 [Cqoi2017]老C的任务 ——树状数组

    直接离散化之后用树状数组扫一遍. 把每一个询问拆成四个就可以做了. %Silvernebula 怒写KD-Tree #include <map> #include <cmath> ...

  3. bzoj 4822: [Cqoi2017]老C的任务【扫描线+树状数组+二维差分】

    一个树状数组能解决的问题分要用树套树--还写错了我别是个傻子吧? 这种题还是挺多的,大概就是把每个矩形询问差分拆成四个点前缀和相加的形式(x1-1,y1-1,1)(x2.y2,1)(x1-1,y2,- ...

  4. bzoj 4823: [Cqoi2017]老C的方块 [最小割]

    4823: [Cqoi2017]老C的方块 题意: 鬼畜方块游戏不解释... 有些特殊边,有些四个方块组成的图形,方块有代价,删掉一些方块使得没有图形,最小化代价. 比较明显的最小割,一个图形中必须删 ...

  5. bzoj 4824: [Cqoi2017]老C的键盘

    Description 老 C 是个程序员.     作为一个优秀的程序员,老 C 拥有一个别具一格的键盘,据说这样可以大幅提升写程序的速度,还能让写出来的程序 在某种神奇力量的驱使之下跑得非常快.小 ...

  6. bzoj 4823 [Cqoi2017]老C的方块——网络流

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4823 一个不合法方案其实就是蓝线的两边格子一定选.剩下两部分四相邻格子里各选一个. 所以这个 ...

  7. BZOJ 4823: [Cqoi2017]老C的方块

    分析: 我觉得我的网络流白学了...QAQ... 其实数据范围本是无法用网络流跑过去的,然而出题者想让他跑过去,也就跑过去了... 看到题目其实感觉很麻烦,不知道从哪里入手,那么仔细观察所给出的有用信 ...

  8. BZOJ 4823 [Cqoi2017]老C的方块 ——网络流

    lrd的题解:http://www.cnblogs.com/liu-runda/p/6695139.html 我还是太菜了.以后遇到这种题目应该分析分析性质的. 网络流复杂度真是$O(玄学)$ #in ...

  9. BZOJ 4824 [Cqoi2017]老C的键盘 ——树形DP

    每一个限制条件相当于一条有向边, 忽略边的方向,就成了一道裸的树形DP题 同BZOJ3167 唯一的区别就是这个$O(n^3)$能过 #include <map> #include < ...

随机推荐

  1. stl总结精简版

    STL 精简版 vetor #include<vector> #include<cstdio> #include<algorithm> #include<io ...

  2. poj1258prim算法

    /*poj 1258 *题意:有若干个农场,现需要将各个农场用光纤连接起来,各个农场之间连接的光纤长度也许不同, *要求求出使得将所有农场连接起来的最短光线长度 *算法分析:使用矩阵将各个农场之间的光 ...

  3. Ubuntu搭建Gitlab服务器

    想到Gitlab就必定会想到SVN,因为两者都是代码管理系统,作为开发人员来说,用习惯了SVN的图形化界面和SVN代码更新和提交的方式, 可能就会觉得使用git会比较麻烦,其实不然git使用起来非常方 ...

  4. jquery 和 mui 上拉加载

    jquery: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <m ...

  5. [国嵌攻略][067][tftp协议分析]

    TFTP作用 用于网络下载,TFTP客户机在TFTP服务器中下载文件. TFTP交换过程 1.配置TFTP服务器 vim /etc/xinetd.d/tftp 2.交换过程 客户端发请求包到服务器 服 ...

  6. oracle创建触发器及作用举例

    --创建触发器及作用举例 create or replace trigger tri before delete on emp --在删除emp表数据之前需要做的事根据自己的业务去写,before是在 ...

  7. 如何开发由Create-React-App 引导的应用(一)

    此文章是翻译How to develop apps bootstrapped with Create React App 官方文档 系列文章 如何开发由Create-React-App 引导的应用 如 ...

  8. JQuery的deferred对象学习总结

    什么是deferred? 可以帮助我们按规定的顺序执行函数,比如说我们ajax请求数据之后,对dom进行数据填充,那我们就要先执行完ajax,拿到数据之后才能进行dom数据填充,所以这就是一个顺序执行 ...

  9. Dig out WeChat deleted chat messages on Android Phone

    As we know that WeChat will wipe deleted chat messages. That's why forensic guys could  not dig out ...

  10. 无格式转换php

    // 无格式转换function ClearHtml($content,$allowtags='') { mb_regex_encoding('UTF-8'); //replace MS specia ...