【题目链接】

http://www.lydsy.com/JudgeOnline/problem.php?id=1058

【题意】

一个序列,提供插入,查询相邻最小差值,查询任意最小差值的操作。

【思路】

Set

用两个set,listed装所有的相邻差值,sorted装所有的数。然后用front[x],last[x]记录位置x上开始和结束的数。

对于Insert,维护listed:删除front[x+1]与last[x]的差值并插入两个新的差值,插入sorted后与前一个后一个作差更新答案。

【代码】

 #include<cmath>
#include<set>
#include<cstdio>
#include<cstring>
#include<iostream>
#define ite multiset<int>::iterator
using namespace std; typedef long long ll;
const int N = 3e6+; multiset<int> sorted,listed; int n,m,tomin;
int last[N],front[N]; ll read() {
char c=getchar();
ll f=,x=;
while(!isdigit(c)) {
if(c=='-') f=-; c=getchar();
}
while(isdigit(c))
x=x*+c-'',c=getchar();
return x*f;
}
int abs(int x) { return x<? -x:x; } int main()
{
n=read(); m=read();
tomin=1e9;
for(int i=;i<=n;i++) {
front[i]=read();
last[i]=front[i];
sorted.insert(front[i]);
if(i!=) listed.insert(abs(front[i]-front[i-]));
}
ite l;
for(ite r=sorted.begin();r!=sorted.end();r++) {
if(r!=sorted.begin())
tomin=min(tomin,abs(*r-*l));
l=r;
}
char op[]; int x,y;
while(m--) {
scanf("%s",op);
if(op[]=='I') {
x=read(),y=read();
ite it=sorted.insert(y);
if(it!=sorted.begin())
--it , tomin=min(tomin,abs(y-*it)) , ++it;
if(it!=sorted.end())
++it , tomin=min(tomin,abs(*it-y)) , --it;
it=listed.find(abs(front[x+]-last[x]));
listed.erase(it);
listed.insert(abs(y-front[x+]));
listed.insert(abs(y-last[x]));
last[x]=y;
} else
if(strlen(op)==) {
printf("%d\n",*listed.begin());
} else {
printf("%d\n",tomin);
}
}
return ;
}

bzoj 1058 [ZJOI2007]报表统计(set)的更多相关文章

  1. BZOJ 1058: [ZJOI2007]报表统计( 链表 + set )

    这种题用数据结构怎么写都能AC吧...按1~N弄个链表然后每次插入时就更新答案, 用set维护就可以了... --------------------------------------------- ...

  2. bzoj 1058: [ZJOI2007]报表统计 (Treap)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1058 题面; 1058: [ZJOI2007]报表统计 Time Limit: 15 Sec ...

  3. [BZOJ 1058] [ZJOI2007] 报表统计 【平衡树】

    题目链接:BZOJ - 1058 题目分析 这道题看似是需要在序列中插入一些数字,但其实询问的内容只与相邻的元素有关. 那么我们只要对每个位置维护两个数 Ai, Bi, Ai 就是初始序列中 i 这个 ...

  4. bzoj 1058: [ZJOI2007]报表统计

    Description 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工 作,作为她的生日礼物之一.经过仔细观察,小Q发现统计一张报表实际上是维护一个 ...

  5. BZOJ 1058: [ZJOI2007]报表统计 multiset + 卡常

    Code: #include<bits/stdc++.h> #define maxn 600000 #define inf 1000000000 using namespace std; ...

  6. bzoj 1058: [ZJOI2007]报表统计【set】

    我想写FHQtreap的!是set自己跑进代码的!因为太好写了 是有点慢--洛谷上不吸氧会T一个点 就是,用一个set p维护所有点值,ans维护MIN_SORT_GAP的答案,每次insert一个点 ...

  7. bzoj P1058 [ZJOI2007]报表统计——solution

    1058: [ZJOI2007]报表统计 Time Limit: 15 Sec  Memory Limit: 162 MB Submit: 4099  Solved: 1390 [Submit][St ...

  8. 【BZOJ】1058: [ZJOI2007]报表统计(splay+set)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1058 当复习一下splay.... 做法很简单..... 观察得知每一次插入一个点只需要维护前后的绝 ...

  9. 1058: [ZJOI2007]报表统计 - BZOJ

    Description 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工作,作为她的生日礼物之一.经过仔细观察,小Q发现统计一张报表实际上是维护一个非 ...

随机推荐

  1. 1058-Tom and Jerry

    描述 Tom和Jerry在10*10的方格中: *...*..... ......*... ...*...*.. .......... ...*.C.... *.....*... ...*...... ...

  2. [Ruby on Rails系列]4、专题:Rails应用的国际化[i18n]

    1. 什么是internationalization(i18n)? 国际化,英文简称i18n,按照维基百科的定义:国际化是指在设计软件,将软件与特定语言及地区脱钩的过程.当软件被移植到不同的语言及地区 ...

  3. Mybatis代码生成器 xml配置文件 连接SQL SERVER 2005

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguratio ...

  4. Android 控制ScrollView滚动到底部

    scrollView.fullScroll(ScrollView.FOCUS_DOWN);滚动到底部 scrollView.fullScroll(ScrollView.FOCUS_UP);滚动到顶部 ...

  5. C语言一维数组中的数据随机排列

    #include <stdio.h>#include <stdlib.h> void randomlize(int *a, int n){        int i = 0,j ...

  6. git log

    http://git-scm.com/book/zh/v2 https://backlogtool.com/git-guide/tw/contents/     http://gitbook.liuh ...

  7. 武汉北大青鸟解读2016年10大IT热门岗位

    武汉北大青鸟解读2016年10大IT热门岗位 2016年1月5日 13:37 北大青鸟 这是IT从业者的辉煌时代,IT行业的失业率正处在历史的低点,而且有的岗位——例如网络和安全工程师以及软件开发人员 ...

  8. 8款必备的免费移动Web开发框架(HTML5/JS)

    标签:JavaScript HTML5 移动开发 Web开发 jQuery 应用程序框架 插件 概述:随着智能手机和平板电脑的普及,移动开发逐渐成为众多开发者追逐的潮流.拥有一款优秀的移动Web开发框 ...

  9. struts2启动报错com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1

    好久没有搞struts2,今天配置strut2.2.1,启动时遇到个小问题.记录下. tomcat启动报错: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

  10. 大四实习准备2_java异常处理_android控件练习

    2015-4-24 Java 异常处理 可以有多个catch;ArrayIndexOutOfBoundsException类是Exception类的子类RuntimeException类的一个间接子类 ...