luogu3755 [CQOI2017]老C的任务
2024-09-08 17:10:06
扫描线水题。
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
int n, m, dx[300005], dy[300005], cntx, cnty, cnt, uu, vv, ww, aa, bb;
ll ans[100005], c[300005];
struct Node{
int idd, val, xxx, yyy;
}nd[500005];
bool cmp(Node x, Node y){
if(x.xxx==y.xxx) return x.idd<y.idd;
else return x.xxx<y.xxx;
}
int lb(int x){
return x&-x;
}
void add(int pos, int w){
for(int i=pos; i<=cnty; i+=lb(i))
c[i] += w;
}
ll query(int pos){
ll re=0;
for(int i=pos; i; i-=lb(i))
re += c[i];
return re;
}
int main(){
cin>>n>>m;
for(int i=1; i<=n; i++){
scanf("%d %d %d", &uu, &vv, &ww);
nd[++cnt] = (Node){0, ww, uu, vv};
dx[++cntx] = uu;
dy[++cnty] = vv;
}
for(int i=1; i<=m; i++){
scanf("%d %d %d %d", &uu, &vv, &aa, &bb);
uu--; vv--;
dx[++cntx] = uu; dx[++cntx] = aa;
dy[++cnty] = vv; dy[++cnty] = bb;
nd[++cnt] = (Node){i, 1, uu, vv};
nd[++cnt] = (Node){i, -1, uu, bb};
nd[++cnt] = (Node){i, -1, aa, vv};
nd[++cnt] = (Node){i, 1, aa, bb};
}
sort(dx+1, dx+1+cntx);
sort(dy+1, dy+1+cnty);
cntx = unique(dx+1, dx+1+cntx) - (dx + 1);
cnty = unique(dy+1, dy+1+cnty) - (dy + 1);
for(int i=1; i<=cnt; i++){
nd[i].xxx = lower_bound(dx+1, dx+1+cntx, nd[i].xxx) - dx;
nd[i].yyy = lower_bound(dy+1, dy+1+cnty, nd[i].yyy) - dy;
}
sort(nd+1, nd+1+cnt, cmp);
for(int i=1; i<=cnt; i++){
if(!nd[i].idd) add(nd[i].yyy, nd[i].val);
else ans[nd[i].idd] += query(nd[i].yyy) * nd[i].val;
}
for(int i=1; i<=m; i++)
printf("%lld\n", ans[i]);
return 0;
}
最新文章
- zookeeper心跳机制流程梳理
- SQL PRIMARY KEY 约束\SQL FOREIGN KEY 约束\SQL CHECK 约束
- 通过HttpWebRequest请求与HttpWebResponse响应方式发布接口与访问接口
- Gson 和 FastJson 性能测试
- Sample SecondarySort 浅析
- JavaScript------事件委托(event delegation)
- Spring MVC无法获取ajax POST的参数和值
- VirtualBox下导入CentOS后,无法上网
- 初识 AutoLayout
- vi模式
- 入门前端之HTML
- AngularJs + ASP.NET MVC
- 定义 : angular view 和controller 之前的 ng-init 由谁来负责
- WebStorm里启动electron项目
- LeetCode 53. Maximum Subarray(最大的子数组)
- supervisord 备注
- GIL
- 【JVM】-NO.113.JVM.1 -【JDK11 HashMap详解-0-全局-put】
- java开学第一周测试代码
- C++二级指针第一种内存模型(指针数组)
热门文章
- E. 打击判定 判断矩形是否相交
- C#的弱引用
- Nginx upstream负载均衡配置
- asp.net 图表
- Java基础教程(25)--I/O
- Java编程基础-面向对象(下)
- SQLServer同一实例下事务操作
- nginx 编译某个模板的问题./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library stati
- Django ORM 一对一,一对多,多对多, 添加,批量插入和查询
- video 的使用