CF1715C.Monoblock
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Stanley has decided to buy a new desktop PC made by the company "Monoblock", and to solve captcha on their website, he needs to solve the following task.
The awesomeness of an array is the minimum number of blocks of consecutive identical numbers in which the array could be split. For example, the awesomeness of an array
- [1,1,1] is 1 ;
- [5,7] is 2 , as it could be split into blocks [5] and [7] ;
- [1,7,7,7,7,7,7,7,9,9,9,9,9,9,9,9,9] is 3, as it could be split into blocks [1] , [7,7,7,7,7,7,7] , and [9,9,9,9,9,9,9,9,9] .
You are given an array a of length n . There are m queries of two integers i , x . A query i , x means that from now on the i -th element of the array a is equal to x .
After each query print the sum of awesomeness values among all subsegments of array a . In other words, after each query you need to calculate $$$$\sum\limits_{l = 1}^n \sum\limits_{r = l}^n g(l, r), $$ where g(l,r) is the awesomeness of the array b = \[a\_l, a\_{l + 1}, \\ldots, a\_r\]$$.
输入格式
In the first line you are given with two integers n and m ( 1≤n,m≤105 ).
The second line contains n integers a1,a2,…,an ( 1≤ai≤109 ) — the array a .
In the next m lines you are given the descriptions of queries. Each line contains two integers i and x ( 1≤i≤n , 1≤x≤109 ).
输出格式
Print the answer to each query on a new line.
输入输出样例
输入#1
5 5 1 2 3 4 5 3 2 4 2 3 1 2 1 2 2
输出#1
29 23 35 25 35
说明/提示
After the first query a is equal to [1,2,2,4,5] , and the answer is 29 because we can split each of the subsegments the following way:
- [1;1] : [1] , 1 block;
- [1;2] : [1]+[2] , 2 blocks;
- [1;3] : [1]+[2,2] , 2 blocks;
- [1;4] : [1]+[2,2]+[4] , 3 blocks;
- [1;5] : [1]+[2,2]+[4]+[5] , 4 blocks;
- [2;2] : [2] , 1 block;
- [2;3] : [2,2] , 1 block;
- [2;4] : [2,2]+[4] , 2 blocks;
- [2;5] : [2,2]+[4]+[5] , 3 blocks;
- [3;3] : [2] , 1 block;
- [3;4] : [2]+[4] , 2 blocks;
- [3;5] : [2]+[4]+[5] , 3 blocks;
- [4;4] : [4] , 1 block;
- [4;5] : [4]+[5] , 2 blocks;
- [5;5] : [5] , 1 block;
which is 1+2+2+3+4+1+1+2+3+1+2+3+1+2+1=29 in total.