[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 ...
随机推荐
- nyoj286-动物统计
动物统计 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 在美丽大兴安岭原始森林中存在数量繁多的物种,在勘察员带来的各种动物资料中有未统计数量的原始动物的名单.科学家想判 ...
- python之简述上下文管理
上下文管理器 原理 代码讲解 原理 上下文管理能保证资源会被正确回收,即保证退出步骤的执行.其用处最多的是,作为确保资源被正确回收的一种方式. 一种重复使用的 try-except-finally 结 ...
- 利用Tensorflow实现手写字符识别
模式识别领域应用机器学习的场景非常多,手写识别就是其中一种,最简单的数字识别是一个多类分类问题,我们借这个多类分类问题来介绍一下google最新开源的tensorflow框架,后面深度学习的内容都会基 ...
- 性能测试之Jforum平台的搭建
学习Jmeter性能基础,想要借助1款现有的软件平台,来练习jmeter基础,<Jmeter实战>书籍上给出样例软件平台:Jforum 一.环境准备 准备:tomcat9.mysql5.5 ...
- 参数化取值策略Random
1.Random+Each iteration,跟顺序读取的结果唯一不同的就是这里是随机读取,取值是每次迭代取值 2.Random+Each occurrence,随机取值更新方式 3.R ...
- ie版本
<!--[if lte IE 6]> 自定义代码 <![endif]-->
- yii 表单小部件使用
首先创建model层 因为要使用表单小部件 所以要加载相应的组件 这里需要的组件有 yii\widgets\ActiveForm 和 yii\helpers\Html 接下来在model定义的clas ...
- TNS-12557: TNS:protocol adapter not loadable TNS-12560: TNS:protocol adapter error
Description: Oracle 10.2 on hpux 11.23 PA. When i try to start listener i go the next errors: Error ...
- wcf的Contract中name的使用
name可以自定义,Contract中的name会更改soap消息中的名称,虽然不影响在服务端代码中的使用 可以看到,在后台代码中使用函数的重用进行编写代码是非常方便的
- css3 transform 旋转div
css3 transform 旋转div 学习了:http://www.w3school.com.cn/cssref/pr_transform.asp