【题目链接】

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. uva 10827

    与108类似 多加了两层循环 水过 #include <iostream> #include <cstring> #include <cstdio> #includ ...

  2. 如何在Ubuntu下搭建Android NDK开发环境

    1 搭建Android SDK开发环境 参考在在Ubuntu下搭建Android SDK开发环境(图文)首先在Ubuntu下搭建Android SDK开发环境. 2 下载NDK开发包 打开官网: ht ...

  3. 转--利用函数模板技术,写一个简单高效的 JSON 查询器

    http://www.cnblogs.com/index-html/archive/2012/07/18/js_select.html http://www.ibm.com/developerwork ...

  4. xcode 树形管理 cocos2d-x的资源

    把资源以目录的形式加入xcode中, 同时, 在加入时, 选择"Create Folder References for any  added folders", 而不是默认的&q ...

  5. linux xxd 命令

    http://www.cnblogs.com/openix/archive/2012/04/23/2466320.html xxd -i dht.jpg dht.h

  6. vim查找/替换字符串 及一些高级用法

    例: 32 ./run 0_39.pkt 0_39.jpg 33 ./run 0_3.pkt 0_3.jpg 34 ./run 0_40.pkt 0_40.jpg 35 ./run 0_41.pkt ...

  7. Creating a web server in pure C(c/c++ 写web server)

    一个简单的例子:https://github.com/fekberg/GoHttp 一个运行在windows上例子:http://www.adp-gmbh.ch/win/misc/webserver. ...

  8. CGI/FASTCGI/ISAPI区别

    一 CGI原理及其性能 1) CGI概念CGI即通用网关接口(Common Gateway Interface),它是一段程序,运行在服务器上,提供同客户端HTML页面的交互,通俗的讲CGI就象是一座 ...

  9. 查看Linux系统的版本以及位数

    1.查看版本 http://jingyan.baidu.com/article/215817f7e360bd1edb142362.html[root@localhost usr]# lsb_relea ...

  10. 解决JDeveloper运行慢的设置/BPM/SOA Server JVM参数设定

    最近在使用 Jdeveloper 10.1.3.3 版本时发现速度奇慢无比,后经Google,发现如下解决方案:在 jdev.conf 文件的末尾加上如下两行,速度即可得到显着的提高, jdev.co ...