Codeforces-752

Link to A:Era

Insert number into the array so that a[i] <= i

assume k's number has been inserted before index j, 

1) a[j] <= k + j no need to add more numbers bofore a[j]       

=> k = k                                          (when a[j] - j <= k)

2) a[j] > k + j, at least (a[j] - j - k) more numbers are needed.

=> k = k + a[j] - j - k = a[j] - j           (when a[j] - j > k)

Therefore k = max(k, a[j] - j)

Complexity: O(n)

Link to B: XOR Specia-LIS-t

 each single element is also a subarrray of a and its longest increasing subsequence is 1.

XOR (even number of 1) = 0

Therefore:

1) If the length of the original array is even, split the array into subarrays with length of 1. Even number of 1 satisfies the requirement natually.

2.1) If the length of the original array is odd, however, exits a pair that a[i] >= a[i+1], split these two elements into one subarray. Others remind the same as the 1). Still even number of 1.

2.2) Length(n) is odd, no pair a[i] >= a[i+1] => the array is strictly increasing. 

If (h[1] + h[2] + ... + h[k] = n) and (h[1] XOR h[2] XOR ... XOR h[k] = 0) exists, since each segment s[i] is strictly increasing => h[i] = b[i] (length of s[i]).

Then (b[1] + b[2] + ... + b[k] = n) and (b[1] XOR b[2] XOR ... XOR b[k] = 0) => the last bits of all b must contain even number of 1. Yet n is an odd number. Contradiction!

Only 1) and 2.1) are possible here.

Complexity: O(n)

Link to C: Di-visible Confusion

A element - a[i] can be removed only when there exist a number x in [2, i+1], so that the element is NOT divisable by x.

Improvement:

if a[i] can be divided by any number between [2, i+1]

==> a[i] >= LCM(2, 3, ..., i+1)         [Notice: LCM(2,3,4,..,23) > 1E9 ]

Therefore, if i >= 22, a[i] must be divisable by a number between [2, i+1].

Conclusion:

1) i >= 22, a[i] can always be removed

2) 1 <= i < 22, using bruteforce to check every number in [2, i+1];

Complextiy: O(n + 21^2)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值