【bzoj2527】[Poi2011]Meteors

Description

Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The planet is unsuitable for colonisation due to strange meteor showers, which on the other hand make it an exceptionally interesting object of study.
The member states of BIU have already placed space stations close to the planet’s orbit. The stations’ goal is to take samples of the rocks flying by. The BIU Commission has partitioned the orbit into msectors, numbered from 1to m, where the sectors 1and mare adjacent. In each sector there is a single space station, belonging to one of the nmember states.
Each state has declared a number of meteor samples it intends to gather before the mission ends. Your task is to determine, for each state, when it can stop taking samples, based on the meter shower predictions for the years to come.
 
Byteotian Interstellar Union有N个成员国。现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1份相邻),第i份上有第Ai个国家的太空站。
这个星球经常会下陨石雨。BIU已经预测了接下来K场陨石雨的情况。 BIU的第i个成员国希望能够收集Pi单位的陨石样本。你的任务是判断对于每个国家,它需要在第几次陨石雨之后,才能收集足够的陨石。 输入: 第一行是两个数N,M。 第二行有M个数,第i个数Oi表示第i段轨道上有第Oi个国家的太空站。 第三行有N个数,第i个数Pi表示第i个国家希望收集的陨石数量。 第四行有一个数K,表示BIU预测了接下来的K场陨石雨。 接下来K行,每行有三个数Li,Ri,Ai,表示第K场陨石雨的发生地点在从Li顺时针到Ri的区间中(如果Li<=Ri,就是Li,Li+1,…,Ri,否则就是Ri,Ri+1,…,m-1,m,1,…,Li),向区间中的每个太空站提供Ai单位的陨石样本。 输出: N行。第i行的数Wi表示第i个国家在第Wi波陨石雨之后能够收集到足够的陨石样本。如果到第K波结束后仍然收集不到,输出NIE。
数据范围: 1<=n,m,k<=3*10^5 1<=Pi<=10^9 1<=Ai<10^9

Input

The first line of the standard input gives two integers, n and m(1<=n,m<=3*10^5) separated by a single space, that denote, respectively, the number of BIU member states and the number of sectors the orbit has been partitioned into.
In the second line there are mintegers Oi(1<=Oi<=n) separated by single spaces, that denote the states owning stations in successive sectors.
In the third line there are nintegers Pi(1<=Pi<=10^9) separated by single spaces, that denote the numbers of meteor samples that the successive states intend to gather.
In the fourth line there is a single integer k(1<=k<=3*10^5) that denotes the number of meteor showers predictions. The following klines specify the (predicted) meteor showers chronologically. The i-th of these lines holds three integers Li, Ri, Ai(separated by single spaces), which denote that a meteor shower is expected in sectors Li,Li+1,…Ri (if Li<=Ri) or sectors Li,Li+1,…,m,1,…Ri (if Li>Ri), which should provide each station in those sectors with Aimeteor samples (1<=Ai<10^9).
In tests worth at least 20% of the points it additionally holds that .

Output

 
Your program should print nlines on the standard output. The i-th of them should contain a single integer Wi, denoting the number of shower after which the stations belonging to the i-th state are expected to gather at least Pi samples, or the word NIE (Polish forno) if that state is not expected to gather enough samples in the foreseeable future.

Sample Input

3 5
1 3 2 1 3
10 5 7
3
4 2 4
1 3 1
3 5 2

Sample Output

3
NIE
1
 
整体二分,就是二分到哪里为止,然后就是统计,判断有没有到了收集个数,
到了放左边,没到放右边,这样继续二分,如何判断NIE,最后加一个inf的,
就是k+1的那一轮一定可以满足所有条件即可。
 
 #include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<vector> #define ll long long
#define N 300007
#define inf 1000000009
using namespace std;
inline int read ()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if (ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=(x<<)+(x<<)+ch-'';ch=getchar();}
return x*f;
} int n,m,k,T;
int ans[N],id[N],l[N],r[N],val[N],num[N],tmp[N];
ll tr[N];
bool mark[N];
vector<int>a[N]; inline int lowbit(int x){return x&(-x);}
void add(int x,int num)
{
if (x>m) return;
for (int i=x;i<=m;i+=lowbit(i)) tr[i]+=num;
}
ll query(int x)
{
ll res=;
for (int i=x;i>=;i-=lowbit(i))
res+=tr[i];
return res;
}
void update(int x,int f)
{
if (l[x]<=r[x]) add(l[x],f*val[x]),add(r[x]+,f*val[x]*-);
else add(,f*val[x]),add(r[x]+,f*val[x]*-),add(l[x],f*val[x]);
}
void solve(int l,int r,int L,int R)
{
if (l>r) return;
if(L==R)
{
for (int i=l;i<=r;i++)ans[id[i]]=L;
return;
}
int mid=(L+R)>>;
while(T<=mid)T++,update(T,);
while(T>mid)update(T,-),T--;
int cnt=,now;ll tot;
for (int i=l;i<=r;i++)
{
tot=,now=id[i];
for (int j=;j<a[now].size();j++)
{
tot+=query(a[now][j]);
if (tot>=num[now])break;//优化
}
if (tot>=num[now]) mark[now]=,cnt++;
else mark[now]=;
} int l1=l,l2=l+cnt;
for (int i=l;i<=r;i++)
if(mark[id[i]])tmp[l1++]=id[i];
else tmp[l2++]=id[i];
for (int i=l;i<=r;i++)id[i]=tmp[i]; solve(l,l1-,L,mid),solve(l1,l2-,mid+,R);
}
int main()
{
n=read(),m=read();
for (int i=;i<=m;i++){int x=read();a[x].push_back(i);}
for (int i=;i<=n;i++)num[i]=read();
k=read();
for (int i=;i<=k;i++)l[i]=read(),r[i]=read(),val[i]=read();
k++,l[k]=,r[k]=n,val[k]=inf;
for (int i=;i<=n;i++)id[i]=i;
solve(,n,,k);
for (int i=;i<=n;i++)
if (ans[i]!=k) printf("%d\n",ans[i]);
else printf("NIE\n");
}

