题目:洛谷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的更多相关文章

  1. BZOJ2527: [Poi2011]Meteors

    补一发题解.. 整体二分这个东西,一开始感觉复杂度不是很靠谱的样子 问了po姐姐,说套主定理硬干.. #include<bits/stdc++.h> #define ll long lon ...

  2. [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 ...

  3. 【BZOJ-2527】Meteors 整体二分 + 树状数组

    2527: [Poi2011]Meteors Time Limit: 60 Sec  Memory Limit: 128 MBSubmit: 831  Solved: 306[Submit][Stat ...

  4. 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 (汉译:符号工具错误:没有找到符合所 ...

  5. bzoj 2527 Meteors - 整体二分 - 树状数组

    Description Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby gala ...

  6. SPOJ Meteors - 可持久化线段树 - 二分法

    Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The plan ...

  7. CH4912 Meteors

    题意 4912 Meteors 0x49「数据结构进阶」练习 描述 Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第 ...

  8. (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 ...

  9. 【SPOJ METEORS】 Meteors

    http://www.spoj.com/problems/METEORS/ (题目链接) 题意 一个星球上有$m$个空间站排列在一个环形轨道上,每个空间站仅属于一个国家.总共有$K$场流星雨,这些流星 ...

  10. 2527: [Poi2011]Meteors[整体二分]

    2527: [Poi2011]Meteors Time Limit: 60 Sec  Memory Limit: 128 MB Submit: 1528  Solved: 556 [Submit][S ...

随机推荐

  1. Scalable Web Architecture and Distributed Systems

    转自:http://aosabook.org/en/distsys.html Scalable Web Architecture and Distributed Systems Kate Matsud ...

  2. Redis 报错:MISCONF Redis is configured to save RDB snapshots

    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Com ...

  3. Python IO编程-读写文件

    1.1给出规格化得地址字符串,这些字符串是经过转义的能直接在代码里使用的字符串 需要导入os模块 import os >>>os.path.join('user','bin','sp ...

  4. 【AIM Tech Round 5 (rated, Div. 1 + Div. 2) B】Unnatural Conditions

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 让a+b的和为100000000...0这样的形式就好了 这样s(a+b)=1<=m就肯定成立了(m>=1) 然后至于s ...

  5. http数据绑定spring mvc详解

  6. 从零開始写游戏引擎(一) - project创建以及文件夹设置还有版本号控制

    一句话提要 好的開始等于成功了一半. 创建文件夹结构 project文件夹下最好分为以下几个文件夹 Docs - 开发文档,设计文档 Assets - 角色,动作,模型和音效等 Source - 代码 ...

  7. centos7.0 安装日志--图文具体解释-python开发环境配置

    centos7.0公布之后,就下载了everthing的DVD镜像.今天有时间,所以决定在vbox底下体验一番--- 上图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nk ...

  8. MFC窗口去边框、置顶、全屏、激活

    静态移除长提边框非常easy,直接设置"Border"属性为"none"就可以 "Maximize Box", "Minimize ...

  9. Android 运行 gson.toJson(object) 报java.lang.StackOverflowError异常

    如以下的代码,运行后报java.lang.StackOverflowError错误: MusicSavedInfo musicSavedInfo=new MusicSavedInfo(currentS ...

  10. PHP别名引用错误:“The use statement with non-compound name … has no effect”

    别名概述 PHP5.3+支持命名空间:namespace,命名空间的一个重要功能是能够使用别名(alias)来引用一个符合规则的名字. 命名空间支持3中形式的别名引用(或称之为引入)方式:类(clas ...