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 ...
随机推荐
- C++中防止STL中迭代器失效——map/set等关联容器——vector/list/deque等序列容器—如何防止迭代器失效—即erase()的使用
序列性容器::(vector和list和deque) erase迭代器不仅使所有指向被删元素的迭代器失效,而且使被 删元素之后的所有迭代器失效,所以不能使用erase(iter++)的方 式, ...
- webstorm 6.0 注册码
User Name: EMBRACE License Key: ===== LICENSE BEGIN ===== 24718-12042010 00001h6wzKLpfo3gmjJ8xoTPw ...
- iOS项目开发实战——plist数组解析
plist数据是苹果公司创造的数据格式,基于XML,因为在iOS,Mac系统中操作plist很方便,所以我们经常会用到.在iOS项目中.系统会自己主动生成一个Info.plist文件,里面存放了iOS ...
- MaterialImageView
https://github.com/zhaozhentao/MaterialImageView
- 屏蔽微软的SignalR
去年采用ASP.NET MVC开发项目,在谷歌浏览器里调试页面的时候,发现项目在不停地请求数据,链接很奇怪: http://localhost:63004/654c2dd725bb4401b8fc0c ...
- 配置mahout
构建Mahout要求系统事先安装 1)JDK 1.6 或更高版本 2)Maven 2.0.9 或 2.0.10 Mahout是Hadoop的一种高级应用.运行Mahout需要提前安装好Hadoop.H ...
- idea自定义文档注释模板
1.类注释模板 IntelliJ IDE --> Preferences --> Editor --> File and Code Templates --> Includes ...
- POJ3692 Kindergarten —— 二分图最大团
题目链接:http://poj.org/problem?id=3692 Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Sub ...
- string operation in powershell
https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/15/keep-your-hands-clean-use-powershell- ...
- I.MX6 wpa_applicant 开启 debug 输出
/*********************************************************************** * I.MX6 wpa_applicant 开启 de ...