๐ notes
1111,
link: https://codeforces.cc/contest/1782/problem/D
given a sequence of integers, , find the maximum perfect squares in the array after you add some integer to every element.
alright, well we know is always possible because we can just add the closest square - to every element, and get .
how about two?
well, if they're both perfect squares then:
and are factor pairs, sooo, we'll just iterate through all possible factor pairs , and do some casework given those.
try both of these differences, and report the best answer.
time complexity:
link: https://codeforces.cc/contest/1696/problem/D
given a permutation of length , consider a graph with nodes, where all nodes , where , or .
now, find the shortest path between and .
clearly, we can't construct the tree because of the tight constraint on , but we can observe that we can go as far as we can as long as we don't violate the current "max-min"ess of the current element.
thus, we could solve with the following pseudo-code.
and something similar for max.
we just have to make one opitmization, if the current element is the min/max, then, we can choose the least/greatest element from to go to next.
we'll precompute these suffix min/maxes.
otherwise, we'll follow our other algo.
https://cses.fi/problemset/task/1650
remember that we can use XOR like a prefix sum, because
so, we just xor the previous range, we get the XOR sum of any range in
https://codeforces.cc/problemset/problem/1359/C
total oversight here, i thought that we could add any amount of hot and cold water, but we can only alternate them.
if we ever alternate between the two, and end with an even number, then the average will always be .
also note that we will get to a point when we get further by trying , so that's what we'll use for our binary search.
https://codeforces.cc/contest/1174/problem/D
consider the prefix XOR of the array, the constraints require that the XOR of any two indices is not , so all , and they aren't zero (so they can't be equal).
then, let's just build the prefix XOR, if we've already put in , then don't put in.
since , we'll iterate through numbers.
https://codeforces.com/contest/803/problem/D
another binary search problemโฆ
split the line into segments, divided by spaces and dashes.
then greedily assign these segments and check the lines required.
https://codeforces.cc/contest/1468/problem/D
well it's never optimal to run away, if we don't have any firecrackers already placed, so we'd want to throw all of our firecrackers, and then run for as long as possible.
after we throw, we have time to run, and the number of fireworks we can throw is bounded by .
so, we'll do another binary search
for all arrays , define the array as, .
given arrays of integers, choose (not necessarily distinct) two arrays , such that you maximize .
output these two arrays. (if multiple solutions exists, output any)
first of all, let's fix the answer, . then, each array can be represented as a binary string with bits, the th bit being on if .
then, for any two arrays, if the bitwise OR of the two is equal to , we have a constructable solution.
since , we'll can iterate through all pairs (), and check if and exist, and that the bitwise OR of the two equal .
time complexity, , which will comfortable pass in time.
this problem took me hours to solve D: