[Solution] Good Subarrays (Hard Version) Codeforces Solution
This is the hard version of this problem. In this version, we have queries. Note that we do not have multiple test cases in this version. You can make hacks only if both versions of the problem are solved.
An array of length is good if for all the -th element is greater than or equal to . In other words, is good if and only if for all ().
You are given an array consisting of positive integers, and you are asked queries.
In each query, you are given two integers and (). You have to do (assign to ). In the updated array, find the number of pairs of indices , where , such that the array is good.
Note that all queries are independent, which means after each query, the initial array is restored.
The first line contains a single integer ().
The second line contains integers ().
The third line contains an integer () — the number of queries.
Each of the next lines contains two integers and () – the description of the -th query.
For each query, print the number of suitable pairs of indices after making the change.
Here are notes for first example.
In first query, after update . Now , , , , , and are suitable pairs.
In second query, after update . Now all subarrays of are good.
In third query, after update . Now , , , , and are suitable.
No comments:
Post a Comment