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 ...
随机推荐
- PHPCMS中GET标签概述、 get 标签语法、get 标签创建工具、get 调用本系统演示样例、get 调用其它系统演示样例
一.get 标签概述 通俗来讲,get 标签是Phpcms定义的能直接调用数据库里面内容的简单化.友好化代码,她可调用本系统和外部数据,仅仅有你对SQL有一定的了解,她就是你的绝世好剑!也就是适合熟悉 ...
- Maven实战(七,八)——经常使用Maven插件介绍
我们都知道Maven本质上是一个插件框架,它的核心并不运行不论什么详细的构建任务,全部这些任务都交给插件来完毕,比如编译源代码是由maven-compiler-plugin完毕的.进一步说,每一个任务 ...
- 解决oracle 表被锁住问题
想修改Oracle下的某一张表,提示 "资源正忙, 但指定以 NOWAIT 方式获取资源, 或者超时失效" 看上去是锁住了. 用系统管理员登录进数据库,然后 SELECT sid, ...
- AJAX请求提交数据
1,AJAX准备知识:JSON JSON指的是JavaScript对象表示方法(JavaScript Object Notation) JSON是轻量级的文本数据交换格式 JSON独立于语言 JSON ...
- S2SH的集成(Struts2,Spring,Hibernate)----青软S2SH(笔记)
- C++不能在栈上申请动态内存,而只能依靠指针
以下三种情况皆错,都编译不过: int main(int argc, char* argv[]) { int a; int b[a]; } int main(int argc, char* argv[ ...
- Hadoop Hive概念学习系列之hive里的索引(十三)
Hive支持索引,但是Hive的索引与关系型数据库中的索引并不相同,比如,Hive不支持主键或者外键. Hive索引可以建立在表中的某些列上,以提升一些操作的效率,例如减少MapReduce任务中需要 ...
- Codeforces Round #361 (Div. 2)A. Mike and Cellphone
A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input standar ...
- UVA11183 Teen Girl Squad —— 最小树形图
题目链接:https://vjudge.net/problem/UVA-11183 You are part of a group of n teenage girls armed with cell ...
- eclipse中jsp页面乱码问题
若上述位置均改为utf-8之后,页面展示扔为乱码,检查jsp页面是否有编码说明