【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. rhel7安装oracle 11gR2

    一.修改操作系统核心参数 在Root用户下执行以下步骤: 1)修改用户的SHELL的限制,修改/etc/security/limits.conf文件 输入命令:vi /etc/security/lim ...

  2. js拿到焦点所在的标签对象

    通过 document.activeElement 此时是js对象,如果要调用jQuery的API那么就转换成jquery对象 $(document.activeElement)

  3. (五)Mybatis总结之一对多、一对一

    一对多 业务场景:张三既是java开发师又是大学老师又是LOL代练,张三拥有多个角色. 1.创建实体类UserInfo和RoleInfo package com.qf.mybatisdemo.pojo ...

  4. HashMap和List遍历方法总结及如何遍历删除元素

    https://blog.csdn.net/demohui/article/details/77748809

  5. vue组件中—bus总线事件回调函数多次执行的问题

    在利用vue组件进行事件监听时发现,如果对N个vue组件实例的bus总线绑定同一事件的回调函数,触发任意组件的对应事件,回调函数至少会被执行N次,这是为什么呢? 为此,调研了普通对象的事件绑定和触发实 ...

  6. 30天自制操作系统 DAY6

    _load_gdtr: 这个函数用来将指定的段上限(limit)和地址赋值给名为GDTR的48位寄存器. 给GDTR赋值唯一的办法是指定一个内存地址,从指定的地址读取6个字节(48位),然后赋值给GD ...

  7. CAS4.0 server 环境的搭建

    1.上cas的官网下载cas server 官网地址:https://github.com/Jasig/cas/releases,下载好后 解压下载的 cas-server-4.0.0-release ...

  8. jquery日期控件+时分秒

    因为项目需要,一些时间上的查询要精确的时分.先看下效果图吧. 所需要的js 跟css 文件 jsp://特别注意引入的先后顺序 <link rel="stylesheet" ...

  9. 迅为iTOP-4418开发板串口虚拟控制台配置为普通串口

    如何将 iTOP-4418 的串口控制台配置为普通串口.在最终的产品中,如果需要额外的串口,可以将调试用的控制台串口作为普通串口使用,因为交付给最终用户手中的产品,一般不需要调试串口.屏蔽串口控制台需 ...

  10. Laravel 使用中间件进行权限控制

    Laravel 使用中间件进行权限控制 飞凡的陀螺 关注 2018.01.24 17:45 字数 264 阅读 1138评论 0喜欢 1 先看 文档Laravel 中间件提供了一种方便的机制来过滤进入 ...