传送门

两个multiset

一个记录相邻元素的差,一个放所有的元素

2个数组

val[i]记录第i个的值,last[i]记录第i个最后插入的数的值

然后乱搞

#include <set>
#include <cstdio>
#include <iostream>
#define N 1001000
#define abs(x) ((x) < 0 ? -(x) : (x))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y)) using namespace std; int n, m, ans = 1e9;
int val[N], last[N];
multiset <int> s, ss;
multiset <int> :: iterator it; inline int read()
{
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * f;
} inline void set_insert(int x)
{
s.insert(x);
it = s.lower_bound(x);
if(it != s.begin())
it--, ans = min(ans, abs(*it - x)), it++;
if((++it) != s.end()) ans = min(ans, abs(*it - x));
} inline void insert(int x, int y)
{
if(x != n)
ss.erase(ss.lower_bound(abs(last[x] - val[x + 1])));
ss.insert(abs(last[x] - y));
if(x != n) ss.insert(abs(val[x + 1] - y));
last[x] = y;
set_insert(y);
} int main()
{
int i, x, y;
char s[21];
n = read();
m = read();
for(i = 1; i <= n; i++)
{
last[i] = val[i] = read();
set_insert(val[i]);
if(i > 1) ss.insert(abs(val[i] - val[i - 1]));
}
for(i = 1; i <= m; i++)
{
scanf("%s", s);
if(s[4] == 'R')
{
x = read();
y = read();
insert(x, y);
}
if(s[4] == 'G') printf("%d\n", *ss.begin());
if(s[4] == 'S') printf("%d\n", ans);
}
return 0;
}

  

[luoguP1110] [ZJOI2007]报表统计(set暴力)的更多相关文章

  1. [补档][ZJOI2007] 报表统计

    [ZJOI2007] 报表统计 题目 传送门 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工作,作为她的生日礼物之一. 经过仔细观察,小Q发现统计一 ...

  2. 洛谷 P1110 [ZJOI2007]报表统计 解题报告

    P1110 [ZJOI2007]报表统计 题目描述 \(Q\)的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小\(Q\)希望可以帮妈妈分担一些工作,作为她的生日礼物之一. 经过仔细 ...

  3. bzoj1058: [ZJOI2007]报表统计

    set.操作:insert(u,v)在u后面插入v,若u后面已插入过,在插入过的后面插入.mingap求出序列两两之间差值的最小值.minsortgap求出排序后的序列两两之间的最小值.用multis ...

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

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

  5. BZOJ_1058_[ZJOI2007]报表统计_STL

    BZOJ_1058_[ZJOI2007]报表统计_STL Description 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工 作,作为她的生日礼 ...

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

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

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

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

  8. 【BZOJ1058】[ZJOI2007]报表统计 STL

    [BZOJ1058][ZJOI2007]报表统计 Description 小Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工作,作为她的生日礼物之一.经 ...

  9. [ZJOI2007]报表统计(splay,堆)

    [ZJOI2007]报表统计(luogu) Description 题目描述 Q的妈妈是一个出纳,经常需要做一些统计报表的工作.今天是妈妈的生日,小Q希望可以帮妈妈分担一些工作,作为她的生日礼物之一. ...

随机推荐

  1. 【转】ios -- ViewController跳转+传值(方式一)

    方式一:通过定义一个实体类传值 (从ViewController1 跳转至 ViewController2) 1.定义实体类NotificationEntity .h声明文件 #import < ...

  2. 2018.4.28 基于java的聊天系统(带完善)

    Java聊天系统 1.Socket类 Socket(InetAddress address, int port) 创建一个流套接字并将其连接到指定 IP 地址的指定端口号. Socket(String ...

  3. E​x​c​h​a​n​g​e​邮​箱​搭​建

    出现的问题: System.Runtime.InteropServices.COMException(0x8004020F): The server rejected one or more reci ...

  4. mysql绿色版下载及应用

    一.mysql绿色版下载 第一歩:打开下载网址:https://www.oracle.com 点击Menu-->Database and Technologies-->Databases- ...

  5. lua在linxu和windows系统下的遍历目录的方法

    在windows下遍历目录使用lfs库:例如遍历整个目录下的所有文件 local lfs = require "lfs" function findPathName(path)  ...

  6. cocos2dx for lua 加密图片

    图片加密的方法有很多种,在cocos2dx中,经常会使用TexturePacker来加密图片,方法如下: 打开TexturePacker,点击Add Sprite添加图片,在output栏下的Text ...

  7. ARC中__weak;__strong;__unsafe_unretained;修饰词

    测试代码: // Human.h代码 @interface Human : NSObject @property (nonatomic, weak) Cat *pinkCat; @property ( ...

  8. Python学习笔记5(函数)

    [摘要]本文详细介绍python中的函数,以及与之相关的参数和作用域的概念,并介绍递归的概念以及在程序中的应用. 函数定义 定义函数要用函数定义语句def.如下: def hello(name): r ...

  9. 单行代码实现xml转换成数组

    $string = '<xml> <return_code><![CDATA[SUCCESS]]></return_code> <return_m ...

  10. Python分布式爬虫开发搜索引擎 Scrapy实战视频教程

    点击了解更多Python课程>>> Python分布式爬虫开发搜索引擎 Scrapy实战视频教程 课程目录 |--第01集 教程推介 98.23MB |--第02集 windows下 ...