AtCoder Regular Contest 179 (ABC题)视频讲解

A - Partition

Problem Statement

You are given integers N N N and K K K.
The cumulative sums of an integer sequence X = ( X 1 , X 2 , … , X N ) X=(X_1,X_2,\dots ,X_N) X=(X1,X2,,XN) of length N N N is defined as a sequence Y = ( Y 0 , Y 1 , … , Y N ) Y=(Y_0,Y_1,\dots ,Y_N) Y=(Y0,Y1,,YN) of length N + 1 N+1 N+1 as follows:
Y 0 = 0 Y_0=0 Y0=0
Y i = ∑ j = 1 i X j ( i = 1 , 2 , … , N ) Y_i=\displaystyle\sum_{j=1}^{i}X_j\ (i=1,2,\dots ,N) Yi=j=1iXj (i=1,2,,N)
An integer sequence X = ( X 1 , X 2 , … , X N ) X=(X_1,X_2,\dots ,X_N) X=(X1,X2,,XN) of length N N N is called a good sequence if and only if it satisfies the following condition:
Any value in the cumulative sums of X X X that is less than K K K appears before any value that is not less than K K K.
Formally, for the cumulative sums Y Y Y of X X X, for any pair of integers ( i , j ) (i,j) (i,j) such that 0 ≤ i , j ≤ N 0 \le i,j \le N 0i,jN, if KaTeX parse error: Expected 'EOF', got '&' at position 6: (Y_i &̲lt; K and Y j ≥ K ) Y_j \ge K) YjK), then KaTeX parse error: Expected 'EOF', got '&' at position 3: i &̲lt; j.
You are given an integer sequence A = ( A 1 , A 2 , … , A N ) A=(A_1,A_2,\dots ,A_N) A=(A1,A2,,AN) of length N N N. Determine whether the elements of A A A can be rearranged to a good sequence. If so, print one such rearrangement.

Constraints

1 ≤ N ≤ 2 × 1 0 5 1 \leq N \leq 2 \times 10^5 1N2×105
− 1 0 9 ≤ K ≤ 1 0 9 -10^9 \leq K \leq 10^9 109K109
− 1 0 9 ≤ A i ≤ 1 0 9 -10^9 \leq A_i \leq 10^9 109Ai109
All input values are integers.

Input

The input is given from Standard Input in the following format:

N N N K K K
A 1 A_1 A1 A 2 A_2 A2 ⋯ \cdots A N A_N AN

Output

If the elements of A A A can be rearranged to a good sequence, print the rearranged sequence ( A 1 ′ , A 2 ′ , … , A N ′ ) (A^{\prime}_1,A^{\prime}_2,\dots ,A^{\prime}_N) (A1,A2,,AN) in the following format:

Yes
A 1 ′ A^{\prime}_1 A1 A 2 ′ A^{\prime}_2 A2 ⋯ \cdots A N ′ A^{\prime}_N AN

If there are multiple valid rearrangements, any of them is considered correct.
If a good sequence cannot be obtained, print No.

Sample Input 1

4 1
-1 2 -3 4

Sample Output 1

Yes
-3 -1 2 4

If you rearrange A A A to ( − 3 , − 1 , 2 , 4 ) (-3,-1,2,4) (3,1,2,4), the cumulative sums Y Y Y in question will be ( 0 , − 3 , − 4 , − 2 , 2 ) (0,-3,-4,-2,2) (0,3,4,2,2). In this Y Y Y, any value less than 1 1 1 appears before any value not less than 1 1 1.

Sample Input 2

4 -1
1 -2 3 -4

Sample Output 2

No

Sample Input 3

10 1000000000
-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 3

Yes
-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long longusing namespace std;typedef pair<int, int> PII;
typedef long long LL;signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);int n, k, sum = 0;cin >> n >> k;std::vector<int> a(n);for (int i = 0; i < n; i ++)cin >> a[i], sum += a[i];if (sum < k	&& k <= 0) {cout << "No" << endl;return 0;}if (k > 0) sort(a.begin(), a.end());else sort(a.begin(), a.end(), greater<int>());cout << "Yes" << endl;for (int i = 0; i < n; i ++)cout << a[i] << " ";cout << endl;return 0;
}

B - Between B and B

Problem Statement

