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 ...
随机推荐
- HDU 5285 wyh2000 and pupil(dfs或种类并查集)
wyh2000 and pupil Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Other ...
- QtQuick桌面应用开发指导 1)关于教程 2)原型和设计 3)实现UI和功能_A
Release1.0 http://qt-project.org/wiki/developer-guides Qt Quick Application Developer Guide for Desk ...
- Evaluate Reverse Polish Notation --leetcode
原题链接:https://oj.leetcode.com/problems/evaluate-reverse-polish-notation/ 题目大意:给出逆波兰式,然后求其结果. 解题方法:单个栈 ...
- [学习笔记]overthewire bandit 通关秘籍
1.第一关 使用putty等工具连入linux即可,注意port等设置. ls 列目录内文件: cat readme,显示文件内容,即可看到密码. 2.第二关 如何查看文件名为-的文件? cat ./ ...
- [办公自动化]企业网IE多版本引发的网页无法访问
今天同事的某个网页无法打开,但是在我的计算机上该网站确实又能打开. 去看了一下,他的其他网站都正常.确认网络本身没有问题. 最后,看了一下IE版本,IE11. 只好尝试一下兼容性视图的设置. 设置了一 ...
- GridView根据一列自动计算(转载)
<%@ Page Language="C#" %> <%@ Import Namespace="System.Xml" %> <! ...
- debian包之间的关系
1 debian包之间存在两大类关系 第一,依赖 第二,冲突 2 依赖类关系 2.1 depends 2.2 pre-depends 2.3 recommends 2.4 suggests 2.5 e ...
- 安装tensorflow的最简单方法(Ubuntu 16.04 && CentOS)
先说点题外话:在用anaconda安装很多次tensorflow失败之后,我放弃了,如果你遇到这样的问题:Traceback (most recent call last)-如果不是因为pip版本,就 ...
- sqlserver2008Mail
use msdb GO DROP PROC MailTim GO CREATE PROC MailTim @Subject NVARCHAR(100),@Body NVARCHAR( ...
- CentOS 6.6实现永久修改DNS地址的方法
本文实例讲述了CentOS 6.6实现永久修改DNS地址的方法. 百牛信息技术bainiu.ltd整理发布于博客园 分享给大家供大家参考,具体如下:1.配置ip地址文件 /etc/sysconfig/ ...