题面

题解

首先我们尝试暴力,那么就对每个点二分一下即可。

我们发现单独二分复杂度太高,而且有些地方很浪费,如求前缀和等。

那么我们就想,能否将它们合并在一起二分呢?

于是就有了整体二分

整体二分即可。

代码

#include<cstdio>
#include<cstring>
#include<vector>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x)); inline int read()
{
int data = 0, w = 1;
char ch = getchar();
while(ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if(ch == '-') w = -1, ch = getchar();
while(ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
return data*w;
} const int maxn(3e5 + 10);
struct node { int l, r; long long a; } r[maxn];
struct qry { int id; long long p; } p[maxn], pl[maxn], pr[maxn];
long long c[maxn]; std::vector<int> a[maxn];
int n, m, ans[maxn], K;
inline void add(int x, int v) { while(x <= m) c[x] += v, x += x & -x; }
inline long long query(int x) { long long ans = 0; while(x) ans += c[x], x -= x & -x; return ans; }
inline void fall(int x, int o)
{
if(r[x].l > r[x].r) add(1, o * r[x].a);
add(r[x].l, o * r[x].a); add(r[x].r + 1, -o * r[x].a);
} inline bool check(int x, long long &sum)
{
sum = 0;
static std::vector<int>::iterator it;
for(it = a[p[x].id].begin(); it != a[p[x].id].end(); ++it) { sum += query(*it); if(sum >= p[x].p) return true; }
return false;
} void Div(int l, int r, int ql, int qr)
{
if(ql > qr) return;
if(l == r) { for(RG int i = ql; i <= qr; i++) ans[p[i].id] = l; return; } int mid = (l + r) >> 1, tl = 0, tr = 0;
long long sum; for(RG int i = l; i <= mid; i++) fall(i, 1);
for(RG int i = ql; i <= qr; i++)
if(check(i, sum)) pl[++tl] = p[i];
else p[i].p -= sum, pr[++tr] = p[i]; for(RG int i = l; i <= mid; i++) fall(i, -1);
for(RG int i = 1; i <= tl; i++) p[i + ql - 1] = pl[i];
for(RG int i = 1; i <= tr; i++) p[i + ql + tl - 1] = pr[i];
Div(l, mid, ql, ql + tl - 1);
Div(mid + 1, r, ql + tl, qr);
} int main()
{
#ifndef ONLINE_JUDGE
file(cpp);
#endif n = read(); m = read();
for(RG int i = 1; i <= m; i++) a[read()].push_back(i);
for(RG int i = 1; i <= n; i++) p[i] = (qry) {i, read()};
K = read();
for(RG int i = 1; i <= K; i++) r[i] = (node) {read(), read(), read()};
r[++K] = (node) {1, m, 1000000000}; Div(1, K, 1, n);
for(RG int i = 1; i <= n; i++) ans[i] == K ? puts("NIE") : printf("%d\n", ans[i]);
return 0;
}

[POI2011]MET-Meteors的更多相关文章

  1. 「POI2011」Meteors

    「POI2011」Meteors 传送门 整体二分,树状数组实现区间修改单点查询,然后注意修改是在环上的. 参考代码: #include <cstdio> #include <vec ...

  2. 【BZOJ】【2527】【POI2011】Meteors

    整体二分+树状数组 整体二分……感谢zyf提供的入门题 简单粗暴的做法:枚举每一个国家,二分他的$w_i$,然后计算……然而这样效率很低…… 整体二分就是:对所有的国家一起进行二分,$w_i$在mid ...

  3. 【BZOJ2527】【POI2011】Meteors [整体二分]

    Meteors Time Limit: 60 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 这个星球经常会下陨石雨.BI ...

  4. 【BZOJ】【2738】&【Tsinsen】【A1333】矩阵乘法

    整体二分+树状数组 过了[BZOJ][2527][POI2011]Meteors以后这题就没那么难啦~ 关键是[从小到大]依次插入数字,然后整体二分每个查询的第k大是在第几次插入中被插入的……嗯大概就 ...

  5. BZOJ2527: [Poi2011]Meteors

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

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

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

  7. 【BZOJ2527】[Poi2011]Meteors 整体二分

    [BZOJ2527][Poi2011]Meteors Description Byteotian Interstellar Union (BIU) has recently discovered a ...

  8. 【bzoj2527】[Poi2011]Meteors(树状数组(单点查询,区间修改)+整体二分)

    [bzoj2527][Poi2011]Meteors Description Byteotian Interstellar Union (BIU) has recently discovered a ...

  9. bzoj 2527: [Poi2011]Meteors 整体二分

    给每个国家建一个链表,这样分治过程中的复杂度就和序列长度线形相关了,无脑套整体二分就可以. (最坑的地方是如果所有位置都是一个国家,那么它的样本个数会爆longlong!!被这个坑了一次,大于p[i] ...

  10. BZOJ2527[Poi2011]Meteors——整体二分+树状数组

    题目描述 Byteotian Interstellar Union (BIU) has recently discovered a new planet in a nearby galaxy. The ...

随机推荐

  1. video文件格式说明(笔记)

    video标签兼容IE8可使用html5media.js,具体demo可以下载文件中的压缩包 移动端兼容参考: http://www.xyhtml5.com/3252.html

  2. BZOJ 1059 矩阵游戏 二分图匹配

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1059 题目大意: 小Q是一个非常聪明的孩子,除了国际象棋,他还很喜欢玩一个电脑益智游戏 ...

  3. android中反射技术使用实例

    在计算机科学领域.反射是指一类应用,它们能够自描写叙述和自控制.也就是说,这类应用通过採用某种机制来实现对自己行为的描写叙述(self-representation)和监測(examination), ...

  4. CF284A Cows and Primitive Roots

    嘟嘟嘟 这道题就是求一个奇素数\(p\)的原根数量. 公式是\(\varphi(\varphi(p))\).又因为\(p\)是质数,所以就是\(\varphi(p - 1)\). (证明啥的我不会-- ...

  5. mysql备份数据库脚本

    mysqldump.exe -uroot -proot mydb > D:\backup_script\bak-tmp\mydb.sql 备注:把mysql的bin下的mysqldump.exe ...

  6. AFSoundManager

    iOS audio playing (both local and streaming) and recording made easy through a complete and block-dr ...

  7. UVALive - 2515 (最小生成树 kruskal)

    You are assigned to design network connections between certain points in a wide area. You are given ...

  8. SQL 语句 merge into

    MERGE INTO tb_st_shxxcount tt USING ( SELECT DISTINCT sd.CODE, COUNT (ts.LRDW) count1, TO_CHAR (ts.L ...

  9. Android的JNI调用(一)

    Android提供NDK开发包来提供Android平台的C++开发,用来扩展Android SDK的功能.主要包括Android NDK构建系统和JNI实现与原生代码通信两部分. 一.Android ...

  10. Linux-- 查看文件 more与其它

    more 翻页查看 用法:more 文件名 nl 显示行号打印(不常用) 1.不打印空白行行号:nl -b t 文件名 类似 cat -b 文件名 2.打印所有行行号:nl -b a 文件名 类似 c ...