You are given a sequence ( X 1 , X 2 , … , X M ) (X_1, X_2, \dots, X_M) (X1,X2,,XM) of length M M M consisting of integers between 1 1 1 and M M M, inclusive.
Find the number, modulo 998244353 998244353 998244353, of sequences A = ( A 1 , A 2 , … , A N ) A = (A_1, A_2, \dots, A_N) A=(A1,A2,,AN) of length N N N consisting of integers between 1 1 1 and M M M, inclusive, that satisfy the following condition:
For each B = 1 , 2 , … , M B = 1, 2, \dots, M B=1,2,,M, the value X B X_B XB exists between any two different occurrences of B B B in A A A (including both ends).
More formally, for each B = 1 , 2 , … , M B = 1, 2, \dots, M B=1,2,,M, the following condition must hold:
For every pair of integers ( l , r ) (l, r) (l,r) such that KaTeX parse error: Expected 'EOF', got '&' at position 10: 1 \leq l &̲lt; r \leq N and A l = A r = B A_l = A_r = B Al=Ar=B, there exists an integer m m m ( l ≤ m ≤ r l \leq m \leq r lmr) such that A m = X B A_m = X_B Am=XB.

Constraints

1 ≤ M ≤ 10 1 \leq M \leq 10 1M10
1 ≤ N ≤ 1 0 4 1 \leq N \leq 10^4 1N104
1 ≤ X i ≤ M 1 \leq X_i \leq M 1XiM
All input values are integers.

Input

The input is given from Standard Input in the following format:

M M M N N N
X 1 X_1 X1 X 2 X_2 X2 ⋯ \cdots X M X_M XM

Output

Print the answer.

Sample Input 1

3 4
2 1 2

Sample Output 1

14

Here are examples of sequences A A A that satisfy the condition:
( 1 , 3 , 2 , 3 ) (1, 3, 2, 3) (1,3,2,3)
( 2 , 1 , 2 , 1 ) (2, 1, 2, 1) (2,1,2,1)
( 3 , 2 , 1 , 3 ) (3, 2, 1, 3) (3,2,1,3)
Here are non-examples:
( 1 , 3 , 1 , 3 ) (1, 3, 1, 3) (1,3,1,3)
There is no X 3 = 2 X_3 = 2 X3=2 between the 3 3 3s.
( 2 , 2 , 1 , 3 ) (2, 2, 1, 3) (2,2,1,3)
There is no X 2 = 1 X_2 = 1 X2=1 between the 2 2 2s.

Sample Input 2

4 8
1 2 3 4

Sample Output 2

65536

All sequences of length 8 8 8 consisting of integers between 1 1 1 and 4 4 4 satisfy the condition.
Note that when X B = B X_B = B XB=B, there is always a B B B between two different occurrences of B B B.

Sample Input 3

4 9
2 3 4 1

Sample Output 3

628

Solution

具体见文末视频。

Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long longusing namespace std;typedef pair<int, int> PII;
typedef long long LL;const int N = 1e4 + 10, M = 11, mod = 998244353;int n, m;
int a[M], f[N][1 << M], mask[M];signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);cin >> m >> n;for (int i = 1; i <= m; i ++)cin >> a[i], mask[a[i]] |= 1ll << i - 1;f[0][(1 << m) - 1] = 1;for (int i = 0; i < n; i ++)for (int j = 1; j <= m; j ++)for (int k = 0; k < 1 << m; k ++)if ((k >> j - 1) & 1)f[i + 1][(k ^ (1 << j - 1)) | mask[j]] = (f[i + 1][(k ^ (1 << j - 1)) | mask[j]] + f[i][k]) % mod;int res = 0;for (int i = 0; i < 1 << m; i ++)res = (res + f[n][i]) % mod;cout << res << endl;return 0;
}

C - Beware of Overflow

Problem Statement

This is an interactive problem (where your program interacts with the judge via input and output).
You are given a positive integer N N N.
The judge has a hidden positive integer R R R and N N N integers A 1 , A 2 , … , A N A_1, A_2, \dots, A_N A1,A2,,AN. It is guaranteed that ∣ A i ∣ ≤ R |A_i|\le R AiR and ∣ ∑ i = 1 N A i ∣ ≤ R \left|\displaystyle\sum_{i=1}^{N}A_i\right| \le R i=1NAi R.
There is a blackboard on which you can write integers with absolute values not exceeding R R R. Initially, the blackboard is empty.
The judge has written the values A 1 , A 2 , … , A N A_1, A_2, \dots, A_N A1,A2,,AN on the blackboard in this order. Your task is to make the blackboard contain only one value ∑ i = 1 N A i \displaystyle\sum_{i=1}^{N}A_i i=1NAi.
You cannot learn the values of R R R and A i A_i Ai directly, but you can interact with the judge up to 25000 25000 25000 times.
For a positive integer i i i, let X i X_i Xi be the i i i-th integer written on the blackboard. Specifically, X i = A i X_i = A_i Xi=Ai for i = 1 , 2 , … , N i=1,2,\dots,N i=1,2,,N.
In one interaction, you can specify two distinct positive integers i i i and j j j and choose one of the following actions:
Perform addition. The judge will erase X i X_i Xi and X j X_j Xj from the blackboard and write X i + X j X_i + X_j Xi+Xj on the blackboard.
∣ X i + X j ∣ ≤ R |X_i + X_j| \leq R Xi+XjR must hold.
Perform comparison. The judge will tell you whether KaTeX parse error: Expected 'EOF', got '&' at position 5: X_i &̲lt; X_j is true or false.
Here, at the beginning of each interaction, the i i i-th and j j j-th integers written on the blackboard must not have been erased.
Perform the interactions appropriately so that after all interactions, the blackboard contains only one value ∑ i = 1 N A i \displaystyle\sum_{i=1}^{N}A_i i=1NAi.
The values of R R R and A i A_i Ai are determined before the start of the conversation between your program and the judge.

