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希望可以帮妈妈分担一些工 作,作为她的生日礼 ...
随机推荐
- 1087. All Roads Lead to Rome (30)
时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Indeed there are many different ...
- EXTJS store 某行某列数据更新等操作
1.可以使用add(Ext.data.Record[] records)或者add(Ext.data.Record record)向store末尾添加一个或多个record.如: var newRec ...
- P3381: [Usaco2004 Open]Cave Cows 2 洞穴里的牛之二
这题..思维上远没有上一题复杂,是一个裸的RMQ..利用倍增就可以解决了. var n,q,i,j,f,t,c:longint; a:array[..,..] of longint; function ...
- sharepoint 2010 masterpage中必须的Content PlaceHolder
Professional SharePoint 2010 Branding and Use
- APP中数据加载的6种方式-b
我们看到的APP,往往有着华丽的启动界面,然后就是漫长的数据加载等待,甚至在无网络的时候,整个处于不可用状态.那么我们怎么处理好界面交互中的加载设计,保证体验无缝衔接,保证用户没有漫长的等待感,而可以 ...
- 企业应用的Web程序的安全性
提起安全性这个话题,大家恐怕依稀还记得Sony的PSP账户信息泄露的事故造成的重大损失.但是又隐隐觉得这事儿离我很远,无需过多考虑.也有的人会想,我们做的是企业内部系统所以不必太在意.但是,Web程序 ...
- 深入理解SQL注入绕过WAF与过滤机制
知己知彼,百战不殆 --孙子兵法 [目录] 0x0 前言 0x1 WAF的常见特征 0x2 绕过WAF的方法 0x3 SQLi Filter的实现及Evasion 0x4 延伸及测试向量示例 0x5 ...
- Akka Stream文档翻译:Quick Start Guide: Reactive Tweets
Quick Start Guide: Reactive Tweets 快速入门指南: Reactive Tweets (reactive tweets 大概可以理解为“响应式推文”,在此可以测试下GF ...
- python中unicode、utf8、gbk等编码问题
转自:http://luchanghong.com/python/2012/07/06/python-encoding-with-unicode-and-gbk-and-utf8.html 概要:编码 ...
- 如何让WIN32应用程序支持MFC类库
参考链接:http://wenku.baidu.com/view/68fc340c79563c1ec5da714b.html