首页 > 其他分享 >[ABC282F] Union of Two Sets

[ABC282F] Union of Two Sets

时间:2023-01-03 16:56:44浏览次数:41  
标签:judge given Union ABC282F Two leq print query ldots

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);
	}
}

标签:judge,given,Union,ABC282F,Two,leq,print,query,ldots
From: https://www.cnblogs.com/mekoszc/p/17022723.html

相关文章

  • [ABC282E] Choose Two and Eat One
    ProblemStatementAboxcontains$N$balls,eachwithanintegerbetween$1$and$M-1$writtenonit.For$i=1,2,\ldots,N$,theintegerwrittenonthe$i$......
  • virtualbox 上安装 esxi 6.7 不认识网卡( no network adapters)
    esxi6.7安装会有各种要求,CPU大于等于2颗,内存大于等于4G等等,还有就是网卡可能提示找不到,默认网卡类型不认识,选这个就行了: ......
  • 论文解读(CAN)《Contrastive Adaptation Network for Unsupervised Domain Adaptation》
    论文信息论文标题:ContrastiveAdaptationNetworkforUnsupervisedDomainAdaptation论文作者:GuoliangKang,LuJiang,YiYang,AlexanderGHauptmann论文来源:CVPR......
  • NetworkPolicy
    36.Egress36.1NetworkPolicy概述#flannel不支持这个策略基于NetworkPolicy在三层(网络层)或四层(传输层)控制拒绝或允许请求流量。1.允许或拒绝特定的pod请求目的name......
  • Gender differences in cortical morphological networks
    文献阅读笔记留存信息起始日期终止日期2022.12.292022.12.30基本信息期刊影响因子/分区题目年份作者标签类型重要性原文链接BrainImagi......
  • Siamese Network
    一、背景除了以前的基础需要经常复习之外,常见的几类场景的算法也要学习一下(想了一下,文本相似度、图片相似、精准营销、生存分析)。这次来学习一下计算图片相似度的一种......
  • cs231n学习笔记——lecture6 Training Neural Networks
    该博客主要用于个人学习记录,部分内容参考自:[基础]斯坦福cs231n课程视频笔记(三)训练神经网络、【cs231n笔记】10.神经网络训练技巧(上)、CS231n学习笔记-训练神经网络、......
  • POJ 2531 Network Saboteur(DFS)
    POJ2531NetworkSaboteur题意​ 把n个节点分成AB两组,给出矩阵\(C_{i,j}\),求\(\sum{C_{i,j}}(i\inA,j\inB)\)的最大值。思路​ n很小,直接爆搜做。枚举一下......
  • C++11:非受限联合体(union)
    在C/C++中,联合体(Union)是一种构造数据类型。在一个联合体内,我们可以定义多个不同类型的成员,这些成员将会共享同一块内存空间。老版本的C++为了和C语言保持兼容,对联合体......
  • /network.sh 执行错误
    执行镜像文件(bootstrap.sh文件运行后正常情况下会生成fabric-samples文件)cdscripts/./bootstrap.sh如果产生以下报错​​fabric-samplesv2.4.3doesnotexist,default......