Constraints

2 ≤ N ≤ 1000 2 \leq N \leq 1000 2N1000
1 ≤ R ≤ 1 0 9 1 \leq R \leq 10^9 1R109
∣ A i ∣ ≤ R |A_i| \leq R AiR
∣ ∑ i = 1 N A i ∣ ≤ R \left|\displaystyle\sum_{i=1}^{N}A_i\right| \le R i=1NAi R
N N N, R R R, and A i A_i Ai are integers.

Input and Output

This is an interactive problem (where your program interacts with the judge via input and output).
First, read N N N from Standard Input.

N N N

Next, repeat the interactions until the blackboard contains only one value ∑ i = 1 N A i \displaystyle\sum_{i=1}^{N}A_i i=1NAi.
When performing addition, make an output in the following format to Standard Output. Append a newline at the end. Here, i i i and j j j are distinct positive integers.

  • i i i j j j

The response from the judge will be given from Standard Input in the following format:

P P P

Here, P P P is an integer:
If P ≥ N + 1 P \geq N + 1 PN+1, it means that the value X i + X j X_i + X_j Xi+Xj has been written on the blackboard, and it is the P P P-th integer written.
If P = − 1 P = -1 P=1, it means that i i i and j j j do not satisfy the constraints, or the number of interactions has exceeded 25000 25000 25000.
When performing comparison, make an output in the following format to Standard Output. Append a newline at the end. Here, i i i and j j j are distinct positive integers.

? i i i j j j

The response from the judge will be given from Standard Input in the following format:

Q Q Q

Here, Q Q Q is an integer:
If Q = 1 Q = 1 Q=1, it means that KaTeX parse error: Expected 'EOF', got '&' at position 5: X_i &̲lt; X_j is true.
If Q = 0 Q = 0 Q=0, it means that KaTeX parse error: Expected 'EOF', got '&' at position 5: X_i &̲lt; X_j is false.
If Q = − 1 Q = -1 Q=1, it means that i i i and j j j do not satisfy the constraints, or the number of interactions has exceeded 25000 25000 25000.
For both types of interactions, if the judge’s response is − 1 -1 1, your program is already considered incorrect. In this case, terminate your program immediately.
When the blackboard contains only one value ∑ i = 1 N A i \displaystyle\sum_{i=1}^{N}A_i i=1NAi, report this to the judge in the following format. This does not count towards the number of interactions. Then, terminate your program immediately.

!

If you make an output in a format that does not match any of the above, -1 will be given from Standard Input.

-1

In this case, your program is already considered incorrect. Terminate your program immediately.

Notes

For each output, append a newline at the end and flush Standard Output. Otherwise, the verdict may be TLE.
Terminate your program immediately after outputting the result (or receiving -1). Otherwise, the verdict will be indeterminate.
Extra newlines will be considered as malformed output.

Sample Input and Output

Here is a possible conversation with N = 3 , R = 10 , A 1 = − 1 , A 2 = 10 , A 3 = 1 N=3, R=10, A_1=-1, A_2=10, A_3=1 N=3,R=10,A1=1,A2=10,A3=1.

