The Great Equalizer

# The Great Equalizer

## 题面翻译

Tema 购买了一台老旧设备,设备上有一个小屏幕和一个磨损的铭文“伟大的平衡器”。

卖家说,这台设备需要提供一个整数数组 $a$ 作为输入,之后“伟大的平衡器”将按照以下方式工作:

1. 将当前数组按升序排序,并删除重复元素,相同元素仅保留第一次出现的;
2. 如果当前数组的长度等于 $1$,设备停止工作并输出数组中的唯一一个数字,即设备的输出值;
3. 向当前数组添加一个等差数列 $\{n,\ n - 1,\ n - 2,\ \ldots,\ 1\}$,其中 $n$ 是当前数组的长度。换句话说,数组的第 $i$ 个元素需要加上 $n - i$(下标从 $0$ 开始);
4. 返回第 $1$ 步。

为了测试设备的运行,Tema 构想了一个整数数组 $a$,然后希望对数组 $a$ 执行 $q$ 次操作,操作如下:

1. 将值 $x$($1 \le x \le 10^9$)赋给元素 $a_i$($1 \le i \le n$);
2. 将数组 $a$ 作为输入提供给设备,并找到设备操作后的结果,同时数组 $a$ 保持不变。

帮助 Tema 找出每个操作后设备的输出值。

## 题目描述

Tema bought an old device with a small screen and a worn-out inscription "The Great Equalizer" on the side.

The seller said that the device needs to be given an array $ a $ of integers as input, after which "The Great Equalizer" will work as follows:

1. Sort the current array in non-decreasing order and remove duplicate elements leaving only one occurrence of each element.
2. If the current length of the array is equal to $ 1 $ , the device stops working and outputs the single number in the array — output value of the device.
3. Add an arithmetic progression { $ n,\ n - 1,\ n - 2,\ \ldots,\ 1 $ } to the current array, where $ n $ is the length of the current array. In other words, $ n - i $ is added to the $ i $ -th element of the array, when indexed from zero.
4. Go to the first step.

To test the operation of the device, Tema came up with a certain array of integers $ a $ , and then wanted to perform $ q $ operations on the array $ a $ of the following type:

1. Assign the value $ x $ ( $ 1 \le x \le 10^9 $ ) to the element $ a_i $ ( $ 1 \le i \le n $ ).
2. Give the array $ a $ as input to the device and find out the result of the device's operation, while the array $ a $ remains unchanged during the operation of the device.

Help Tema find out the output values of the device after each operation.

## 输入格式

The first line of the input contains a single integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases.

Then follows the description of each test case.

The first line of each test case contains a single integer $ n $ ( $ 1 \le n \le 2 \cdot 10^5 $ ) — the size of the array $ a $ that Tema initially came up with.

The second line of each test case contains $ n $ integers $ a_1, a_2, a_3, \ldots, a_n $ ( $ 1 \le a_i \le 10^9 $ ) — the elements of the array $ a $ .

The third line of a set contains a single integer $ q $ ( $ 1 \le q \le 2 \cdot 10^5 $ ) — the number of operations.

Each of the next $ q $ lines of a test case contains two integers $ i $ ( $ 1 \le i \le n $ ) and $ x $ ( $ 1 \le x \le 10^9 $ ) - the descriptions of the operations.

It is guaranteed that the sum of the values of $ n $ and the sum of the values of $ q $ for all test cases do not exceed $ 2 \cdot 10^5 $ .

## 输出格式

For each test case, output $ q $ integers — the output values of the device after each operation.

## 样例 #1

### 样例输入 #1

```

4
3
2 4 8
3
1 6
2 10
3 1
5
1 2 2 2 2
1
5 3
2
5 6
7
1 2
1 7
1 7
2 5
1 2
2 7
2 2
5
2 5 1 10 6
10
1 7
4 8
2 5
1 4
2 8
3 4
1 9
3 7
3 4
3 1


```

### 样例输出 #1

```

10 12 15 
4 
10 8 8 9 8 12 2 
14 12 12 11 11 10 11 10 11 14


```

## 提示

Let's consider the first example of the input.

Initially, the array of numbers given as input to the device will be $ [6, 4, 8] $ . It will change as follows: $ $$$[6, 4, 8] \rightarrow [4, 6, 8] \rightarrow [7, 8, 9] \rightarrow [10, 10, 10] \rightarrow [10] $ $ </p><p>Then, the array of numbers given as input to the device will be  $ \[6, 10, 8\] $ . It will change as follows:  $ $ [6, 10, 8] \rightarrow [6, 8, 10] \rightarrow [9, 10, 11] \rightarrow [12, 12, 12] \rightarrow [12] $ $ </p><p>The last array of numbers given as input to the device will be  $ \[6, 10, 1\] $ . It will change as follows:  $ $ [6, 10, 1] \rightarrow [1, 6, 10] \rightarrow [4, 8, 11] \rightarrow [7, 10, 12] \rightarrow [10, 12, 13] \rightarrow [13, 14, 14] \rightarrow [13, 14] \rightarrow [15, 15] \rightarrow [15] $ $$$

