bzoj1058: [ZJOI2007]报表统计
set。操作:insert(u,v)在u后面插入v,若u后面已插入过,在插入过的后面插入。mingap求出序列两两之间差值的最小值。minsortgap求出排序后的序列两两之间的最小值。用multiset维护就可以了。忽略了新插入的数对于mingap的影响WA了一次。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
int read(){
int x=0;char c=getchar();bool f=true;
while(!isdigit(c)) {
if(c=='-') f=false;c=getchar();
}
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return f?x:-x;
}
const int nmax=500005;
const int inf=0x7f7f7f7f;
int a[nmax],last[nmax];
char s[20];
multiset<int>S,T;
int as(int x){
return x<0?-x:x;
}
int main(){
int n=read(),m=read();
rep(i,1,n) a[i]=read(),last[i]=a[i],S.insert(a[i]);
S.insert(-inf);S.insert(inf); int smin=inf;
set<int>::iterator it;
set<int>::iterator tmp;
for(it=S.begin();it!=S.end();it++){
if(it!=S.begin()) smin=min(smin,*it-*tmp);
tmp=it;
} rep(i,2,n) T.insert(as(a[i]-a[i-1])); set<int>::iterator first;
set<int>::iterator second;
while(m--){
scanf("%s",s);
if(s[0]=='I'){
int u=read(),v=read();
it=T.find(as(a[u+1]-last[u]));
T.erase(it);T.insert(as(v-last[u]));T.insert(as(a[u+1]-v));
last[u]=v; it=S.insert(v);first=--it;++it;second=++it;--it;
smin=min(smin,min(v-*first,*second-v));
}else if(s[4]=='G') printf("%d\n",*T.begin());
else printf("%d\n",smin);
}
return 0;
}
ps:set用法
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
set<int>s;
int main(){
int n=read();
for(int i=1;i<=n;i++) {
int tmp=read();s.insert(tmp);
}
set<int>::iterator it;
for(it=s.begin();it!=s.end();it++)
printf("%d\n",*it);
printf("%d\n",*s.begin());
printf("%d\n",*s.end());
printf("%d\n",s.size());
printf("%d\n",s.count(2));//0/1
printf("%d\n",s.count(5));
s.clear();
if(s.empty()) printf("Orzzzzzz\n"); printf("erase operator\n");
set<int>::iterator first;
set<int>::iterator second;
for(int i=1;i<=10;i++) s.insert(i);
first=s.begin();second=s.begin();second++;second++;
s.erase(first, second);s.erase(s.begin());s.erase(7);
for(it=s.begin();it!=s.end();it++)
printf("%d\n",*it); printf("find operator\n");
s.clear();
for(int i=1;i<=10;i++) s.insert(i);
if((it=s.find(5))!=s.end()) printf("%d\n",*it);//qaq what function
printf("%d\n",*(++it)); printf("wzc operator\n");
printf("%d\n",*s.lower_bound(3));
printf("%d\n",*s.upper_bound(3));
return 0;
}
1058: [ZJOI2007]报表统计
Time Limit: 15 Sec Memory Limit: 162 MB
Submit: 2815 Solved: 968
[Submit][Status][Discuss]
Description
Input
Output
对于每一个“MIN_GAP”和“MIN_SORT_GAP”命令,输出一行答案即可。
Sample Input
5 3 1
INSERT 2 9
MIN_SORT_GAP
INSERT 2 6
MIN_GAP
MIN_SORT_GAP
Sample Output
2
1
HINT
N , M ≤500000 对于所有的数据,序列内的整数不超过5*10^8。
Source
bzoj1058: [ZJOI2007]报表统计的更多相关文章
- BZOJ1058: [ZJOI2007]报表统计(set)
Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 4190 Solved: 1420[Submit][Status][Discuss] Descript ...
- bzoj1058: [ZJOI2007]报表统计 stl xjbg
小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工作,作为她的生日礼物之一.经过仔细观察,小Q发现统计一张报表实际上是维护一个可能为负数的整数数列,并且 ...
- BZOJ1058:[ZJOI2007]报表统计(Splay,堆)
Description 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工 作,作为她的生日礼物之一.经过仔细观察,小Q发现统计一张报表实际上是维护一个 ...
- [bzoj1058][ZJOI2007][报表统计] (STL)
Description 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工 作,作为她的生日礼物之一.经过仔细观察,小Q发现统计一张报表实际上是维护一个 ...
- 【set】【multiset】bzoj1058 [ZJOI2007]报表统计
对n个位置,每个位置维护一个vector. 每次插入,可能对MIN_SORT_GAP产生的影响,只可能是 插入元素 和 它的 前驱 后继 造成的,用一个set维护(存储所有序列中的元素). 我们还得维 ...
- 【BZOJ1058】[ZJOI2007]报表统计 STL
[BZOJ1058][ZJOI2007]报表统计 Description 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工作,作为她的生日礼物之一.经 ...
- BZOJ 1058: [ZJOI2007]报表统计( 链表 + set )
这种题用数据结构怎么写都能AC吧...按1~N弄个链表然后每次插入时就更新答案, 用set维护就可以了... --------------------------------------------- ...
- [补档][ZJOI2007] 报表统计
[ZJOI2007] 报表统计 题目 传送门 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工作,作为她的生日礼物之一. 经过仔细观察,小Q发现统计一 ...
- BZOJ_1058_[ZJOI2007]报表统计_STL
BZOJ_1058_[ZJOI2007]报表统计_STL Description 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工 作,作为她的生日礼 ...
随机推荐
- lnmp全面优化集合nginx+mysql+php
lnmp的全名是linux+nginx+mysql+php,既然是全面优化那我们就从linux系统的选择入手.debian系统可以算是 linux各分支中做的比较突出的一类,连谷歌都抛弃linux订制 ...
- hadoop中遇到的问题。
1.物理主机中无法访问管理界面,在虚拟主机中可以访问, 这跟防火墙有关系,重启一下防火墙,然后关闭,最后重启一下handoop,应该就可以了!!!!(hadoop首战顺利!!!!!(●'◡'●))
- WPF简单的口算案例
前几天在博客园,看到有博友利用Winform做了一个口算案例,于是我想把它移植在WPF程序中.Winform程序:http://www.cnblogs.com/ImYZF/p/3345452.html ...
- jquery pass parameter to ajax callback
$('.del').on('click', function () { var id = $(this).attr('id'); var url = '/m/g2_content_del/' + id ...
- hdu 4717 The Moving Points(第一个三分题)
http://acm.hdu.edu.cn/showproblem.php?pid=4717 [题意]: 给N个点,给出N个点的方向和移动速度,求每个时刻N个点中任意两点的最大值中的最小值,以及取最小 ...
- 企业应用的Web程序的安全性
提起安全性这个话题,大家恐怕依稀还记得Sony的PSP账户信息泄露的事故造成的重大损失.但是又隐隐觉得这事儿离我很远,无需过多考虑.也有的人会想,我们做的是企业内部系统所以不必太在意.但是,Web程序 ...
- Does not contain a valid host:port authority: Master:8031 (configuration property 'yarn.resourcemanager.resource-tracker.address')
问题解决: 这个错误是:yarn里面的配置的格式有错误:如: <property> <name>yarn.resourcemanager.address</name> ...
- sentos 上安装vnc图形界面
一.安装gnome图形化桌面 CentOS 6.3 64位 #yum groupinstall -y "X Window System" #yum groupinstall - ...
- 解决eclipse复制粘贴js代码卡死的问题
鸣谢:http://blog.csdn.net/zhangzikui/article/details/24805935 ---------------------------------------- ...
- zoj 3725
题意: n个格子排成一条直线,可以选择涂成红色或蓝色,问最少 m 个连续为红色的方案数. 解题思路: 应该是这次 ZOJ 月赛最水的一题,可惜还是没想到... dp[i] 表示前 i 个最少 m 个连 ...