[BOI2011]MET-Meteors
题目:洛谷P3527。
题目大意:
n个国家在某星球上建立了m个空间站(一个空间站只属于一个国家),空间站围成一个环。
现在知道要下k天陨石,每天都在一个区间内下,每个点都下同样多的(若r>l,则说明区间是\(1~r和l~m\))。
每个国家有一个目标陨石数。
问每个国家最早在什么时候达到目标陨石数。若下完了还达不到,则输出NIE。
解题思路:
整体二分。
对所有的国家一起二分,用树状数组维护前缀(后缀)。
对于每个答案,将能达到目标的国家和达不到的国家分开,然后继续二分即可。
时间复杂度\(O(n\log^2 n)\)。
线段树被卡常┭┮﹏┭┮
C++ Code:
#include<cstdio>
#include<vector>
#include<cctype>
#define LoveLive long long
const int M=500005,N=300005;
int k,n,m,P[N],q[N],ans[N],now,tmp[N];std::vector<int>a[N];
LoveLive Bit[M];
bool type[N];
inline int readint(){
int c=getchar(),d=0;
for(;!isdigit(c);c=getchar());
for(;isdigit(c);c=getchar())
d=(d<<3)+(d<<1)+(c^'0');
return d;
}
struct stars{
int l,r,s;
}d[N];
inline void add(int i,int a){for(;i<=m;i+=i&-i)Bit[i]+=a;}
inline LoveLive query(int i){LoveLive a=0;for(;i;i-=i&-i)a+=Bit[i];return a;}
inline void update(int tm,int det){
if(d[tm].l<=d[tm].r)add(d[tm].l,det*d[tm].s),add(d[tm].r+1,-det*d[tm].s);else
add(1,det*d[tm].s),add(d[tm].r+1,-det*d[tm].s),add(d[tm].l,det*d[tm].s);
}
void solve(int l,int r,int l1,int l2){
if(l1>l2)return;
if(l==r){
for(int i=l1;i<=l2;++i)ans[q[i]]=l;
return;
}
int mid=l+r>>1;
while(now<mid)update(++now,1);
while(now>mid)update(now--,-1);
int cnt=0;
for(int i=l1;i<=l2;++i){
LoveLive p=0;
int&id=q[i];
for(int j=0,dd=a[id].size();j<dd&&p<P[id];++j)p+=query(a[id][j]);
if(p>=P[id])type[id]=1,++cnt;else
type[id]=0;
}
int t1=l1,t2=l1+cnt;
for(int i=l1;i<=l2;++i)
if(type[q[i]])tmp[t1++]=q[i];else
tmp[t2++]=q[i];
for(int i=l1;i<=l2;++i)q[i]=tmp[i];
solve(l,mid,l1,t1-1);
solve(mid+1,r,t1,l2);
}
int main(){
n=readint(),m=readint();
for(int i=1;i<=m;++i)a[readint()].push_back(i);
for(int i=1;i<=n;++i)P[q[i]=i]=readint();
k=readint()+1;
for(int i=1;i<k;++i){
d[i].l=readint();
d[i].r=readint();
d[i].s=readint();
}
d[k]=(stars){1,m,1e9};
solve(1,k,1,n);
for(int i=1;i<=n;++i)
if(ans[i]<k)printf("%d\n",ans[i]);else puts("NIE");
return 0;
}
[BOI2011]MET-Meteors的更多相关文章
- BZOJ2527: [Poi2011]Meteors
补一发题解.. 整体二分这个东西,一开始感觉复杂度不是很靠谱的样子 问了po姐姐,说套主定理硬干.. #include<bits/stdc++.h> #define ll long lon ...
- [Android Tips] 23. How to fail/stop Gradle task immediately if some conditions are not met
throw new GradleException("conditions are not met") 参考 How to fail/stop task immediately i ...
- 【BZOJ-2527】Meteors 整体二分 + 树状数组
2527: [Poi2011]Meteors Time Limit: 60 Sec Memory Limit: 128 MBSubmit: 831 Solved: 306[Submit][Stat ...
- C# signtool error:no certificates were found that met all the given criteria 错误解决方案
程序运行时报错:signtool error:no certificates were found that met all the given criteria (汉译:符号工具错误:没有找到符合所 ...
- bzoj 2527 Meteors - 整体二分 - 树状数组
Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby gala ...
- SPOJ Meteors - 可持久化线段树 - 二分法
Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The plan ...
- CH4912 Meteors
题意 4912 Meteors 0x49「数据结构进阶」练习 描述 Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第 ...
- (10)The secret to great opportunities? The person you haven't met yet
https://www.ted.com/talks/tanya_menon_the_secret_to_great_opportunities_the_person_you_haven_t_met_y ...
- 【SPOJ METEORS】 Meteors
http://www.spoj.com/problems/METEORS/ (题目链接) 题意 一个星球上有$m$个空间站排列在一个环形轨道上,每个空间站仅属于一个国家.总共有$K$场流星雨,这些流星 ...
- 2527: [Poi2011]Meteors[整体二分]
2527: [Poi2011]Meteors Time Limit: 60 Sec Memory Limit: 128 MB Submit: 1528 Solved: 556 [Submit][S ...
随机推荐
- nyoj158-省赛来了
省赛来了 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 一年一度的河南省程序设计大赛又要来了. 竞赛是要组队的,组队形式:三人为一队,设队长一名,队员两名. 现在问题就 ...
- Problem 3
Problem 3 # Problem_3.py """ The prime factors of 13195 are 5, 7, 13 and 29. What is ...
- Python学习笔记(2)操作符和数据类型
2019-02-25 一: (1)常用操作符: ① 算数操作符:=.-.*./.%(求余).**(幂运算).//(地板除法:计算结果取比商小的最大整型) 注意:幂运算操作符比其左侧的一元运算符的优先级 ...
- (0)资料官网【从零开始学Spring Boot】
Spring Boot官网:http://projects.spring.io/spring-boot/ Eclipse官网:http://www.eclipse.org/ Maven官网:http: ...
- HDU5926 Mr. Frog’s Game
/* HDU5926 Mr. Frog’s Game http://acm.hdu.edu.cn/showproblem.php?pid=5926 杂题水题 * */ #include <cst ...
- Arduino Yun高速新手教程(大学霸内部资料)
Arduino Yun高速新手教程(大学霸内部资料) 本资料为国内第一本Arduino Yun教程.具体解说Arduino Yun的基本结构.开发环境.系统配置.并着力解说关键功能--Bridge.最 ...
- QT5 Failed to load platform plugin "windows" 终极解决方式 命令行问题
Failed to load platform plugin "windows" 这个错误在双击exe运行时不会出现,当传递命令行參数时出问题 ,解决方法: int main(in ...
- ExtJs--16--Ext.override()方法专门用来重写对象的方法
Ext.onReady(function(){ /** * Ext.override()方法专门用来重写对象的方法 */ //定义个类 Ext.define("U",{ //该类的 ...
- ”危险“的RESTRICT与GCC的编译优化(编程者对编译器所做的一个“承诺”:使用restrict修饰过的指针,它所指向的内容只能经由该指针修改)
restrict是C99标准中新添加的关键字,对于从C89标准开始起步学习C语言的同学来说(包括我),第一次看到restrict还是相当陌生的.Wikipedia给出的解释如下: In the C p ...
- hdoj--1251--统计难题(字典树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...