InputOutputExplanation
3First, the integer $N$ is given.
? 1 2Perform a comparison.
1The judge returns $1$ because $X_1\lt X_2\ (-1\lt 10)$.
+ 1 3Perform an addition.
4The judge erases $X_1 = -1$ and $X_3 = 1$ from the blackboard and writes $X_1 + X_3 = 0$. This is the fourth integer written.
+ 2 4Perform an addition.
5The judge erases $X_2 = 10$ and $X_4 = 0$ from the blackboard and writes $X_2 + X_4 = 10$. This is the fifth integer written.
!The blackboard contains only one value $\displaystyle\sum_{i=1}^{N}A_i$, so report this to the judge.

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long longusing namespace std;typedef pair<int, int> PII;
typedef long long LL;bool cmp(int a, int b) {cout << "? " << a << " " << b << endl;int ok;cin >> ok;return ok;
}signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);int n;cin >> n;std::vector<int> id;for (int i = 1; i <= n; i ++)id.push_back(i);sort(id.begin(), id.end(), cmp);while (n > 1) {cout << "+ " << id[0] << " " << id.back() << endl;int p;cin >> p;id.erase(id.begin()), id.pop_back();n --;if (n == 1) break;int l = 0, r = id.size() - 1;while (l < r) {int mid = l + r >> 1;if (cmp(p, id[mid])) r = mid;else l = mid + 1;}if (!cmp(p, id[r])) r ++;id.insert(id.begin() + r, p);}cout << "!\n";return 0;
}

视频题解

AtCoder Regular Contest 179(A ~ C 题讲解)


最后祝大家早日在这里插入图片描述

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

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

相关文章

交互设计如何助力传统技艺在当代复兴?

背景介绍 榫卯是中国传统木工中一种独特的接合技术&#xff0c;它通过构件间的凸凹部分相互配合来实现两个或多个构件的紧密结合。这种结构方式不依赖于钉子或其他金属连接件&#xff0c;而是利用木材自身的特性&#xff0c;通过精巧的设计和工艺&#xff0c;实现构件间的稳定…

GEE数据集:美国植被干旱响应指数 (Vegetation Drought Response Index,VegDRI)数据集

植被干旱响应指数 (VegDRI) 简介 植被干旱响应指数&#xff08;VegDRI&#xff09;是一个每周一次的地理空间模型&#xff0c;用于描述干旱对美国本土植被造成的压力。VegDRI干旱监测工具是由美国地质调查局EROS中心、内布拉斯加大学国家干旱缓解中心&#xff08;NDMC&#…

计算机网络学习实践:配置主机通过DHCP获取IP并通过域名访问web服务器

计算机网络学习实践&#xff1a;配置主机通过DHCP获取IP并通过域名访问web服务器 点一点就能配置&#xff0c;不需要输入命令 1.实验准备 实验环境&#xff1a;思科的模拟器 实验设备&#xff1a; 3个服务器&#xff0c;1个二层交换机&#xff08;不是三层的&#xff09;&a…

一个弹出的虚假安全警告去除

虚假的安全警告 poratus.azurewebsites.net Pornographic spyware detected! Remove viruses with Avira Antivirus 通过 Microsoft Edge GPT-4 (OpenAI) 这个提示可能是一个虚假的安全警告&#xff0c;被称为“恐吓软件”&#xff08;scareware&#xff09;&#xff0c;旨在…

名下企业查询,清晰明了;在线操作,方便快捷

在现代社会&#xff0c;越来越多的人开始涉足创业和投资&#xff0c;拥有自己的企业成为一种时尚。然而&#xff0c;随之而来的是繁琐的企业注册流程和复杂的信息查询。为了解决这个问题&#xff0c;挖数据平台推出了一项名下企业查询接口&#xff0c;提供了一种方便快捷的方式…

计算机网络介绍

计算机网络介绍 概述网络概述相关硬件 链路层VLAN概念VLAN 特点VLAN 的划分帧格式端口类型原理 STP概念特点原理 Smart Link概念特点组网 网络层ARP概念原理 IP概念版本IP 地址 IPv4IP 地址数据报格式 IPv6特点IP 地址数据报格式 ICMP概念分类报文格式 VRRP概念原理报文格式 OS…

片上电控系统集成技术

一、背景 片上电机控制系统集成技术&#xff08;On-Chip Motor Control System Integration&#xff09;是一种先进的电子工程技术&#xff0c;它主要聚焦于将复杂的电机控制算法和硬件组件整合到单一集成电路&#xff08;IC&#xff09;中&#xff0c;以便于高效、精确地管理…

计算机毕业设计 | 基于Koa+vue的高校宿舍管理系统宿舍可视化系统

项目介绍 项目背景 随着科技的发展&#xff0c;智能化管理越来越重要。大学生在宿舍的时间超过了1/3&#xff0c;因此良好的宿舍管理对学生的生活和学习极为关键。学生宿舍管理系统能够合理安排新生分配宿舍&#xff0c;不浪费公共资源&#xff0c;减轻学校管理压力&#xff…

关于工作组

什么是局域网&#xff08;内网&#xff09; 我们常说的内网指的就是局域网&#xff0c;局域网&#xff08;Local Area Network&#xff0c;简称LAN&#xff09;是指在相对较小的地理范围内&#xff0c;如一个办公室、学校、住宅区或建筑群内部&#xff0c;通过通信设备&#xf…

