【题目链接】

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. hibernate多对一单向外键

    hibernate多对一单向外键: 描述:

  2. spoj 2178

    好水...... #include<cstdio> #include<cstdlib> #include<cstring> #include<algorith ...

  3. 程序自动生成Dump文件

    前言:通过drwtsn32.NTSD.CDB等调试工具生成Dump文件, drwtsn32存在的缺点虽然NTSD.CDB可以完全解决,但并不是所有的操作系统中都安装了NTSD.CDB等调试工具.了解了 ...

  4. POJ 3393 Lucky and Good Months by Gregorian Calendar

    http://poj.org/problem?id=3393 题意 : 对于这篇长长的英语阅读,表示无语无语再无语,花了好长时间,终于读完了.题目中规定每周的周六日为假日,其他为工作日,若是一个月的第 ...

  5. POJ2739Sum of Consecutive Prime Numbers

    http://poj.org/problem?id=2739 题意 :一个正整数能够表示为一个或多个连续素数和,给你一个正整数,让你求,有多少个这样的表示.例如:整数53有两种表示方法,5+7+11+ ...

  6. android dialog 原来dialog对话框也有自己的按键监听事件 onKeyDown方法

    探讨在一个activity中按menu键时弹出自己定义的dialog(自定义菜单对话框)时,再按一次手机的menu键发现这个自定义的dialog菜单并没有关闭,原来是这个dialog内部也有onKey ...

  7. 一个简单的C#加密解密类

    //DES默认密钥向量 private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; /// < ...

  8. 关于DataTables一些小结

    最近项目中使用了DataTables,故小结了一下. 导入CSS文件<link rel="stylesheet" href="<%=base %>/js ...

  9. [itint5]三数和为0

    http://www.itint5.com/oj/#20 其实是3sum的变种,有重复数字,但是一开始还是写错了.其实是选定一个后,在右边剩余数组里找2sum,找到一组后继续找. #include & ...

  10. Fisher's exact test( 费希尔精确检验)

    Fisher's exact test[1][2][3] is a statistical significance test used in the analysis ofcontingency t ...