Codeforces 1167

1167 B

题意

有一个包含6个元素的数组, (4,8,15,16,23,42) 6个数每个数在数组中恰好出现1次。现在你有4次询问机会,每次询问 (i,j) ,返回 (a_i*a_j) 。要你输出这个数组。

Example

input

16
64
345
672

output

? 1 1
? 2 2
? 3 5
? 4 6
! 4 8 15 16 23 42

询问 ((1,2),(2,3),(4,5),(5,6)) 再暴力判断一下。

1167 D

题意

给你一个合法的括号序列,你可以把一些括号染色,要求染色过的括号的子序列合法且未染色过的括号的子序列也合法。最小化染色过的括号的子序列的深度和未染色过的括号的子序列的深度的最大值并构造一个染色方案。

Examples

input

2
()

output

11

input

4
(())

output

0101

input

10
((()())())

output

0110001111

设原括号序列的深度为 (mx) ,把深度 (≥mx/2) 的括号全染色。

1167 E

题意

有一个数组 (a) 长度为 (n) ,其中最大值为 (m) ,定义 (f(l,r)) 为删除值在 ([l,r]) 区间里的元素后剩下的数组。求数对 ((l,r)) 的个数,满足 (f(l,r)) 非严格单调递增。 ((n,mle 10^6))

Examples

input
3 3
2 3 1
output
4
input
7 4
1 3 1 2 2 4 3
output
6

(L[x]) 表示最左边的值为 (x) 的元素的下标, (R[x]) 表示最右边的。
如果 (f(l,r)) 合法,那么一定满足 (∀i,jin [1,l-1]∪[r+1,m],i<j,R[i]<L[j])
即:

  • (∀iin [1,l-1],max(R[1dots i-1])<L[i])
  • (∀iin [r+1,m],R[i]<min(L[i+1dots m]))
  • (max(R[1dots l-1])<min(L[r+1dots m]))

用two-pointers从左往右扫。跟数据结构毫无关系。

原文地址:https://www.cnblogs.com/BlogOfchc1234567890/p/11046930.html