参考代码

#include <bits/stdc++.h>
#define long long ll;
using namespace std;int a[200005], b[200005];int main()
{ios::sync_with_stdio(0);cin.tie(0);int t; cin>>t;while(t--){int n;cin>>n;multiset <int> s, diff;diff.insert(0);for (int i = 1; i <= n; i++){cin>>b[i];a[i] = b[i];s.insert(b[i]);}sort(b + 1, b + n + 1);for (int i = 2; i <= n; i++)diff.insert(b[i] - b[i - 1]);int q;cin>>q;while (q--){int id, x, A = -1, B = -1;cin>>id>>x;s.erase(s.find(a[id]));auto it = s.lower_bound(a[id]);if(it != s.end())B = *it;if(it != s.begin()){--it;A = *it;}if(A != -1)diff.erase(diff.find(a[id] - A));if(B != -1)diff.erase(diff.find(B - a[id]));if(A != -1 && B != -1)diff.insert(B - A);a[id] = x;it = s.lower_bound(a[id]);A = -1;B = -1;if (it != s.end())B = *it;if (it != s.begin()){--it;A = *it;}if (A != -1)diff.insert(a[id] - A);if (B != -1)diff.insert(B - a[id]);if (A != -1 && B != -1)diff.erase(diff.find(B - A));s.insert(a[id]);cout << *(--s.end()) + *(--diff.end()) << ' ';}cout << '\n';}return 0;
}

原题链接

CF1862G The Great Equalizer

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/813429.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

OSCP靶场--Fail

OSCP靶场–Fail 考点(rsync未授权覆盖公钥Fail2ban提权) 1.nmap扫描 ## ┌──(root㉿kali)-[~/Desktop] └─# nmap -sV -sC 192.168.153.126 -p- -Pn --min-rate 2500 Starting Nmap 7.92 ( https://nmap.org ) at 2024-04-12 23:34 EDT Warning: 192.168.153.126 giving …

招生管理|基于SprinBoot+vue的招生管理系统系统设计与实现(源码+数据库+文档)

招生管理目录 基于SprinBootvue的招生管理系统设计与实现 一、前言 二、系统设计 三、系统功能设计 前台 后台 教师权限 学生权限&#xff1a; 四、数据库设计 五、核心代码 六、论文参考 七、最新计算机毕设选题推荐 八、源码获取&#xff1a; 博主介绍&#xff…

大数据------JavaWeb------JDBC(完整知识点汇总)

JDBC 定义 全称为Java数据库连接&#xff08;Java DataBase Connectivity&#xff09;&#xff1a;是使用java语句来操作所有关系型数据库的一套API JDBC本质 它是官方定义的一套操作所有关系型数据库的规则&#xff08;即接口&#xff09;&#xff0c;各个数据库厂商会去实现…

Java 9 新特性

Java 9 新特性 Java 9 发布于 2017 年 9 月 22 日&#xff0c;带来了很多新特性&#xff0c;其中最主要的变化是已经实现的模块化系统。接下来我们会详细介绍 Java 9 的新特性。 Java 9 新特性 模块系统&#xff1a;模块是一个包的容器&#xff0c;Java 9 最大的变化之一是引…

VLC-Qt实现简单的视频播放器

VLC-Qt是一个结合了Qt应用程序和libVLC的免费开源库。它提供了用于媒体播放的核心类&#xff0c;以及用于快速开发媒体播放器的GUI类。由于集成了整个libVLC&#xff0c;VLC-Qt具备了libVLC的所有特性&#xff0c; 例如&#xff1a;libVLC实例和播放器、单个文件和列表播放、音…

.NET i18n 多语言支持与国际化

环境 WIN10 VS2022 .NET8 1.&#x1f44b;创建项目 2.&#x1f440;创建Resources Controllers HomeController.en.resx HomeController.fr.resx HomeController.zh.resx 3.&#x1f331;Program.cs添加国际化支持 // 添加国际化支持 builder.Services.AddLocalization(…

6.Hexo标签插件和资产文件夹

标签插件 标签插件&#xff0c;基本上是只是一些小的代码片段&#xff0c;可以将他们添加到markdown文件中 以便添加特定的代码&#xff0c;不需要编写复杂或混乱的HTML 当很多时候想要在markdown页面添加一些特殊元素&#xff0c;通常必须使用HTML 如果不想这么用HTML&#…

CSS特效---百分比加载特效

1、演示 2、一切尽在代码中 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name"viewport" content"widthdevice-width, initial-scale1.0" /><title>Document</title&…

公众号文章如何添加多个附件?

