For the first time, perform the contest of CF... yesterday's Easy question brushed 5 times back to sleep .. the competition started smoothly today .. two major questions: AC .. but there is no more... I did not understand question .. focus on E .. after the competition is over...
Data scope for this question .. it can only be an O (n) or O (nlogn) algorithm .. so it cannot be DP .. however, O (nlogn) cannot find the reason for splitting .. so the idea of this question should go straight to the O (n) algorithm... since it is O (n ).. then the perceptual estimation is to sweep from 1 to n .. process the traversal at the same time .. the result is displayed after scanning .. scan the sum [1 ~ of t from 1 to the current position ~ M] To count... and you can calculate the number of cubes to be deleted based on the current length t and the current bit color x: t-sum [x ~ In t, sum [x] x consecutive .. the key to the problem comes out .. if t-sum [x]> k .. obviously, it will not happen .. what should I do ?..
I recorded a few pieces of information .. s [x] indicates the number of x colors when the current position is t .. B [x] indicates the last feasible position of x starting point .. last [x] represents the starting point of the last x segment .. point [I] records the information of each point .. including next .. that is to say, it fails to jump to the next position... w indicates the number of cubes with the same I-bit color when the value is less than or equal to I...
Then, let's look at my program...
Program:
[Cpp]
# Include <iostream>
# Include <algorithm>
# Include <stdio. h>
# Include <string. h>
# Include <math. h>
# Include <queue>
# Define OOS 2000000000
# Define ll long
Using namespace std;
Struct node
{
Int next, w;
} Point [2, 200005];
Int s [200005], B [200005], last [200005], n, m, k, x, q;
Int main ()
{
Int t, ans, m, p;
Memset (s, 0, sizeof (s ));
Memset (point, 0, sizeof (point ));
Memset (B, 0, sizeof (B ));
Scanf ("% d", & n, & m, & k );
Ans = q = 0;
For (t = 1; t <= n; t ++)
{
Scanf ("% d", & x );
S [x] ++;
If (! B [x])
{
B [x] = t;
Last [x] = t;
Point [t]. w = s [x];
} Else
If (x! = Q)
{
Point [last [x]. next = t;
Point [t]. w = s [x];
Last [x] = t;
}
Q = x;
M = t-B [x] + 1;
While (m-(s [x]-point [B [x]. w + 1)> k)
{
B [x] = point [B [x]. next;
M = t-B [x] + 1;
} Www.2cto.com
If (s [x]-point [B [x]. w + 1> ans) ans = s [x]-point [B [x]. w + 1;
}
Printf ("% d \ n", ans );
Return 0;
}