• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

题意:

给定一个长度为n .的数组,对于一个值域区间\([x,y]\),如果有一种把原数组分成k个子数组的方法,并且每个子数组中\([x,y]\)中的数严格大于不在\([x,y]\)中的数,则称该值域区间有效。找到最短的范围间隔并输出一个分割方案。

\(1 \阿乐_i\le n\)

思路:

如果能截成\(k ^ 1 \)段,那肯定能截成\(k\)段,所以你只需要看你最多能截多少段。

对于某个\([x,y]\),记录\(a_i\in [x,y]\)为\(1\),否则为\(-1\)。那么当一个子段中的数之和为\(\ge 1\)时,这个子段就是合法的。

注意这个和每次变化1,所以如果某个区间\(a_i,\cdots,a_j\)的和是2,那么可以把它切成两段,每段的和是1。所以为了最大化段数,每个段的和是1。所以你最多可以切掉区间区间内的量——不存在的量段。

随着\(x\)的增加,\(y\)也会增加。让我们用两只手来做。

void sol() {

CINnk;

向量c(n ^ 1,0);

for(int I=1;I=n;i ) cin a,c[a];

int L=0,R=1e9

for(int l=1,r=0,s=0;l=n;l ) {

while(r n(r l | | 2 * s-NK))s=c[r];

如果(2*s-n=k R - L r - l) L=l,R=r

s-=c[l];

}

cout L ' ' R endl

for(int l=1,r=1,s=0,K=0;r=n;r ) {

if(K==k-1)返回cout l ' ' n endl,void();

s=a[R]=L a[R]=R;

if(2*s-(r-l 1)==1) K,s=0,cout l ' ' r endl,l=r 1;

}

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now