扫描线水题。

#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;
}

最新文章

  1. zookeeper心跳机制流程梳理
  2. SQL PRIMARY KEY 约束\SQL FOREIGN KEY 约束\SQL CHECK 约束
  3. 通过HttpWebRequest请求与HttpWebResponse响应方式发布接口与访问接口
  4. Gson 和 FastJson 性能测试
  5. Sample SecondarySort 浅析
  6. JavaScript------事件委托(event delegation)
  7. Spring MVC无法获取ajax POST的参数和值
  8. VirtualBox下导入CentOS后,无法上网
  9. 初识 AutoLayout
  10. vi模式
  11. 入门前端之HTML
  12. AngularJs + ASP.NET MVC
  13. 定义 : angular view 和controller 之前的 ng-init 由谁来负责
  14. WebStorm里启动electron项目
  15. LeetCode 53. Maximum Subarray(最大的子数组)
  16. supervisord 备注
  17. GIL
  18. 【JVM】-NO.113.JVM.1 -【JDK11 HashMap详解-0-全局-put】
  19. java开学第一周测试代码
  20. C++二级指针第一种内存模型(指针数组)

热门文章

  1. E. 打击判定 判断矩形是否相交
  2. C#的弱引用
  3. Nginx upstream负载均衡配置
  4. asp.net 图表
  5. Java基础教程(25)--I/O
  6. Java编程基础-面向对象(下)
  7. SQLServer同一实例下事务操作
  8. 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
  9. Django ORM 一对一,一对多,多对多, 添加,批量插入和查询
  10. video 的使用