Luogu 3586 [POI2015]LOG
考虑离散化后开权值线段树。
设序列中不小于$s$的数有$cnt$个,小于$s$的数的和为$sum$。
那么操作Z能成功的充要条件是$sum \geq (c - cnt) * s$。
如果序列中不小于$s$的数超过了$c$个,那么直接每一次都选这些数就好了。
如果没有超过$c$个的话,这$cnt$个数每一次都要选,然后再贪心地取剩下的数中最大的就行了。
需要把询问中出现的$a, s$和$0$一起离散化。
细节没想清楚WA好久
膜Claris
Code:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll; const int N = 1e6 + ;
const int inf = << ; int n, qn, tot = , maxn = , a[N];
ll b[N << ]; struct Querys {
int type, x, y;
} q[N]; struct Innum {
int val, id;
} in[N << ]; bool cmp(const Innum &x, const Innum &y) {
if(x.val != y.val) return x.val < y.val;
else return x.id < y.id;
} inline int max(int x, int y) {
return x > y ? x : y;
} inline void read(int &X) {
X = ;
char ch = ;
int op = ;
for(; ch > '' || ch < ''; ch = getchar())
if(ch == '-') op = -;
for(; ch >= '' && ch <= ''; ch = getchar())
X = (X << ) + (X << ) + ch - ;
X *= op;
} inline void discrete() {
in[].val = -inf;
sort(in + , in + + tot, cmp);
for(int cnt = , i = ; i <= tot; i++) {
if(in[i].val != in[i - ].val) cnt++;
maxn = max(maxn, cnt);
b[cnt] = in[i].val;
q[in[i].id].y = cnt;
}
} namespace SegT {
ll s[N << ];
int cnt[N << ]; #define lc p << 1
#define rc p << 1 | 1
#define mid ((l + r) >> 1) inline void up(int p) {
if(p) {
s[p] = s[lc] + s[rc];
cnt[p] = cnt[lc] + cnt[rc];
}
} void modify(int p, int l, int r, int x, int v) {
if(x == l && r == x) {
s[p] += (ll)b[l] * v;
cnt[p] += v;
return;
} if(x <= mid) modify(lc, l, mid, x, v);
else modify(rc, mid + , r, x, v);
up(p);
} ll qSum(int p, int l, int r, int x, int y) {
if(x > y) return 0LL;
if(x <= l && y >= r) return s[p]; ll res = 0LL;
if(x <= mid) res += qSum(lc, l, mid, x, y);
if(y > mid) res += qSum(rc, mid + , r, x, y);
return res;
} int qCnt(int p, int l, int r, int x, int y) {
// if(x > y) return 0;
if(x <= l && y >= r) return cnt[p]; int res = ;
if(x <= mid) res += qCnt(lc, l, mid, x, y);
if(y > mid) res += qCnt(rc, mid + , r, x, y);
return res;
} } using namespace SegT; int main() {
read(n), read(qn);
in[++tot] = (Innum) {, };
for(int i = ; i <= qn; i++) {
char op[]; scanf("%s", op);
read(q[i].x), read(q[i].y);
if(op[] == 'U') q[i].type = , in[++tot] = (Innum) {q[i].y, i};
else q[i].type = , in[++tot] = (Innum) {q[i].y, i};
} discrete(); /* for(int i = 1; i <= maxn; i++)
printf("%lld ", b[i]);
printf("\n");
for(int i = 1; i <= qn; i++)
printf("%d %d %d\n", q[i].type, q[i].x, q[i].y);
printf("\n"); */ for(int i = ; i <= n; i++)
a[i] = , modify(, , maxn, , ); for(int i = ; i <= qn; i++) {
if(q[i].type == ) {
modify(, , maxn, a[q[i].x], -);
modify(, , maxn, q[i].y, );
a[q[i].x] = q[i].y;
} else {
int cnt = qCnt(, , maxn, q[i].y, maxn);
/* if(cnt >= q[i].x) {
puts("TAK");
continue;
} */
ll sum = qSum(, , maxn, , q[i].y - );
if(sum >= (q[i].x - cnt) * b[q[i].y]) puts("TAK");
else puts("NIE");
}
} return ;
}
Luogu 3586 [POI2015]LOG的更多相关文章
- [POI2015]LOG(树状数组)
今天考试考了这题,所以来贡献\([POI2015]LOG\)的第一篇题解.代码略丑,调了快三个小时才调出来\(AC\)代码. 对于这种小清新数据结构题,所以我觉得树状数组才是这道题的正确打开方式. 首 ...
- luogu P3592 [POI2015]MYJ
题目链接 luogu P3592 [POI2015]MYJ 题解 区间dp 设f[l][r][k]表示区间l到r内最小值>=k的最大收益 枚举为k的位置p,那么包含p的区间答案全部是k 设h[i ...
- 树状数组【洛谷P3586】 [POI2015]LOG
P3586 [POI2015]LOG 维护一个长度为n的序列,一开始都是0,支持以下两种操作:1.U k a 将序列中第k个数修改为a.2.Z c s 在这个序列上,每次选出c个正数,并将它们都减去1 ...
- 洛谷 P3586 [POI2015]LOG
P3586 [POI2015]LOG 题目描述 维护一个长度为n的序列,一开始都是0,支持以下两种操作:1.U k a 将序列中第k个数修改为a.2.Z c s 在这个序列上,每次选出c个正数,并将它 ...
- BZOJ 4386 Luogu P3597 [POI2015]Wycieczki (矩阵乘法)
题目链接: (bzoj) https://www.lydsy.com/JudgeOnline/problem.php?id=4386 (luogu) https://www.luogu.org/pro ...
- BZOJ4377 Kurs szybkiego czytania \ Luogu 3589[POI2015]KUR - 数学思维题
Solution 我又双叒叕去看题解啦$QAQ$, 真的想不到鸭 输入 $a$ 和 $n$ 互质, 所以满足 $a \times i \ mod \ n$ $(0<=i<n)$ 肯定是不重 ...
- 洛谷P3586 [POI2015]LOG(贪心 权值线段树)
题意 题目链接 Sol 显然整个序列的形态对询问没什么影响 设权值\(>=s\)的有\(k\)个. 我们可以让这些数每次都被选择 那么剩下的数,假设值为\(a_i\)次,则可以\(a_i\)次被 ...
- [POI2015]LOG
题目 发现询问是针对整个区间,也就是说位置什么用都没有 发现我们需要构造出\(s\)个长度为\(c\)的数列,每个数只能在一个数列中出现一次,且一个数最多的使用次数是其大小 对于那些大于等于\(s\) ...
- Luogu 3594 [POI2015]WIL-Wilcze doły
简单题. 考虑没有修改数字的条件的限制,我们直接用双指针扫描就可以计算出答案了. 然后考虑加入修改数字的条件,只要用单调队列维护出当前两个指针表示的区间中长度为$d$的一段区间的最大值,用总和减掉这个 ...
随机推荐
- UVA - 11014 Make a Crystal (莫比乌斯反演)
给定一个n*n*n的立方体(中心点为原点O),选择尽量多的点,使得对于任意两点A,B,B不在线段OA上. 可以发现,原问题可转化为三维坐标下的点(x,y,z)中有多少个点的gcd(x,y,z)=1. ...
- Web打印的处理 方案之普通报表打印
做过许多 的Web项目,大多数在打印页面内容的时刻 ,采用的都是议决 Javascript调用系统内置的打印要领 执行 打印,也就是调用 PrintControl.ExecWB(?,?)实现直接打印和 ...
- Python函数-callable()
callable(object) 作用: 检查对象object是否可调用.如果返回True,object仍然可能调用失败:但如果返回False,调用对象ojbect绝对不会成功. 注意: 类是可调用的 ...
- angular.run 妙用
**1.浏览器判断**在angular做微信应用的时候,有时候我们也想把相同一份代码运行在非微信的浏览器上,这时候我们可以在angular的run上写点东西实现~例如asw.run函数里执行定义一个$ ...
- Nexus安装以及2,3比较
解压缩之后, 进入nexus-3.6.2-01/bin文件夹中,执行: ./nexus start 如果使用root将会得到一个告警:Detected execution as "root& ...
- MyEclipse启动tomcat增加内存配置
omcat增加内存在catalina.bat下 MyEclipse增加内存 设置Window->Preferences->Application Servers->Tomcat -- ...
- Jmeter & TICK
背景: 本来只是想在将Jmeter的测试结果写入InfluxDB, 但发现从InfluxDB V1.3后开始, 已经不支持Web Admin interface, 才发现InfluxData 搞了 ...
- Spring之3:BeanFactory、ApplicationContext、ApplicationContextAware区别
在Spring中系统已经为用户提供了许多已经定义好的容器实现,而不需要开发人员事必躬亲.相比那些简单拓展BeanFactory的基本IoC容器,开发人员常用的ApplicationContext除了能 ...
- PV 和 UV IP
PV(page view),即页面浏览量,或点击量;通常是衡量一个网络新闻频道或网站甚至一条网络新闻的主要指标. 高手对pv的解释是,一个访问者在24小时(0点到24点)内到底看了你网站几个页面.这里 ...
- Java 8新增的日期、时间格式器
一 获取DateTimeFormatter对象的三种方式 直接使用静态常量创建DateTimeFormatter格式器 使用代码不同风格的枚举值来创建DateTimeFormatter格式器 根据模式 ...