差分一下上线段树

#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int n, m, uu, vv, ww;
vector<int> d[100005];
struct SGT{
int cnt[400005], pos[400005];
void pushUp(int o){
int lson=o<<1;
int rson=lson|1;
if(cnt[lson]>=cnt[rson]){
cnt[o] = cnt[lson];
pos[o] = pos[lson];
}
else{
cnt[o] = cnt[rson];
pos[o] = pos[rson];
}
}
void update(int o, int l, int r, int x, int k){
if(l==r){
cnt[o] += k;
pos[o] = l;
}
else{
int mid=(l+r)>>1;
int lson=o<<1;
int rson=lson|1;
if(x<=mid) update(lson, l, mid, x, k);
if(mid<x) update(rson, mid+1, r, x, k);
pushUp(o);
}
}
}sgt;
int main(){
cin>>n>>m;
for(int i=1; i<=m; i++){
scanf("%d %d %d", &uu, &vv, &ww);
d[uu].push_back(ww);
d[vv+1].push_back(-ww);
}
for(int i=1; i<=n; i++){
for(int j=0; j<d[i].size(); j++)
if(d[i][j]>0) sgt.update(1, 1, 100000, d[i][j], 1);
else sgt.update(1, 1, 100000, -d[i][j], -1);
if(sgt.cnt[1]) printf("%d\n", sgt.pos[1]);
else printf("-1\n");
}
return 0;
}

最新文章

  1. 一个java的Profile工具
  2. maven install 读取jar包时出错;error in opening zip file
  3. HTML-学习笔记(1)
  4. [daily][archlinux][fonts] 在linux下管理字体
  5. 20145305《JAVA程序设计》课程总结
  6. 使用CSS为内容设定特定的鼠标样式(cursor)介绍
  7. Forms身份验证和基于Role的权限验证
  8. POJ2533 Longest Ordered Subsequence 【最长递增子序列】
  9. Core Animation中的组动画
  10. 应用程序写Xml文档
  11. C++汉诺塔递归实现
  12. 利用OpenCms9提供的模块创建新站点
  13. 【转】Redis学习笔记(五)如何用Redis实现分布式锁(2)—— 集群版
  14. leaflet 如何绘制圆
  15. maven编译的时候跳过test
  16. PHP socket通信之UDP
  17. Oracle中,如何查看FRA(Flashback Recovery Area)的利用率
  18. CoreDNS Plugins ---&gt; hosts
  19. tcp socket/ unix socket
  20. spring + mybatis合集

热门文章

  1. 微信BUG之微信内置的浏览器中window.location.href 不跳转
  2. HDU - 6058 Kanade's sum
  3. 【Tsinsen】A1280. 最长双回文串
  4. 数位dp知识点整理
  5. PHP的加密方式
  6. mysql对库,表及记录的增删改查
  7. 【学习笔记】C++ cout 输出小数点后指定位数
  8. C++模板类头文件和实现文件分离
  9. iOS 网络开发
  10. [实用技巧] Mac下面如何通过终端快速打开当前文件夹