ABBYY Cup 3.0 - Finals (online version)
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)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 成功解决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 ...
- 使用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版本过 ...
- 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 解决方式 也是要管理员身份运行 重点在最后一句 ...
- 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 ...
- 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 ...
随机推荐
- 【甘道夫】并行化频繁模式挖掘算法FP Growth及其在Mahout下的命令使用
今天调研了并行化频繁模式挖掘算法PFP Growth及其在Mahout下的命令使用,简单记录下试验结果,供以后查阅: 环境:Jdk1.7 + Hadoop2.2.0单机伪集群 + Mahout0.6 ...
- BestCoder Round #2 1001 TIANKENG’s restaurant
不得不说,bastcoder是个hack游戏啊.!. 题意:求最少要多少张椅子才干让全部来的客人有地方坐!! 就是一个区间的处理吧!!!和HDU 1556 我待水似流年.流年待我似水神似! ..! ...
- 记一次Tomcat无法正常启动的查错与解决之路
使用LombozEclipse运行某Web应用,结果总是404. 换另一个Eclipse运行,还是404. 换Tomcat到更高版本,还是404. 直接启动Tomcat,闪退. 用重定向拦截输出,可惜 ...
- 对于api安全性的思考
目前的情况下api被很多地方应用,随之而来的是api的安全性问题. 我所认识到的安全性问题有以下几个方面: 1.DDoS(拒绝服务攻击),接口被恶意调用,使真实的用户无法享受到正常畅通的服务. ...
- 嵌入式开发之davinci---IPIPE、IPIPEIF and ISIF这三者有什么区别
(1)缩写概念 (2)各自区别 (3)不同sensor 采集接口 (4)采集后的数据链路link (5)8127 中的iss和ipipe的区别 (1)缩写概念 http://www.ti.com.cn ...
- PartialView中的页面重定向
在MVC的每个action中,都可以指定一种返回页面的类型,可以是ActionResult,这表示返回的页面为view或者是一个PartialView,前台是一个全整页面,后台是页面的一部分. 在以A ...
- WWDC笔记:2011 Session 125 UITableView Changes, Tips and Tricks
What’s New Automatic Dimensions - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSect ...
- 发布Java桌面程序
我拿了一份桌面工具的开源代码,修修改改,在elipse上运行,感觉良好,但到了发布应用程序,就傻眼了.我居然不知道咋发布! 呵呵,不愧是Java小白! 如果是微软阵营,直接就编译成exe了.但java ...
- 【bzoj1965】[Ahoi2005]SHUFFLE 洗牌
x*2^m==l (mod n+1)x=(n/2+1)^m*l mod n+1 #include<algorithm> #include<iostream> #include& ...
- Map dependencies with code maps
https://docs.microsoft.com/en-us/visualstudio/modeling/map-dependencies-across-your-solutions Instal ...