国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

算法競賽2022年第十三屆藍橋杯C++ B組_砍竹子

2022-04-13 12:18 作者:Clayton_Zhou  | 我要投稿

//?https://www.acwing.com/problem/content/4412/

//? 代碼已經(jīng)通過測試

#include<cstdio>

#include<cctype>

#include<vector>

#include<algorithm>

?#include <iostream>

?#include<math.h>


using namespace std;

const int maxn=210000,maxt=maxn*3;


int n;


long? long B[maxn]={2,1 ,4, 2, 6, 7};


long long MAX[maxt ][5];





void Pushup(int p){//合并信息


MAX[p][0]=max(MAX[p<<1][0],MAX[p<<1|1][0]); //? for update

?MAX[p][2]=max(MAX[p<<1][2],MAX[p<<1|1][2]);

if(MAX[p<<1][0]!=MAX[p<<1|1][0]){

MAX[p][2]=1;

if (MAX[p][0]==MAX[p<<1][0]){? ?// max is on the left

MAX[p][1]=MAX[p<<1][1];

MAX[p][3]=MAX[p<<1][3];

MAX[p][4]=MAX[p<<1][4];

}

else { // max is on the right

MAX[p][1]=MAX[p<<1|1][1];

MAX[p][3]=MAX[p<<1|1][3];

MAX[p][4]=MAX[p<<1|1][4];

}

}

else? ?// 左右最大值相等

{

if(MAX[p<<1][4]+1? != MAX[p<<1|1][3]) // not consecutive

MAX[p][1]=MAX[p<<1][1]+MAX[p<<1|1][1];

else // consecutive

MAX[p][1]=MAX[p<<1][1]+MAX[p<<1|1][1]-1;


MAX[p][3]=MAX[p<<1][3]; // left boundary

MAX[p][4]=MAX[p<<1|1][4]; // right boundary

}

}


void Build(int L,int R,int p ){?

if (L==R){

? MAX[p][0]=B[L];?

? MAX[p][1]=1;? // The number of segments equal to the maximum

? ?MAX[p][2]=0; // All nodes equal to the maximum


? MAX[p][3]=L; // left boundary

? MAX[p][4]=R; // right boundary


//if(p==8)printf("p=8:? %lld? ,? %lld,? ?%lld? \n",MAX[p][0], MAX[p][1], MAX[p][2]); ?

return;

}

int mid=(R+L)>>1;

Build(L,mid,p<<1);Build(mid+1,R,p<<1|1);?

Pushup(p);

}


??

??


void update(int cur,int lt,int rt,int val){

?

if(lt==rt || MAX[cur][2]==0){?

MAX[cur][0]=val;return;?

}

?

int mid=(lt+rt)>>1;


if(MAX[cur<<1][0] ==MAX[cur][0])

update(cur<<1,lt,mid,val);//訪問左孩子

if(MAX[cur<<1|1][0] ==MAX[cur][0])

update(cur<<1|1,mid+1,rt,val);//訪問右孩子

Pushup(cur);//更新信息 ?

}



int main(){

int count=0;

n=6;?

//*

cin >>n;

for(int x=0;x<n;x++)

cin >> B[x];?

//*/

Build(0,n-1,1);

?


int tmp;

while(MAX[1][0]!=1)

{

count += MAX[1][1];

? tmp=sqrt( MAX[1][0]/2+1);??

update(1, 0, n-1, tmp);


/*

for(int x=1;x<10;x++)

{

printf("%lld? ,? %lld,? ?%lld? \n",MAX[x][0], MAX[x][1], MAX[x][2]);

}

printf("\n"); */


}

?

? printf("%d\n",count);

? ?

return 0;

}


算法競賽2022年第十三屆藍橋杯C++ B組_砍竹子的評論 (共 條)

分享到微博請遵守國家法律
静安区| 黔江区| 金川县| 弥勒县| 广宗县| 鄂州市| 潼南县| 泰宁县| 扶余县| 平定县| 仁寿县| 奉贤区| 定西市| 元朗区| 赤壁市| 定兴县| 汝城县| 都安| 宝丰县| 曲阳县| 新蔡县| 康保县| 安图县| 新龙县| 新建县| 镇远县| 呼和浩特市| 阿荣旗| 长沙市| 兰考县| 德江县| 武安市| 溧水县| 安平县| 苏州市| 德州市| 肇庆市| 揭东县| 万山特区| 阳原县| 张家口市|