bzoj 4378: [POI2015]Logistyka ——树桩数组+离散化
Description
维护一个长度为n的序列,一开始都是0,支持以下两种操作:
1.U k a 将序列中第k个数修改为a。
2.Z c s 在这个序列上,每次选出c个正数,并将它们都减去1,询问能否进行s次操作。
每次询问独立,即每次询问不会对序列进行修改。
Input
第一行包含两个正整数n,m(1<=n,m<=1000000),分别表示序列长度和操作次数。
接下来m行为m个操作,其中1<=k,c<=n,0<=a<=10^9,1<=s<=10^9。
Output
包含若干行,对于每个Z询问,若可行,输出TAK,否则输出NIE。
Sample Input
U 1 5
U 2 7
Z 2 6
U 3 1
Z 2 6
U 2 2
Z 2 6
Z 2 1
Sample Output
TAK
NIE
TAK
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
const int M=2e6+;
using std::sort;
using std::unique;
using std::lower_bound;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int n,m;
char c[M][];
struct pos{LL x,w,s;}q[M];
int x[M],cnt,v[M],last[M];
LL s[M],w[M];//sÊÇÇóÓжàÉÙ¸öÊý±ÈÎҴ󣨺ó׺£© wÊÇÇó±ÈÎÒСµÄÊýµÄºÍ£¨Ç°×º£©
#define lowbit(x) x&-x
void ins_s(int x,int v){while(x) s[x]+=v,x-=lowbit(x);}
LL query_s(int x){LL sum=; while(x<=cnt) sum+=s[x],x+=lowbit(x); return sum;}
void ins_w(int x,int v){while(x<=cnt) w[x]+=v,x+=lowbit(x);}
LL query_w(int x){LL sum=; while(x) sum+=w[x],x-=lowbit(x); return sum;}
int main(){
n=read(); m=read();
for(int i=;i<=m;i++){
scanf("%s",c[i]);
q[i].x=read(); q[i].w=read();
x[++cnt]=q[i].w;
}
sort(x+,x++cnt); cnt=unique(x+,x++cnt)-x-;
for(int i=;i<=m;i++) q[i].s=lower_bound(x+,x++cnt,q[i].w)-x;
for(int i=;i<=m;i++){
if(c[i][]=='U'){
if(last[q[i].x]) ins_s(last[q[i].x],-),ins_w(last[q[i].x],-v[q[i].x]);
last[q[i].x]=q[i].s; v[q[i].x]=q[i].w;
ins_s(last[q[i].x],); ins_w(last[q[i].x],v[q[i].x]);
}
else{
LL ly=,k=query_s(q[i].s);
if(q[i].s->) ly=query_w(q[i].s-);
if((q[i].x-k)*q[i].w<=ly) printf("TAK\n");
else printf("NIE\n");
}
}
return ;
}
bzoj 4378: [POI2015]Logistyka ——树桩数组+离散化的更多相关文章
- @bzoj - 4378@ [POI2015] Logistyka
目录 @description@ @solution@ @accepted code@ @details@ @description@ 维护一个长度为 n 的序列,一开始都是 0,支持以下两种操作: ...
- @bzoj - 4378@ [POI2015] Pustynia
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个长度为 n 的正整数序列 a,每个数都在 1 到 10^ ...
- 【BZOJ4378】[POI2015]Logistyka 树状数组
[BZOJ4378][POI2015]Logistyka Description 维护一个长度为n的序列,一开始都是0,支持以下两种操作:1.U k a 将序列中第k个数修改为a.2.Z c s 在这 ...
- D - Nested Segments CodeForces - 652D (离散化+树桩数组)
D - Nested Segments CodeForces - 652D You are given n segments on a line. There are no ends of some ...
- bzoj 4386: [POI2015]Wycieczki
bzoj 4386: [POI2015]Wycieczki 这题什么素质,爆long long就算了,连int128都爆……最后还是用long double卡过的……而且可能是我本身自带大常数吧,T了 ...
- hdu4605 树状数组+离散化+dfs
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- BZOJ_5055_膜法师_树状数组+离散化
BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...
- [POI2015]Logistyka
[POI2015]Logistyka 题目大意: 一个长度为\(n(n\le10^6)\)的数列\(A_i\),初始全为\(0\).操作共\(m(m\le10^6)\)次,包含以下两种: 将\(A_x ...
- nyoj117——树状数组升级版(树状数组+离散化)
求逆序数 时间限制:2000 ms | 内存限制:65535 KB 难度:5 描述 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中 ...
随机推荐
- lintcode-173-链表插入排序
173-链表插入排序 用插入排序对链表排序 样例 Given 1->3->2->0->null, return 0->1->2->3->null 标签 ...
- ssl证书验证的问题
对于https请求,是需要ssl证书验证的请求的,所以如果在请求时如果不带ssl证书,那么可以忽略证书的验证 有三种方法去实现: 1.Requests请求: 在文档中可以看到:http://docs. ...
- 3dContactPointAnnotationTool开发日志(二二)
昨天是实现了显示GameObject子GameObject的选项卡功能,今天就是要让statusPanel可以控制它们的位置.旋转和缩放了. 没什么难的,对应选项卡绑定上对应的物体或子物体即可 ...
- C# lamda表达式
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 加密和数字签名工具GPG
转载: 源文件位置:http://blog.chinaunix.net/uid-9525959-id-2001824.html GPG [功能] GPG是加密和数字签名的免费工具,大多用于加密信息的 ...
- java-实用的sql语句
一.在数据库创建表格的SQL语句 1,创建一个link表格,包含属性:lid 主键,title 标题, imgpath 图片地址 , url 网址 , info 说明, isshow 显示1 ...
- 修改MSSQL字段类型
update Data_Project set SyncTime=NULL; alter table Data_Project alter column SyncTime datetime; upda ...
- DELPHI的MEMO组件
位于Standard选项卡上,它是对EDIT控件的扩展,可以对多行文本进行显示.输入 和编辑. Lines属性: 该属性实际上为TStrings类型的对象,用来存放Memo对象的文本 TStrings ...
- html5 js canvas中画星星的函数
function drawStar(cxt, x, y, outerR, innerR, rot) { cxt.beginPath(); ; i < ; i++) { cxt.lineTo(Ma ...
- RT-thread内核之邮箱
一.邮箱控制块:在include/rtdef.h中 #ifdef RT_USING_MAILBOX /** * mailbox structure */ struct rt_mailbox { str ...