This title belongs to the topic just do it. . .
CONSIDERING greedy
Number (= x) in the current point is to be deleted when considering its nearest point how many steps required, the nearest you can delete the point 2 k , and this point is the point closest to the front of it, and it is in front of deleted point out there is a cur, so each number required (the current position minus 2 k -cur) times to reach, so come to the program:
#include<bits/stdc++.h> using namespace std; inline int read() { int x(0),neg(1);char ch(getchar()); while(!isdigit(ch)) { if (ch=='-') neg=-1; ch=getchar(); } while(isdigit(ch)) { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*neg; } int n,k,x,cnt,cur; int main() { int ans=0; n=read(),k=read(); for (int i=1;i<=n;++i) { x=read(); if (x==k) { int t=i-(1<<((int)log2(i))); if (t>cur) { ans+=t-cur; cur=t; } cut ++; Why ++ ; } } Printf ( " % d \ n " , ans + ent); return 0 ; }