贺州学院CC


私信TA

用户名:13768543723

访问量:1869

签 名:

等  级
排  名 6803
经  验 1317
参赛次数 5
文章发表 2
年  龄 0
在职情况 学生
学  校 贺州学院
专  业

  自我简介:

解题思路:
既能实现数组的二分查找,又能实现链表的O(1)删除,原来是map。


注意事项:

参考代码:


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

map<int,int> M;

map<int,int>::iterator it,it2;

int getPow(int x){

static ll Pow[33],op=-1;

if(op==-1){

Pow[0]=1;

for(int i=1;i<32;i++){

Pow[i]=Pow[i-1]<<1;

}

op=1;

return upper_bound(Pow,Pow+31,x)-Pow;

}

int main()

{

int n,m,x;

ll sum=0;

scanf("%d%d",&n,&m); 

for(int i=1;i<=n;i++){

scanf("%d",&x);

sum+=x;

M[i]=x;

}

int l,r;

for(int i=1;i<=m;i++){

scanf("%d%d",&l,&r);

for(it=M.lower_bound(l);it!=M.end()&&it->first<=r;){

x=getPow(it->second);

sum-=it->second-x;

it->second=x;

if(x<=2){

it2=it;

it++;

M.erase(it2);

}else{

it++;

}

}

printf("%lld\n",sum);

}

return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区