CF1423I.Lookup Tables
NOI/NOI+/CTSC
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
John has Q closed intervals of consecutive 2K-bit numbers [li,ri] and one 16-bit value vi for each interval. (0≤i<Q)
John wants to implement a function F that maps 2K-bit numbers to 16-bit numbers in such a way that inputs from each interval are mapped to that interval's value. In other words: $$F(x) = v_i, \; \textrm{for every } 0 \leq i \lt Q \; \textrm{, and every } x \in [l_i, r_i]$$ The output of F for other inputs is unimportant.
John wants to make his implementation of F fast so he has decided to use lookup tables. A single 2K-bit lookup table would be too large to fit in memory, so instead John plans to use two K-bit lookup tables, LSBTable and MSBTable. His implementation will look like this: $$ F(x) = \textrm{LSBTable}[\textrm{lowKBits}(x)] \; \& \; \textrm{MSBTable}[\textrm{highKBits}(x)]$$ In other words it returns the "bitwise and" of results of looking up the K least significant bits in LSBTable and the K most significant bits in MSBTable.
John needs your help. Given K, Q and Q intervals [li,ri] and values vi, find any two lookup tables which can implement F or report that such tables don't exist.
约翰有 Q 个闭区间 [li,ri],每个区间由连续的 2K 位整数构成,并为每个区间配有一个 16 位值 vi(其中 0≤i<Q)。
约翰希望实现一个函数 F,该函数将 2K 位整数映射为 16 位整数,使得每个区间内的所有输入均被映射到对应区间的值 vi。换言之:
F(x) = v\_i, \; \textrm{对每个 } 0 \leq i < Q \; \textrm{及每个 } x \in \[l\_i, r\_i\]对于其他输入,F 的输出值无关紧要。
为使 F 的实现尽可能高效,约翰决定采用查表法(lookup tables)。但单个 2K 位的查找表过大,无法装入内存;因此他计划使用两个 K 位查找表:LSBTable 和 MSBTable。其实现方式如下:
即:先提取 x 的最低 K 位(记为 lowKBits(x))并在 LSBTable 中查表,再提取 x 的最高 K 位(记为 highKBits(x))并在 MSBTable 中查表,最后对两个查表结果执行按位与(bitwise AND)操作并返回结果。
约翰需要你的帮助:给定 K、Q,以及 Q 个区间 [li,ri] 和对应值 vi,请找出任意一对满足要求的查找表 LSBTable 和 MSBTable;若不存在这样的查找表,则报告无解。
输入格式
The first line contains two integers K and Q ($ 1 \lt = K \lt = 16$, 1<=Q<=2⋅105).
Each of the next Q lines contains three integers li, ri and vi. ( 0≤li≤ri<22K, 0≤vi<216).
第一行包含两个整数 K 和 Q($ 1 \leq K \leq 16$,1≤Q≤2⋅105)。
接下来的 Q 行每行包含三个整数 li、ri 和 vi(0≤li≤ri<22K,0≤vi<216)。
输出格式
On the first line output "possible" (without quotes) if two tables satisfying the conditions exist, or "impossible" (without quotes) if they don't exist.
If a solution exists, in the next 2⋅2K lines your program should output all values of the two lookup tables (LSBTable and MSBTable) it found. When there are multiple pairs of tables satisfying the conditions, your program may output any such pair.
On lines 1+i output LSBTable[i]. (0≤i<2K, 0≤LSBTable[i]<216).
On lines 1+2K+i output MSBTable[i]. (0≤i<2K, 0≤MSBTable[i]<216).
第一行输出“possible”(不带引号),表示存在满足条件的两张查找表;若不存在,则输出“impossible”(不带引号)。
若解存在,则在接下来的 2⋅2K 行中,你的程序应输出所找到的两张查找表(LSBTable 和 MSBTable)的所有值。当存在多对满足条件的表格时,你的程序可输出其中任意一对。
第 1+i 行输出 LSBTable[i]。(0≤i<2K,且 0≤LSBTable[i]<216)
第 1+2K+i 行输出 MSBTable[i]。(0≤i<2K,且 0≤MSBTable[i]<216)
输入输出样例
输入#1
1 2 0 2 1 3 3 3
输出#1
possible 1 3 1 3
输入#2
2 4 4 5 3 6 7 2 0 3 0 12 13 1
输出#2
possible 3 3 2 2 0 3 0 1
输入#3
2 3 4 4 3 5 6 2 12 14 1
输出#3
impossible
说明/提示
A closed interval [a,b] includes both a and b.
In the first sample, tables LSBTable=[1,3] and MSBTable=[1,3] satisfy the conditions: F[0]=LSBTable[0]&MSBTable[0]=1&1=1, F[1]=LSBTable[1]&MSBTable[0]=3&1=1, F[2]=LSBTable[0]&MSBTable[1]=1&3=1, F[3]=LSBTable[1]&MSBTable[1]=3&3=3.
In the second sample, tables LSBTable=[3,3,2,2] and MSBTable=[0,3,0,1] satisfy all the conditions.
In the third sample there are no two lookup tables which can satisfy the conditions.
闭区间 [a,b] 包含端点 a 和 b。
在第一个样例中,查找表 LSBTable=[1,3] 与 MSBTable=[1,3] 满足条件:F[0]=LSBTable[0]&MSBTable[0]=1&1=1,F[1]=LSBTable[1]&MSBTable[0]=3&1=1,F[2]=LSBTable[0]&MSBTable[1]=1&3=1,F[3]=LSBTable[1]&MSBTable[1]=3&3=3。
在第二个样例中,查找表 LSBTable=[3,3,2,2] 与 MSBTable=[0,3,0,1] 满足所有条件。
在第三个样例中,不存在两个查找表能够满足条件。
输入解题思路,AI测评打分。不知道怎么写?