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$的一段区间的最大值,用总和减掉这个 ...
随机推荐
- hdoj-3791-二叉搜索树(二叉搜索树模板题)
#include <cstring> #include <cstdio> #include <iostream> using namespace std; type ...
- 利用HTML5开发Android笔记(上篇)
资源来自于www.mhtml5.com 杨丰盛老师成都场的PPT分享 一个很简明的demo 可以作为入门基础 学习的过程中做了点笔记 整理如下 虽然内容比较简单 但是数量还是比较多的 所以分了3篇 ( ...
- Tomcat设计模式分析(转) 2
Tomcat 系统架构与设计模式,第 2 部分: 设计模式分析 这个分为两个部分的系列文章研究了 Apache Tomcat 服务器的系统架构以及其运用的很多经典设计模式.第 1 部分 分析了 Tom ...
- [转]NME Android目标中文输入问题完美解决!
最近研究了一下haxe,发现蛮牛逼的,转几篇知识帖 haXe开发笔记:中文问题的小结 * .hx源文件中如果包含中文,要保存成UTF-8编码才能够正确被haXe编译器解析,是否包含BOM(Byte O ...
- 常用Kerberos指令
1. 以超管身份进入kadminkadmin.local addprinc -randkey root/master1@JENKIN.COM //生成随机key的principal addprin ...
- WPF基本概念入门
关于数据类型,有原子类型,列表类型,字典类型等等,而wpf对应控件有contentControl,itemsControl,headerItemsControl等. 控件和类型一一对应,控件和类型之间 ...
- 通过Azure File Service搭建基于iscsi的共享盘
在Azure上目前已经有基于Samba协议的共享存储了. 但目前在Azure上,还不能把Disk作为共享盘.而在实际的应用部署中,共享盘是做集群的重要组件之一.比如仲裁盘.Shared Disk等. ...
- hihoCoder#1050(树中最长路)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中,小Ho发现他不仅仅可以拼凑成一 ...
- Doubango简介-sip
Welcome Android http://code.google.com/p/imsdroid/ http://code.google.com/p/imsdroid/source/browse/# ...
- 2016.5.30让窗口处于最顶层的方法,比TopMost灵活
最简单的方法Form. Activate() 稍复杂的方法用API,目前没有看出比第一种方法有什么好处(可操作其它窗口,这就是好处2016.7.31) [System.Runtime.InteropS ...