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希望可以帮妈妈分担一些工 作,作为她的生日礼 ...
随机推荐
- 获取json对象长度的问题
平时,我们获取一些字符串或数组的长度的时候会使用length,例如: var str ="asdasd" console.log(str.length) //输出6 var arr ...
- QQ聊天机器人for PHP版 (登录,收、发消息)
<?php include "http_no_cookie.class.php"; class qq { public $sid; public $http; public ...
- Visual C++2010开发权威指南 中文高清PDF - VC.NET
第一部分 Visual C++ 2010开发与新特性第1章 Visual C++ 2010开发环境简介 11.1 Visual C++ 2010简介 11.2 Visual C++ 2010下 ...
- 【socket】一分钟理清 socket udpsocket tcpsocket tcplistener TCPClient和 UDPClient
socket 套接字接口是各种语言tcp udp的网络操作的基础. 直接用socket 对象开发 可以选择 udpsocket 或者 tcpsocket ,两者在使用上仅一些方法和参数不同,所有的底 ...
- 懒惰的JY--关于遍历
先上题: [问题描述] 众所周知,JY的百度搜索算法已经练的炉火纯青,任何搜索题都能0.000ms出解. 不幸的是,JY遇到了一道百度搜索算法解决不了的题目,题目是这样的: 给定N个数A[1] A[2 ...
- 【BZOJ 1202】 [HNOI2005]狡猾的商人
Description 刁姹接到一个任务,为税务部门调查一位商人的账本,看看账本是不是伪造的.账本上记录了n个月以来的收入情况,其中第i 个月的收入额为Ai(i=1,2,3...n-1,n), .当 ...
- 【BZOJ 1791】 [Ioi2008]Island 岛屿
Description 你将要游览一个有N个岛屿的公园.从每一个岛i出发,只建造一座桥.桥的长度以Li表示.公园内总共有N座桥.尽管每座桥由一个岛连到另一个岛,但每座桥均可以双向行走.同时,每一对这样 ...
- 扫盲Linq知识
LINQ,语言集成查询(Language Integrated Query),是在.NET Framework 3.5 中出现的技术. 借助于LINQ技术,我们可以使用一种类似SQL的语法来查询任何形 ...
- spoj 24
大数 #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> ...
- 在WIN32 DLL中使用MFC库遇到的问题
今天写了一个DLL,DLL中用到的一个类里用到的MSXML的COM组件,所以在DLL中要包含afx.h头文件,也就不可避免的要用到MFC的类库了,但在编译时出现了错误:mfcs42d.lib(dllm ...