上位机图像处理和嵌入式模块部署(f407 mcu中tf卡读写和fatfs挂载)

【 声明&#xff1a;版权所有&#xff0c;欢迎转载&#xff0c;请勿用于商业用途。 联系信箱&#xff1a;feixiaoxing 163.com】 很早之前&#xff0c;个人对tf卡并不是很重视&#xff0c;觉得它就是一个存储工具而已。后来在移植v3s芯片的时候&#xff0c;才发现很多的soc其实…

如何监控慢 SQL?

引言&#xff1a;在开发和维护数据库驱动的应用程序时&#xff0c;监控慢 SQL 查询是确保系统性能和稳定性的关键一环。慢 SQL 查询可能会导致系统性能下降、资源浪费和用户体验差等问题。因此&#xff0c;及时监控和优化慢 SQL 查询对于保障系统的正常运行和用户满意度至关重要…

k8s 1.28.x 配置nfs

1.安装nfs&#xff0c;在每个节点上安装 yum install -y nfs-utils 2.创建共享目录(主节点上操作) mkdir -p /opt/nfs/k8s 3.编写NFS的共享配置 /opt/nfs/k8s *(rw,no_root_squash) #*代表对所有IP都开放此目录&#xff0c;rw是读写 4.启动nfs systemctl enable nfs-ser…

动态代理(黑马笔记)

一、BigStar 大明星类 package com.itheima.mydynamicproxy1; public class BigStar implements Star {//实现接口要重写里边的抽象方法private String name;public BigStar() {}public BigStar(String name) {this.name name;}//唱歌Override //表示重写接口中的方法public…

Java | Leetcode Java题解之第127题单词接龙

题目&#xff1a; 题解&#xff1a; class Solution {Map<String, Integer> wordId new HashMap<String, Integer>();List<List<Integer>> edge new ArrayList<List<Integer>>();int nodeNum 0;public int ladderLength(String beginW…

算法-找出N个数组的共同元素

一、代码与执行结果 财经新闻是大众了解金融事件的重要渠道&#xff0c;现有N位编辑&#xff0c;分别对K篇新闻进行专业的编辑与排版。需要您找出被这N位编辑共同编辑过的新闻&#xff0c;并根据这些新闻ID升序排列返回一个数组。 import random# 查找编辑共同处理的新闻id def…

RunLoop小白入门

核心概念 什么是 RunLoop ? RunLoop 是 iOS 和 macOS 应用程序框架中的一个核心概念&#xff0c;用于管理线程的事件处理。它可以看作是一个循环&#xff0c;用于持续接收和处理各种事件&#xff0c;如用户输入、定时器、网络事件等。RunLoop 在保持应用程序响应用户交互和系…

系统与软件工程软件测试过程

系统与软件工程 软件测试 测试过程 &#xff1b;对应的国标是GB/T 38634.4 2020 &#xff0c;该标准的范围规定适应用于治理、管理和实施任何组织,项目或较小规模测试活动的软件测试的测试过程,定义了软件测试通用过程,给出了描述过程的支持信息图表。 一 术语和定义 1.1实测…

力扣173题:二叉搜索树迭代器(含模拟面试)

❤️❤️❤️ 欢迎来到我的博客。希望您能在这里找到既有价值又有趣的内容&#xff0c;和我一起探索、学习和成长。欢迎评论区畅所欲言、享受知识的乐趣&#xff01; 推荐&#xff1a;数据分析螺丝钉的首页 关注微信公众号 数据分析螺丝钉 免费领取价值万元的python/java/商业…

Luminus推出新型高性能 UV-A LED

​Luminus Devices推出的SST-08H-UV&#xff0c;作为SST-08-UV的升级版&#xff0c;以其独特的高功率UV-A LED系列&#xff0c;犹如一道璀璨的光束&#xff0c;照亮了众多领域。这款LED的卓越之处在于&#xff0c;它巧妙地利用了365nm、385nm、395nm和405nm的峰值波长选项&…

使用System-Verilog实现FPGA基于DE2-115开发板驱动HC_SR04超声波测距模块|集成蜂鸣器,led和vga提示功能

文章目录 前言一、实验原理1.1 传感器概述&#xff1a;1.2 传感器引脚1.3 传感器工作原理1.4 整体测距原理及编写思路 二、System-Verilog文件2.1 时钟分频&#xff08;1&#xff09;clk_div.sv2.2 超声波测距&#xff08;1&#xff09;hc_sr_trig.sv&#xff08;2&#xff09;…