【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. WebSphere中配置的数据源在Web应用中引用的写法

    WebSphere中配置的数据源在Web应用中引用时名称一定要和数据源的JNDI名称保持一致,否则会出现无法找到数据源的错误. 引用WAS的数据源时只需要与JNDI名称保持一致即可. 引用Tomcat ...

  2. ASP.NET MVC 实现伪静态

    1  什么是伪静态? 现在很多门户网站或者各大电商平台的网站的链接最后都是.htm或者.htm结尾,那么他们的网页真的是静态的html吗?拿京东来说,有无数个页面都都Html,在商品每时每刻都可能被更 ...

  3. Access OLE对象和附件的区别

    OLE 对象 来自 Office 和基于 Windows 的程序的图像.文档.图形和其他对象 最多可存储 2GB 数据(此大小限制适用于所有 Access 数据库).请记住,添加 2GB 数据会导致数 ...

  4. shell 2 解析

    ---- shell 3 /home/oracle/utility/macro/call_autopurge_arch.sh Description: Call purge archive log f ...

  5. Snort里的规则目录文件解读(图文详解)

    不多说,直接上干货! snort的规则啊,是基于文本的,它通常存在于snort程序目录中或者子目录中,规则文件按照不同的组,进行分类存放的. snort的安装目录 [root@datatest sno ...

  6. suricata.yaml (一款高性能的网络IDS、IPS和网络安全监控引擎)默认配置文件(图文详解)

    不多说,直接上干货! 前期博客 基于CentOS6.5下Suricata(一款高性能的网络IDS.IPS和网络安全监控引擎)的搭建(图文详解)(博主推荐) 或者 基于Ubuntu14.04下Suric ...

  7. AJPFX理解反射及反射的应用

    怎么理解反射,反射的应用        反射就是把Java类中的各种成分映射成相应的Java类.        一般情况下我们要解决某个问题,先找到相关的类,创建该类的对象,然后通过该对象调用对应的方 ...

  8. JDK11源码分析之集合类(一)----HashMap

    一,首先需要拉取JDK11源码: 方便起见我给出芋道源码作者已经拉取好的openJDK11的GitHub地址只需要fork一下克隆到本地导入IDEA中就可以对源码分析了: https://github ...

  9. Android动态权限申请

    Android系统中,目前Dangerous级别的权限都需要动态申请.步骤如下: 1.AndroidManfiest.xml中申明需要的动态权限 <?xml version="1.0& ...

  10. 安卓(Android)关于 RecyclerView 不能填充满宽度

    RecyclerView 不能填充满屏幕宽度 RecyclerView 的 Adapter 在使用是,一定要 @Overridepublic RecyclerView.ViewHolder onCre ...