National_Wind's blog

By National_Wind, history, 3 years ago, In English

Hey guys!

Today I want to ask about this problem.

Given an array A size N and q queries. (|A[i]| <= 1e5, N <= 1e5, q <= 1e5)

Define F(B), B is a subarray (consecutive) of array A, is the number of distinct values of B. For example: F({1, 2, 3, 4}) = 4

For every query i x, change value A[i] to x, and calculate the sum of all F(B) in the new array A. For a query when A = {1, 1, 2}

  • F({1}) = F({1}) = F({2}) = F({1, 1}) = 1;
  • F({1, 2}) = F({1, 1, 2}) = 2;

The sum result is 1 * 4 + 2 * 2 = 8;

Test: Input

4

1 2 3 4

3

1 1

2 1

3 1

Output

20

17

13

Full text and comments »

  • Vote: I like it
  • +10
  • Vote: I do not like it

By National_Wind, history, 4 years ago, In English

Hi guys, I have this problem. In a given array a length n, how many subarray are there that satisfies: max_element — min_element of the subarray is even. Given that 1 <= n <= 1e5, 1 <= ai <= 1e9. I can't figure out a better solution than O(n^2) solution. How to solve this problem? Thanks!

Full text and comments »

  • Vote: I like it
  • +14
  • Vote: I do not like it