[ABC282F] Union of Two Sets
Problem Statement
This is an interactive task, where your and the judge's programs interact via Standard Input and Output.
You and the judge will follow the procedure below.
The procedure consists of phases $1$ and $2$; phase $1$ is immediately followed by phase $2$.
(Phase $1$)
- The judge gives you an integer $N$.
 - You print an integer $M$ between $1$ and $50000$, inclusive.
 - You also print $M$ pairs of integers $(l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M)$ such that $1 \leq l_i \leq r_i \leq N$ for every $i = 1, 2, \ldots, M$ (the $M$ pairs do not have to be distinct).
 
(Phase $2$)
- The judge gives you an integer $Q$.
 - You and the judge repeats the following $Q$ times.
- The judge gives you two integers $L$ and $R$ as a query.
 - You respond with two integers $a$ and $b$ between $1$ and $M$, inclusive (possibly with $a = b$).
Here, $a$ and $b$ must satisfy the condition below. Otherwise, your submission will be judged incorrect.- The union of the set $\lbrace l_a, l_a+1, \ldots, r_a\rbrace$ and the set $\lbrace l_b, l_b+1, \ldots, r_b\rbrace$ equals the set $\lbrace L, L+1, \ldots, R\rbrace$.
 
 
 
After the procedure above, terminate the program immediately to be judged correct.
Constraints
- $1 \leq N \leq 4000$
 - $1 \leq Q \leq 10^5$
 - $1 \leq L \leq R \leq N$
 - All values in the input are integers.
 
Input and Output
This is an interactive task, where your and the judge's programs interact via Standard Input and Output.
(Phase $1$)
- First, $N$ is given from the input.
 - Next, an integer $M$ between $1$ and $50000$, inclusive, should be printed.
 - Then, $(l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M)$ should be printed, one at a time.
Specifically, for each $i = 1, 2, \ldots, M$, the $i$-th output should be $(l_i, r_i)$ in the following format: 
$l_i$ $r_i$
(Phase $2$)
- First, $Q$ is given from the input.
 - In each query, integers $L$ and $R$ representing the query are given in the following format:
 
$L$ $R$
- In response to each query, two integers $a$ and $b$ should be printed in the following format:
 
$a$ $b$
Cautions
- At the end of each output, print a newline and flush Standard Output. Otherwise, you may get the TLE verdict.
 - If your program prints a malformed output or quits prematurely, the verdict will be indeterminate. Particularly, note that in case of a runtime error, the verdict may be WA or TLE instead of RE.
 - After phase $2$, immediately terminate the program. Otherwise, the verdict will be indeterminate.
 - $L$ and $R$ given in phase $2$ will be decided according to $(l_1, r_1), (l_2, r_2), \ldots, (l_M, r_M)$ you print in phase $1$.
 
Sample Interaction
Below is a sample interaction with $N = 4$ and $Q = 4$.
=
| Input | Output | Description | 
|---|---|---|
4 | 
$N$ is given. | |
6 | 
You print $M$. | |
3 3 | 
You print $(l_1, r_1) = (3, 3)$. | |
4 4 | 
You print $(l_2, r_2) = (4, 4)$. | |
1 1 | 
You print $(l_3, r_3) = (1, 1)$. | |
2 4 | 
You print $(l_4, r_4) = (2, 4)$. | |
1 3 | 
You print $(l_5, r_5) = (1, 3)$. | |
2 2 | 
You print $(l_6, r_6) = (2, 2)$. | |
4 | 
$Q$ is given. | |
1 3 | 
As the first query, $L = 1$ and $R = 3$ are given. | |
1 5 | 
You respond with $a = 1$ and $b = 5$. | |
3 4 | 
As the second query, $L = 3$ and $R = 4$ are given. | |
2 1 | 
You respond with $a = 2$ and $b = 1$. | |
2 4 | 
As the third query, $L = 2$ and $R = 4$ are given. | |
4 4 | 
You respond with $a = 4$ and $b = 4$. | |
1 1 | 
As the fourth query, $L = 1$ and $R = 1$ are given. | |
3 3 | 
You respond with $a = 3$ and $b = 3$. | |
这个构造和ST表的完全一样。把所有长度为 $1,2,4,8\cdots$ 的区间在一开始给出。然后在求区间合并时也想ST表那样,令 $k=\lfloor\log (r-l+1)\rfloor$,输出 $[l,l+2^k-1]$ 和 $[r-2^k+1,r]$ 对应的编号就行了。
#include<cstdio>
const int N=4005;
int n,st[15][N],lg[N],idx,q,l,r,k;
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
		lg[i]=lg[i>>1]+1;
	for(int i=0;i<=lg[n];i++)
		for(int j=1;j+(1<<i)-1<=n;j++)
			st[i][j]=++idx;
	printf("%d\n",idx);
	for(int i=0;i<=lg[n];i++)
		for(int j=1;j+(1<<i)-1<=n;j++)
			printf("%d %d\n",j,j+(1<<i)-1);
	fflush(stdout);
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d%d",&l,&r);
		k=lg[r-l+1];
		printf("%d %d\n",st[k][l],st[k][r-(1<<k)+1]);
		fflush(stdout);
	}
}
												
											[ABC282F] Union of Two Sets的更多相关文章
- TSQL 分组集(Grouping Sets)
		
分组集(Grouping Sets)是多个分组的并集,用于在一个查询中,按照不同的分组列对集合进行聚合运算,等价于对单个分组使用“union all”,计算多个结果集的并集.使用分组集的聚合查询,返回 ...
 - 转:GROUPING SETS、ROLLUP、CUBE
		
转:http://blog.csdn.net/shangboerds/article/details/5193211 大家对GROUP BY应该比较熟悉,如果你感觉自己并不完全理解GROUP BY,那 ...
 - GROUPING SETS、ROLLUP、CUBE
		
大家对GROUP BY应该比较熟悉,如果你感觉自己并不完全理解GROUP BY,那么本文不适合你.还记得当初学习SQL的时候,总是理解不了GROUP BY的作用,经过好长时间才终于明白GROUP BY ...
 - Group By Grouping Sets
		
Group by分组函数的自定义,与group by配合使用可更加灵活的对结果集进行分组,Grouping sets会对各个层级进行汇总,然后将各个层级的汇总值union all在一起,但却比单纯的g ...
 - PHP  Redis 全部操作方法
		
Classes and methods Usage Class Redis Class RedisException Predefined constants Class Redis Descript ...
 - [转]LUA元表
		
lua元表和元方法 <lua程序设计> 13章 读书笔记 lua中每个值都有一个元表,talble和userdata可以有各自独立的元表,而其它类型的值则共享其类型所属的单一元表.lua在 ...
 - 使用guava带来的方便
		
 guava是在原先google-collection 的基础上发展过来的,是一个比较优秀的外部开源包,最近项目中使用的比较多,列举一些点.刚刚接触就被guava吸引了...  这 ...
 - MST(Kruskal’s Minimum Spanning Tree Algorithm)
		
You may refer to the main idea of MST in graph theory. http://en.wikipedia.org/wiki/Minimum_spanning ...
 - java 泛型深入之Set有用工具 各种集合泛型深入使用演示样例,匿名内部类、内部类应用于泛型探讨
		
java 泛型深入之Set有用工具 各种集合泛型深入使用演示样例,匿名内部类.内部类应用于泛型探讨 //Sets.java package org.rui.generics.set; import j ...
 - redis 有序集合(zset)函数
		
redis 有序集合(zset)函数 zAdd 命令/方法/函数 Adds the specified member with a given score to the sorted set stor ...
 
随机推荐
- CSS实现文字描边效果
			
一.介绍最近在一个项目的宣传页中,设计师使用了文字描边效果,之前我确实没有实现过文字的描边效果,然后我在查阅资料后,知道了实现方法.文字描边分为两种:内外双描边和单外描边,也就是指在给文字加上描边效果 ...
 - 【译】通过 GitHub Copilot Chat 简化代码优化和调试(AI 辅助编程)
			
今年3月,我们宣布了 Visual Studio 2022 的 GitHub Copilot Chat.通过 Chat, Copilot 已经超越了代码补全,提供了对代码工作原理的深入分析和解释.它支 ...
 - 使用API调用获取商品数据的完整方案
			
 在电子商务应用程序中,商品详情接口是不可或缺的一部分.它用于从电商平台或自己的数据库中获取商品数据,并将其提供给应用程序的其他部分使用.本文将详细介绍如何设计一个完整的商品详情接口方案,其中包括使 ...
 - 虾皮shopee根据ID取商品详情 API 返回值说明
			
 item_get-根据ID取商品详情 注册开通 shopee.item_get 公共参数 名称 类型 必须 描述 key String 是 调用key(必须以GET方式拼接在URL中) secr ...
 - RocketMQ 系列(五)高可用与负载均衡
			
RocketMQ 系列(五)高可用与负载均衡 RocketMQ 前面系列文章如下: RocketMQ系列(一) 基本介绍 RocketMQ 系列(二) 环境搭建 RocketMQ 系列(三) 集成 S ...
 - 解决 wg-quick 在 Mac 上 bash 3 无法运行的问题
			
问题原因 我可以理解,开发人员不想使用苹果使用的旧bash v3.但从用户的帖子来看,安装一个较新的bash并不那么好 所以我看了wireguard的wg-quick.需要支持的唯一变化,两个bash ...
 - 关于关闭Sublime Text自动更新提示
			
Sublime Text默认提示自动更新,实在让人烦不胜烦,那么有没有办法解决嘞,那当然是有的,下面就教你如何关闭Sublime Text自动更新提示 首先注册,不注册的话,一切操作都没有用:(注册码 ...
 - 逻辑漏洞挖掘之XSS漏洞原理分析及实战演练
			
一.前言 2月份的1.2亿条用户地址信息泄露再次给各大公司敲响了警钟,数据安全的重要性愈加凸显,这也更加坚定了我们推行安全测试常态化的决心.随着测试组安全测试常态化的推进,有更多的同事对逻辑漏洞产生了 ...
 - MySQL系列之备份恢复——运维在备份恢复方面、备份类型、备份方式及工具、逻辑备份和物理备份、备份策略、备份工具使用-mysqldump、企业故障恢复案例、备份时优化参数、MySQL物理备份工具
			
文章目录 1. 运维在数据库备份恢复方面的职责 1.1 设计备份策略 1.2 日常备份检查 1.3 定期恢复演练(测试库) 1.4 故障恢复 1.5 迁移 2. 备份类型 2.1 热备 2.2 温备 ...
 - matlab启动时的路径警告
			
前段时间在做HDLCoder时为方便修改设置加了一条路径在搜索路径目录,后来把路径名称修改了,文件夹也删掉了,换句话说就是路径不存在了,然后在matlab的setpath对话框里边也把该目录删除了. ...