A 开个数组记录一下

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
#define LL long long
#define INF 1e10
#define N 300010
LL sum[N];
int a[N];
int pa[N];
map<int,int>f;
int main()
{
int n,i,g=,x;
cin>>n;
for(i = ; i <= n ;i++)
{
cin>>a[i];
if(a[i]>)
sum[i] = sum[i-]+a[i];
else
sum[i] = sum[i-];
f[a[i]] = i;
}
LL maxz=-INF;
for(i = ; i <= n ;i++)
{
if(i==f[a[i]]) continue;
LL s = sum[f[a[i]]]-sum[i-];
if(a[i]<) s+=*a[i];
if(maxz<s)
{
x = i;
maxz = s;
}
}
for(i = ; i < x ;i++)
pa[++g] = i;
for(i = f[a[x]]+ ; i <= n ;i++)
pa[++g] = i;
for(i = x+ ; i < f[a[x]] ; i++)
if(a[i]<)
{
g++;
pa[g] = i;
}
cout<<maxz<<" "<<g<<endl;
sort(pa+,pa+g+);
for(i = ; i < g ; i++)
cout<<pa[i]<<" ";
if(g)
cout<<pa[g]<<endl;
return ;
}

B 线段树 连续的数中较大的数的位置如果比较小的小得话 就+1 求和询问下就行
把L写成了1 悲剧了。。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
using namespace std;
#define LL long long
#define INF 1e10
#define N 300010
int a[N],po[N];
int s[N<<];
void up(int w)
{
s[w] = s[w<<]+s[w<<|];
}
void build(int l,int r,int w)
{
if(l==r)
{
if(po[l]>po[l+])
s[w] = ;
else s[w] = ;
return ;
}
int m = (l+r)>>;
build(l,m,w<<);
build(m+,r,w<<|);
up(w);
}
int query(int a,int b,int l,int r,int w)
{
if(a<=l&&b>=r)
{
return s[w];
}
int m = (l+r)>>;
int ans = ;
if(a<=m)
ans+=query(a,b,l,m,w<<);
if(b>m)
ans+=query(a,b,m+,r,w<<|);
return ans;
}
void update(int p,int l,int r,int w)
{
if(l==r)
{
if(po[l+]<po[l])
s[w] = ;
else s[w] = ;
return ;
}
int m = (l+r)>>;
if(p<=m)
update(p,l,m,w<<);
else
update(p,m+,r,w<<|);
up(w);
}
int main()
{
int i,q,k,n;
cin>>n;
for(i = ;i <= n ;i++)
{
cin>>a[i];
po[a[i]] = i;
}
build(,n-,);
cin>>q;
while(q--)
{
cin>>k;
int x,y;
if(k==)
{
cin>>x>>y;
cout<<query(x,y-,,n-,)+<<endl;
}
else
{
cin>>x>>y;
po[a[x]] = y;
po[a[y]] = x;
swap(a[x],a[y]);
if(a[x]<n)
update(a[x],,n-,);
int k = a[x]-;
if(k>&&k<n)
update(k,,n-,);
if(a[y]<n)
update(a[y],,n-,);
k = a[y]-;
if(k>&&k<n)
update(k,,n-,);
}
}
return ;
}

C1 拿背包做的 因为不知道每次都应该减最大的
C2 知道了这个结论 可以先暴力出10^6 把10^12分为两部分 循环前一部分 这样复杂度指数级减小一般 然后开个二维数组c[i][j] 一维表示前一部分数的最大值 然后暴力j

这样每次减到《=0  小于0的部分再下一次循环中减去

注意点 减到0的时候 需注意要减的值 比如3999999 第一次减到3000000的话 下次不能直接循环c[2][1000000] 而是可以减一次3

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define LL long long
#define N 1000000
#define INF 0xfffffff
int dp[][N+];
int o[][N+];
int main()
{
int i,j;
LL n;
for(i = ;i <= ; i++)
{
dp[i][] = ;
}
for(i = ; i <= ; i++)
for(j = ; j <= N ;j++)
{
int mm = i;
int k = j;
while(k)
{
int x = k%;
mm = max(mm,x);
k/=;
}
if(mm>=j)
{
dp[i][j] = dp[i][]+;
o[i][j] = j-mm;
}
else
{
dp[i][j] = dp[i][j-mm]+;
o[i][j] = o[i][j-mm];
}
}
while(cin>>n)
{
if(n<=N)
{
cout<<dp[][n]<<endl;
continue;
}
LL m = n%N,nm = n/N;
LL s = ;
int k = ;
for(i = nm ; i >= ; i--)
{
int y = i,ma = ;
while(y)
{
int x = y%;
y/=;
ma = max(ma,x);
}
if(i!=nm) m = N+k;
s += dp[ma][m];
k = o[ma][m];
if(k==&&i!=)
{
s++;
k = -ma;
}
}
cout<<s<<endl;
}
return ;
}

