离线树状数组 hihocoder 1391 Countries
官方题解:
// 离线树状数组 hihocoder 1391 Countries #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <math.h>
#include <memory.h>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const LL inf = 0x3f3f3f3f;
const LL MOD =100000000LL;
// const int N = 1e5+10;
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;}
const int MAXN = ;
struct node{
LL l,r,v;
}N[MAXN]; LL f[MAXN],x[MAXN];
int cmp(node a,node b){
return a.r<b.r;
}
void add(LL w,LL v){
for(;w<=MAXN;w+=w&(-w)) f[w]+=v;
}
LL getsum(LL w){
LL sum=;
for(;w;w-=w&(-w)) sum+=f[w];
return sum;
} int main(){
LL n,m,bs,nn,M;
while(~scanf("%lld%lld",&n,&m)){
memset(f,,sizeof(f));
memset(x,,sizeof(x));
scanf("%lld",&bs);
scanf("%lld%lld",&nn,&M);
LL r=m+bs;
LL k=;
LL sum=;
for(LL i=;i<=nn;i++){
LL s,t,v;
scanf("%lld%lld%lld",&s,&t,&v);
if(s+t<bs||s+t>r) continue;
else{
N[++k].l=s+*t,N[k].r=s+*t+(r-s-t)/(*t)**t;
N[k].v=v;
sum+=v;
}
}
for(LL i=;i<=M;i++){
LL s,t,v;
scanf("%lld%lld%lld",&s,&t,&v);
N[++k].l=s+t,N[k].v=v;
sum+=v;
if(s+t*<bs||s+t*>r) N[k].r=N[k].l;
else{
N[k].r=s+*t+(r-s-*t)/(*t)**t;
}
}
LL g=k;
k=;
for(LL i=;i<=g;i++){
x[++k]=N[i].l,x[++k]=N[i].r,x[++k]=N[i].r-n;
}
sort(N+,N++g,cmp);
sort(x+,x++k);
k=unique(x+,x++k)-x-;
LL ans=-inf;
for(LL i=;i<=g;i++){
LL w,pre,now;
w=lower_bound(x+,x++k,N[i].l)-x;
now=lower_bound(x+,x++k,N[i].r)-x;
pre=lower_bound(x+,x++k,N[i].r-n)-x;
add(w,N[i].v);
ans=max(ans,getsum(now)-getsum(pre-));
}
printf("%lld\n",sum-ans);
}
return ;
}
离线树状数组 hihocoder 1391 Countries的更多相关文章
- POJ 3416 Crossing --离线+树状数组
题意: 给一些平面上的点,然后给一些查询(x,y),即以(x,y)为原点建立坐标系,一个人拿走第I,III象限的点,另一个人拿II,IV象限的,点不会在任何一个查询的坐标轴上,问每次两人的点数差为多少 ...
- HDU 2852 KiKi's K-Number(离线+树状数组)
题目链接 省赛训练赛上一题,貌似不难啊.当初,没做出.离线+树状数组+二分. #include <cstdio> #include <cstring> #include < ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组
题目链接:CF #365 (Div. 2) D - Mishka and Interesting sum 题意:给出n个数和m个询问,(1 ≤ n, m ≤ 1 000 000) ,问在每个区间里所有 ...
- CF #365 (Div. 2) D - Mishka and Interesting sum 离线树状数组(转)
转载自:http://www.cnblogs.com/icode-girl/p/5744409.html 题目链接:CF #365 (Div. 2) D - Mishka and Interestin ...
- HDU3333 Turing Tree 离线树状数组
题意:统计一段区间内不同的数的和 分析:排序查询区间,离线树状数组 #include <cstdio> #include <cmath> #include <cstrin ...
- 13年山东省赛 Boring Counting(离线树状数组or主席树+二分or划分树+二分)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 2224: Boring Counting Time Limit: 3 Sec ...
- 区间的关系的计数 HDU 4638 离线+树状数组
题目大意:给你n个人,每个人都有一个id,有m个询问,每次询问一个区间[l,r],问该区间内部有多少的id是连续的(单独的也算是一个) 思路:做了那么多离线+树状数组的题目,感觉这种东西就是一个模板了 ...
- BZOJ_2743_[HEOI2012]采花_离线+树状数组
BZOJ_2743_[HEOI2012]采花_离线+树状数组 Description 萧芸斓是Z国的公主,平时的一大爱好是采花.今天天气晴朗,阳光明媚,公主清晨便去了皇宫中新建的花园采花 .花园足够大 ...
- SPOJ DQUERY - D-query (莫队算法|主席树|离线树状数组)
DQUERY - D-query Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query ...
随机推荐
- jquery Deferred demo
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- USACO Section 4.2: Drainage Ditches
最大流的模板题 /* ID: yingzho1 LANG: C++ TASK: ditch */ #include <iostream> #include <fstream> ...
- Android 如何处理崩溃的异常
Android中处理崩溃异常 大家都知道,现在安装Android系统的手机版本和设备千差万别,在模拟器上运行良好的程序安装到某款手机上说不定就出现崩溃的现象,开发者个人不可能购买所有设备逐个调试 ...
- MAVEN “Plugin execution not covered by lifecycle configuration”
pom文件中报错提示: Plugin execution not covered by lifecycle configuration: net.alchim31.maven:yuicompresso ...
- NDK(1)配置ndk,含eclipse,Android Studio1.5.1
现在的ndk配置已经非常简单,如果看到要cygwin的请关闭. 1,Eclipse 添加ndk linux,mac ,windows 相似, a.下载 ndk并解压, b.在eclipse的andro ...
- Linq 学习笔记
简介: LINQ 提供一种统一的方式,让我们能在C#语言中直接查询和操作各种数据. LINQ是用来描述数据访问总体方式的术语.LINQ to Object是针对实现了IEnumerable< ...
- linux 多处理器概念
Linux 提出了 Multi-Processing 的概念,它的调度器可以将操作系统的线程均分到各个核(或硬件线程)上去执行,以此达到并行计算的目的,从而也可以极大地提高系统的性能. 实现计数器 1 ...
- poj 2479 (DP)
求一个区间内连续两段不相交区间最大和. // File Name: 2479.cpp // Author: Missa_Chen // Created Time: 2013年06月22日 星期六 16 ...
- KVC&KVO&NSNotification
KVC,即是指 NSKeyValueCoding,一个非正式的 Protocol,提供一种机制来间接访问对象的属性.KVO 就是基于 KVC 实现的关键技术之一. 一个对象拥有某些属性.比如说,一个 ...
- (转)UILabel的详细使用
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 75, 40)]; //初始化UIlbel并设定frame lab ...