【bzoj2527】[Poi2011]Meteors(树状数组(单点查询,区间修改)+整体二分)的更多相关文章

  1. 题解报告:Luogu P3368 【模板】树状数组 2(区间修改,单点查询)

    题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...

  2. A Simple Problem with Integers 多树状数组分割,区间修改,单点求职。 hdu 4267

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  3. poj 2763 Housewife Wind(树链剖分+单点查询+区间修改)

    题目链接:http://poj.org/problem?id=2763 题意:给一个数,边之间有权值,然后两种操作,第一种:求任意两点的权值和,第二,修改树上两点的权值. 题解:简单的树链剖分. #i ...

  4. Libre OJ 130、131、132 (树状数组 单点修改、区间查询 -> 区间修改,单点查询 -> 区间修改,区间查询)

    这三题均可以用树状数组.分块或线段树来做 #130. 树状数组 1 :单点修改,区间查询 题目链接:https://loj.ac/problem/130 题目描述 这是一道模板题. 给定数列 a[1] ...

  5. TZOJ 2725 See you~(二维树状数组单点更新区间查询)

    描述 Now I am leaving hust acm. In the past two and half years, I learned so many knowledge about Algo ...

  6. hdu 2642二维树状数组 单点更新区间查询 模板题

    二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...

  7. POJ 2155 Matrix【二维树状数组+YY(区间计数)】

    题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  8. P3368 【模板】树状数组 2(区间增减,单点查询)

    P3368 [模板]树状数组 2 题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表 ...

  9. 洛谷 P3368 【模板】树状数组 2(区间加,单点查询)

    题目链接 https://www.luogu.org/problemnew/show/P3368 树状数组 最基础的用法:https://www.cnblogs.com/yinyuqin/p/1096 ...

  10. nyoj 123 士兵杀敌(四) 树状数组【单点查询+区间修改】

    士兵杀敌(四) 时间限制:2000 ms  |  内存限制:65535 KB 难度:5   描述 南将军麾下有百万精兵,现已知共有M个士兵,编号为1~M,每次有任务的时候,总会有一批编号连在一起人请战 ...

随机推荐

  1. iOS- NSThread/NSOperation/GCD 三种多线程技术的对比及实现 -- 转

    1.iOS的三种多线程技术 1.NSThread 每个NSThread对象对应一个线程,量级较轻(真正的多线程) 2.以下两点是苹果专门开发的“并发”技术,使得程序员可以不再去关心线程的具体使用问题 ...

  2. jmeter(四)检查点

    JMeter也有像LR中的检查点,本篇就来介绍下JMeter的检查点如何去实现. JMeter里面的检查点通过添加断言来完成. 检查点:上一章讲到,我们对用户名和密码进行了参数化,那么怎样来判断jme ...

  3. Css 基本的规则写法

    样式表的写法: css的语法由一些标志构成,就是一个基本的样式表由选择器,属性和属性值构成.Css有标准的写法规则标准的css写法: h1 { Font-family:黑体;} h1:表示选择符Fon ...

  4. hdu 6011 Lotus and Characters 贪心

    http://acm.hdu.edu.cn/showproblem.php?pid=6011 先把数字从小到大排好,比如是-6.3.4这样, 然后处理出后缀和,当后缀和 <= 0的时候马上停止就 ...

  5. Solr中的group与facet的区别 [转]

    Solr中的group与facet的区别 facet 自己理解就是分组聚合用的, 如下说明 http://blog.csdn.net/a925907195/article/details/472572 ...

  6. Windows 7下如何在Cygwin下正确安装Tcpreplay(图文详解)

    可以在大家安装的Cygwin的安装目录下执行(我的这里是D:\SoftWare\cygwin) #winpcap的安装过程:|$ unzip WpdPack_4_1_2.zip|$ cp -r Wpd ...

  7. 组合模式和php实现

    组合模式(有时候又叫做部分-整体模式): 将对象组合成树形结构以表示“部分整体”的层次结构.组合模式使得用户对单个对象和组合对象的使用具有一致性.它使我们树型结构的问题中,模糊了简单元素和复杂元素的概 ...

  8. core\stm32f10x.h(244): error: #67: expected a "}"

  9. C++ 继承/派生、访问属性、构造函数

    1.子类继承父类的继承方式:public,private,protected,不写则默认为private: 2.子类会继承父类的全部成员(除了构造函数.析构函数,虽然析构函数有virtual,但是不是 ...

  10. AIX 10201 HA RAC 安装+升级到10204

    1:查看系统版本 [rac1:root:/hacmp/hacmp5.4/ha5.4/installp/ppc] oslevel -s 6100-06-06-1140 lslpp -al bos.adt ...