ABBYY Cup 3.0 - Finals (online version)的更多相关文章

  1. codeforce ABBYY Cup 3.0 - Finals (online version) B2. Shave Beaver! 线段树

    B2. Shave Beaver!   The Smart Beaver has recently designed and built an innovative nanotechnologic a ...

  2. composer install 遇到问题 Problem 1 - phpunit/phpunit 5.7.5 requires php ^5.6 || ^7.0 -> your PHP version (5.5.3 0) does not satisfy that requirement.

    $ composer install Loading composer repositories with package information Updating dependencies (inc ...

  3. Pycharm 中You are using pip version 10.0.1, however version 18.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.

    今天运行程序的时候出现了: You are using pip version 10.0.1, however version 18.1 is available.You should conside ...

  4. pip install psutil出错-You are using pip version 10.0.1, however version 18.0 is available.

    今天想用python代替shell做运维相关的事,写代码都是在本机,调试在服务器上 C:\Users\0>pip install psutilRequirement already satisf ...

  5. 成功解决You are using pip version 9.0.1, however version 9.0.3 is available. You should consider upgra

    解决问题 You are using pip version 9.0.3, however version 10.0.1 is available.You should consider upgrad ...

  6. 使用pip命令报You are using pip version 9.0.3, however version 18.0 is available pip版本过期.解决方案

    使用pip命令安装或卸载第三方库时报You are using pip version 9.0.3, however version 18.0 is available.错误,一般情况下是pip版本过 ...

  7. pip安装selenium时,报错“You are using pip version 10.0.1, however version 18.0 is available.”的问题

    pip安装selenium,pip install selenium 类型这样错误 1  原因可能不是以管理员身份运行cmd安装selenium 2  解决方式 也是要管理员身份运行 重点在最后一句 ...

  8. Python pip安装时You are using pip version 9.0.1, however version 18.0 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.

    在我们安装第三方库的时候会在结尾出现如下两行内容 You are using pip version 9.0.1, however version 18.0 is available. You sho ...

  9. You are using pip version 10.0.1, however version 20.2.2 is available.

    在安装第三方库时,出现如下提示: You are using pip version 10.0.1, however version 20.2.2 is available.You should co ...

随机推荐

  1. Failed to load resource: the server responded with a status of 404 (Not Found)

    Failed to load resource: the server responded with a status of 404 (Not Found) 报错情况:图标加载失败 原因分析:路径错误 ...

  2. 每天一个JavaScript实例-获取元素当前高度

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  3. webstorm 6.0 注册码

    User Name: EMBRACE   License Key: ===== LICENSE BEGIN ===== 24718-12042010 00001h6wzKLpfo3gmjJ8xoTPw ...

  4. Mongodb for PHP教程之数据操作

    Mongodb的常用操作 参看手册,php官方的http://us2.php.net/manual/en/mongo.manual.php 也可以参看mongodb官方的教程 数据库连接 ⑴默认格式 ...

  5. XxPay支付系统-boot版本 使用

    https://segmentfault.com/a/1190000016987391?utm_source=tag-newest 有三个版本: spring boot 版本: spring clou ...

  6. 手机阅读行业SWOT分析

    上个星期,在公司内部的分享活动上给童鞋们分享了手机阅读行业现状,小伙伴儿们嗷嗷待哺的眼神促使我把PPT转换为博客里的文字和图片,再一次更加深入地进入手机阅读. 通过SWOT分析分析我们能够对手机阅读行 ...

  7. Delphi全角转半角

    function ToDBC( input :String):WideString;varc:WideString;i:Integer;beginc := input;for i:=1 to Leng ...

  8. YTU 1008: 童年生活二三事

    1008: 童年生活二三事 时间限制: 1000 Sec  内存限制: 64 MB 提交: 842  解决: 592 题目描述 Redraiment小时候走路喜欢蹦蹦跳跳,他最喜欢在楼梯上跳来跳去. ...

  9. codeforces 689E E. Mike and Geometry Problem(组合数学)

    题目链接: E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes ...

  10. 三.OC基础--1.NSString的创建和使用,2多文件开发,3类方法,4封装

    三:OC--1.NSString的创建和使用, 1,创建常量字符串,注意使用“@“符号. NSString *astring = @"This is a String!"; //后 ...