【LG3527】[POI2011]MET-Meteors

题面

洛谷

题解

整体二分。

每次二分\(mid\),如果到时间\(mid\)以收集过\(P_i\)就存入子序列\(L\),否则存入子序列\(R\)

修改可以树状数组区间修改单点查询做

每个王国的掉落地点用\(vector\)存一下即可

看起来复杂度是平方的实则为线性的

总复杂度\(O(nlog^2)\)

代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
namespace IO {
const int BUFSIZE = 1 << 20;
char ibuf[BUFSIZE], *is = ibuf, *it = ibuf;
inline char gc() {
if (is == it) it = (is = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
return *is++;
}
}
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (ch != '-' && (ch > '9' || ch < '0')) ch = IO::gc();
if (ch == '-') w = -1 , ch = IO::gc();
while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = IO::gc();
return w * data;
}
typedef long long ll;
const int MAX_N = 300005;
struct Node { ll p; int id; } q[MAX_N], lq[MAX_N], rq[MAX_N];
struct Option { int l, r, v; } p[MAX_N];
vector<int> G[MAX_N];
int N, M, K, ans[MAX_N];
ll c[MAX_N];
inline int lb(int x) { return x & -x; }
void add(int x, int v) { while (x <= M) c[x] += v, x += lb(x); }
ll sum(int x) { ll res = 0; while (x > 0) res += c[x], x -= lb(x); return res; }
void modify(int x, int w) {
int l = p[x].l, r = p[x].r, v = p[x].v;
if (l <= r) add(l, w * v), add(r + 1, -w * v);
else add(1, v * w), add(r + 1, -v * w), add(l, v * w);
}
void Div(int lval, int rval, int st, int ed) {
if (st > ed) return ;
if (lval == rval) { for (int i = st; i <= ed; i++) ans[q[i].id] = lval; return ; }
int mid = (lval + rval) >> 1;
int lt = 0, rt = 0; ll res = 0;
for (int i = lval; i <= mid; i++) modify(i, 1);
for (int i = st; i <= ed; i++) {
res = 0; vector<int> :: iterator ite; int x = q[i].id;
for (ite = G[x].begin(); ite != G[x].end(); ++ite) { res += sum(*ite); if (res >= q[i].p) break; }
if (res >= q[i].p) lq[++lt] = q[i];
else q[i].p -= res, rq[++rt] = q[i];
}
for (int i = lval; i <= mid; i++) modify(i, -1);
for (int i = 1; i <= lt; i++) q[st + i - 1] = lq[i];
for (int i = 1; i <= rt; i++) q[st + lt + i - 1] = rq[i];
Div(lval, mid, st, st + lt - 1);
Div(mid + 1, rval, st + lt, ed);
}
int main () {
N = gi(), M = gi();
for (int i = 1; i <= M; i++) G[gi()].push_back(i);
for (int i = 1; i <= N; i++) q[i] = (Node){gi(), i};
K = gi();
for (int i = 1; i <= K; i++) p[i] = (Option){gi(), gi(), gi()};
++K; p[K] = (Option){1, M, 1e9};
Div(1, K, 1, N);
for (int i = 1; i <= N; i++) ans[i] == K ? puts("NIE") : printf("%d\n", ans[i]);
return 0;
}

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

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

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

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

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

  3. 【BZOJ2217】[Poi2011]Lollipop 乱搞

    [BZOJ2217][Poi2011]Lollipop Description 有一个长度为n的序列a1,a2,...,an.其中ai要么是1("W"),要么是2("T& ...

  4. 【BZOJ2525】[Poi2011]Dynamite 二分+树形DP

    [BZOJ2525][Poi2011]Dynamite Description Byteotian Cave的结构是一棵N个节点的树,其中某些点上面已经安置了炸.药,现在需要点燃M个点上的引线引爆所有 ...

  5. 【BZOJ2212】[Poi2011]Tree Rotations 线段树合并

    [BZOJ2212][Poi2011]Tree Rotations Description Byteasar the gardener is growing a rare tree called Ro ...

  6. 【BZOJ2213】[Poi2011]Difference DP

    [BZOJ2213][Poi2011]Difference Description A word consisting of lower-case letters of the English alp ...

  7. 【BZOJ2530】[Poi2011]Party (xia)构造

    [BZOJ2530][Poi2011]Party Description 给定一张N(保证N是3的倍数)个节点M条边的图,并且保证该图存在一个大小至少为2N/3的团. 请输出该图的任意一个大小为N/3 ...

  8. 【BZOJ2216】[Poi2011]Lightning Conductor 决策单调性

    [BZOJ2216][Poi2011]Lightning Conductor Description 已知一个长度为n的序列a1,a2,...,an.对于每个1<=i<=n,找到最小的非负 ...

  9. 【BZOJ2525】[Poi2011]Dynamite(二分,树形dp)

    [BZOJ2525][Poi2011]Dynamite Description Byteotian Cave的结构是一棵N个节点的树,其中某些点上面已经安置了炸.药,现在需要点燃M个点上的引线引爆所有 ...

随机推荐

  1. 如何使用Excel选择整列排序

    在excel中,排序的时候弹窗提示“若要执行此操作,所有合并单元格需大小相同”,该怎么操作才能实现排序呢?接下来,小编就和大家分享具体操作.   工具/原料   excel 方法/步骤     打开出 ...

  2. gluoncv 目标检测,训练自己的数据集

    https://gluon-cv.mxnet.io/build/examples_datasets/detection_custom.html 官方提供两种方案,一种是lst文件,一种是xml文件(v ...

  3. libconfig C++ 学习笔记

    1. C++API 头文件 #include <libconfig.h++> ,命名空间:using namespace libconfig; 2.多线程使用问题: (1)libconfi ...

  4. zabbix安装(网络)

    https://www.zabbix.com/documentation/3.4/zh/manual/quickstart/login   zabbix安装官网 https://www.zabbix. ...

  5. Docker创建镜像文件并在容器中运行

    1.如何创建镜像文件 首先找到Docker ToolBox安装的路径,在路径下直接新建Dockerfile文件 在Dockerfile文件里写入的内容为: FROM docker/whalesay:l ...

  6. HTMLFormElement获取表单里面所有的值然后以json形式返回

    function HTMLFormElement(){ this.init(); return this.json; } HTMLFormElement.prototype.init = functi ...

  7. 清除IE8/IE9/IE10/IE11浏览器缓存文件 100%有效

    不管你是哪个版本的IE浏览器,按照下面指示操作,都能清除掉你使用浑身解数也清不掉的缓存文件! 第一步,打开IE浏览器——工具——Internet选项 有的IE浏览器的Internet选项藏在右上角一个 ...

  8. STM32F103 ucLinux开发之一(BOOT分析及源码)

    STM32F103 ucLinux开发BOOT STM3210E-EVAL官方开发板主芯片STM32F103ZET6: 片内512K Flash,地址0x0800 0000 ~ 0x0807 FFFF ...

  9. 设计一个方法injectBeforeAsyncSend,能够实现如下功能:在发起异步请求之前打印出请求的类型、URL、method、body、timestamp 等信息。

    异步请求逻辑注入 工作中我们需要对异步请求的请求信息打印日志,但是又不能耦合在业务代码中打印.请设计一个方法injectBeforeAsyncSend,能够实现如下功能:在发起异步请求之前打印出请求的 ...

  10. OC之block 和协议

    一.BOLCK (一)简介 BLOCK是什么?苹果推荐的类型,效率高,在运行中保存代码.用来封装和保存代码,有点像函数,BLOCK可以在任何时候执行. BOLCK和函数的相似性:(1)可以保存代码(2 ...