在公众号分享一些文档给粉丝下载&#xff0c;有那么几种方式。比如把文档转成超链接&#xff0c;放在公众号的“阅读原文”处&#xff0c;或者把文件转成二维码&#xff0c;贴在公众号文章里面。这两种方式其实都需要先把文件转成超链接&#xff08;网页链接&#xff09;&#…

开发需求15-使用el-checkbox组件实现el-tree组件的父子关联关系(非全选/全不选)

需求描述: 大家都知道el-tree可以很明显的通过选中来体现上下节点的父子选中状态,那么如果要求把后端把el-tree的数据结构,通过一个展开的list返回给你,使用el-checkbox组件渲染每一个节点,同时要求选中某一个节点,同时可以选中其父节点和子节点;取消也是一样。 思路:…

【目标检测数据集】VOC2007 数据集介绍

一、介绍 VOC 数据是 PASCAL VOC Challenge 用到的数据集&#xff0c;官网&#xff1a;http://host.robots.ox.ac.uk/pascal/VOC/ 备注&#xff1a;VOC数据集常用的均值为&#xff1a;mean_RGB(122.67891434, 116.66876762, 104.00698793) Pytorch 上通用的数据集的归一化指…

OVITO-2.9版本

关注 M r . m a t e r i a l , \color{Violet} \rm Mr.material\ , Mr.material , 更 \color{red}{更} 更 多 \color{blue}{多} 多 精 \color{orange}{精} 精 彩 \color{green}{彩} 彩&#xff01; 主要专栏内容包括&#xff1a; †《LAMMPS小技巧》&#xff1a; ‾ \textbf…

岛屿个数(dfs)

[第十四届蓝桥杯省B 岛屿个数] 小蓝得到了一副大小为 M N MN MN 的格子地图&#xff0c;可以将其视作一个只包含字符 0 0 0&#xff08;代表海水&#xff09;和 1 1 1&#xff08;代表陆地&#xff09;的二维数组&#xff0c;地图之外可以视作全部是海水&#xff0c;每个岛…

C++递推算法

位数问题 #include<bits/stdc.h> using namespace std; void f(int); int a[100][100]; int b[100][100]; int n; int main() {cin>>n;long long x0;for(int i1;i<n;i){xx*10;}long long y0;long long tx;for(int i1;i<n;i){yyt*9;tt/10;}int sum0;int summ…

守护数据安全:如何应对.360、.halo勒索病毒的攻击

尊敬的读者&#xff1a; 近年来&#xff0c;网络安全问题日益严重&#xff0c;各种病毒、木马、勒索软件层出不穷。其中&#xff0c;.360、.halo勒索病毒因其独特的传播方式和恶意行为而备受关注。本文将对该病毒进行深入剖析&#xff0c;并提出相应的应对策略&#xff0c;帮助…

蓝桥杯易错点汇总

1.当想输入一个数字再输入一个字符串要多一个nextLine(); int a scan.nextInt(); String b scan.nextLine(); 在Java编程语言中&#xff0c;使用Scanner类进行输入时&#xff0c;需要注意nextInt()和nextLine()方法的使用。nextInt()用于读取下一个整数&#xff0c;而nextLi…

基于SSM+Vue的宠物销售系统设计与实现

附录,系统运行视频 一、引言 随着互联网的快速发展,电子商务已经成为人们日常生活中不可或缺的一部分。在这个背景下,宠物销售系统应运而生,为宠物爱好者提供了一个便捷、高效的在线购买、领养宠物的平台。本文旨在介绍一个基于SSM(Spring+SpringMVC+MyBatis)框架和Vue…

系统架构最佳实践 -- 一般优惠券平台系统架构设计

优惠券是商城的一种基础的营销工具&#xff0c;在目前c端用户对于电子优惠券已经非常熟悉的情况下&#xff0c;一般自营商城的营销活动系统&#xff0c;都是从优惠券开始搭建。 一、名词定义 基于个人理解&#xff0c;为方便表述&#xff0c;首先对可能产生歧义的名词进行如下…

ubuntu 设置 root 用户密码,创建新用户并赋权限

ubuntu 设置 root 用户密码&#xff0c;创建新用户并赋权限 在适用于 Linux 的 Windows 子系统上运行 Linux GUI 应用&#xff0c; 安装 Ubuntu-20.04 系统&#xff0c;新安装好的系统&#xff0c;设置用户名密码时&#xff0c; root 用户密码默认为空&#xff0c;这时需要设置…

Windows 基于yaml-cpp库的安装与使用【附C++读写.yaml配置文件教程代码】

目录 0 三方库介绍1 源码下载2 源码编译2.1 解压源码资源包2.2 新建build文件夹2.3 使用CMake编译源码2.4 设置编译环境2.5 开始生成工程2.6 打开工程2.7 查看文件2.8 整理文件3 测试示例(读写yaml配置文件)0 三方库介绍 yaml-cpp库 是一个功能强大的 C++ 库,用于处理 YAML …