Codeforces Global Round 1 自闭记
A:签到。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int b,k,a[100010];
signed main()
{
/*#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
const char LL[]="%I64d\n";
#endif*/
b=read(),k=read();b&=1;
for (int i=1;i<=k;i++) a[i]=read();
if (b==0)
{
if (a[k]&1) cout<<"odd";
else cout<<"even";
}
else
{
int s=0;
for (int i=1;i<=k;i++) s+=a[i];
if (s&1) cout<<"odd";
else cout<<"even";
}
return 0;
//NOTICE LONG LONG!!!!!
}
B:显然先连接距离较小的点。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,k,a[N],b[N],ans;
signed main()
{
/*#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
const char LL[]="%I64d\n";
#endif*/
n=read(),m=read(),k=read();
for (int i=1;i<=n;i++) a[i]=read();
ans=a[n]-a[1]+1;
for (int i=2;i<=n;i++) b[i]=a[i]-a[i-1];
sort(b+2,b+n+1);reverse(b+2,b+n+1);
for (int i=2;i<=k;i++) ans-=b[i]-1;
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}
C:当a!=2k-1时,令k为满足2k-1>a的最小正整数,显然可以令b=2k-1^a使答案成为2k-1,并且显然不可能更优。a=2k-1时直接暴力打表。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int q,ans[1<<25];
signed main()
{
/*#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
const char LL[]="%I64d\n";
#endif*/
q=read();
for (int i=1;i<=22;i++)
{
for (int j=1;j<(1<<i)-1;j++)
ans[(1<<i)-1]=max(ans[(1<<i)-1],gcd((1<<i)-1&j,(1<<i)-1^j));
}
ans[(1<<23)-1]=178481;
ans[(1<<24)-1]=5592405;
ans[(1<<25)-1]=1082401;
while (q--)
{
int x=read();
if (ans[x]>0) printf("%d\n",ans[x]);
else
{
while (x!=(x&-x)) x^=x&-x;
printf("%d\n",(x<<1)-1);
}
}
return 0;
//NOTICE LONG LONG!!!!!
}
E:https://www.cnblogs.com/Gloid/p/10060025.html 作为一个做过所谓原题的选手看了1h这个题感到十分自闭。事实上第一眼就想到了这个原题,发现并不一样之后就去梦游了。毕竟当时也不是用前缀和的做法做的,而是自己想了半天搞了个做法还觉得挺nb,反应不过来也挺正常。但现在感觉我这做法好像也能类似的搬过来?自闭了啊?
比较差分集合是否相同即可,因为每次操作相当于交换差分数组中相邻两数。注意特判首尾。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,q[N<<4],head,tail,cnt;
ll a[N],b[N];
bool flag[N];
signed main()
{
/*#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
const char LL[]="%I64d\n";
#endif*/
n=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=n;i++) b[i]=read();
if (a[1]!=b[1]||a[n]!=b[n]) {cout<<"No";return 0;}
for (int i=n;i>=1;i--) a[i]-=a[i-1];
for (int i=n;i>=1;i--) b[i]-=b[i-1];
sort(a+1,a+n+1);
sort(b+1,b+n+1);
for (int i=1;i<=n;i++) if (a[i]!=b[i]) {cout<<"No";return 0;}
cout<<"Yes";
return 0;
//NOTICE LONG LONG!!!!!
}
D:注意到一定存在最优方案使得同种顺子最多出两次。然后就是普及组dp了。我这种弱智怎么可能注意的到啊。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define N 1000010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,u,a[N],f[N][3][3];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
const char LL[]="%I64d\n";
#endif
n=read(),m=read();
for (int i=1;i<=n;i++) a[read()]++;
memset(f,200,sizeof(f));
f[0][0][0]=0;
for (int i=1;i<=m+2;i++)
for (int j=0;j<=2;j++)
for (int k=0;k<=2;k++)
for (int x=0;x<=2;x++)
if (k<=a[i]&&j+k<=a[i-1]&&j+k+x<=a[i-2])
f[i][j][k]=max(f[i][j][k],f[i-1][x][j]+x+(a[i-2]-j-k-x)/3);
cout<<f[m+2][0][0];
return 0;
//NOTICE LONG LONG!!!!!
}
F:对dfs序建线段树维护当前点到每个点的距离(非叶子设为inf),询问按dfs序离线,然后整棵树dfs一遍并维护距离即可,这个维护仅仅是线段树上的区间加和区间减。我觉得比D简单多了!算了云选手没资格说话。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define N 500010
#define inf 100000000000000000ll
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,fa[N],p[N],len[N],dfn[N],id[N],L[N<<2],R[N<<2],size[N],t,cnt,cur;
ll deep[N],ans[N],tree[N<<2],lazy[N<<2];
struct data
{
int to,len;
bool operator <(const data&a) const
{
return to<a.to;
}
};
vector<data> edge[N];
struct data2
{
int x,l,r,i;
bool operator <(const data2&a) const
{
return dfn[x]<dfn[a.x];
}
}q[N];
void addedge(int x,int y,int z){edge[x].push_back((data){y,z});}
void dfs(int k)
{
dfn[k]=++cnt;id[cnt]=k;size[k]=1;
for (int i=0;i<edge[k].size();i++)
{
deep[edge[k][i].to]=deep[k]+edge[k][i].len;
dfs(edge[k][i].to);
size[k]+=size[edge[k][i].to];
}
if (edge[k].size()) deep[k]=inf;
}
void up(int k){tree[k]=min(tree[k<<1],tree[k<<1|1]);}
void build(int k,int l,int r)
{
L[k]=l,R[k]=r;
if (l==r)
{
tree[k]=deep[id[l]];
return;
}
int mid=l+r>>1;
build(k<<1,l,mid);
build(k<<1|1,mid+1,r);
up(k);
}
void update(int k,ll x){tree[k]+=x;lazy[k]+=x;}
void down(int k){update(k<<1,lazy[k]),update(k<<1|1,lazy[k]),lazy[k]=0;}
void add(int k,int l,int r,int x)
{
if (l>r) return;
if (L[k]==l&&R[k]==r) {update(k,x);return;}
if (lazy[k]) down(k);
int mid=L[k]+R[k]>>1;
if (r<=mid) add(k<<1,l,r,x);
else if (l>mid) add(k<<1|1,l,r,x);
else add(k<<1,l,mid,x),add(k<<1|1,mid+1,r,x);
up(k);
}
ll query(int k,int l,int r)
{
if (L[k]==l&&R[k]==r) return tree[k];
if (lazy[k]) down(k);
int mid=L[k]+R[k]>>1;
if (r<=mid) return query(k<<1,l,r);
else if (l>mid) return query(k<<1|1,l,r);
else return min(query(k<<1,l,mid),query(k<<1|1,mid+1,r));
}
void work(int k)
{
while (k==q[cur+1].x) cur++,ans[q[cur].i]=query(1,q[cur].l,q[cur].r);
for (int i=0;i<edge[k].size();i++)
{
int to=edge[k][i].to;
add(1,dfn[to],dfn[to]+size[to]-1,-edge[k][i].len);
add(1,1,dfn[to]-1,edge[k][i].len);
add(1,dfn[to]+size[to],n,edge[k][i].len);
work(to);
add(1,dfn[to],dfn[to]+size[to]-1,edge[k][i].len);
add(1,1,dfn[to]-1,-edge[k][i].len);
add(1,dfn[to]+size[to],n,-edge[k][i].len);
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read();
for (int i=2;i<=n;i++)
{
fa[i]=read();len[i]=read();
addedge(fa[i],i,len[i]);
}
for (int i=1;i<=n;i++) sort(edge[i].begin(),edge[i].end());
dfs(1);
for (int i=1;i<=m;i++) q[i].x=read(),q[i].l=read(),q[i].r=read(),q[i].i=i;
sort(q+1,q+m+1);
build(1,1,n);
work(1);
for (int i=1;i<=m;i++) printf("%I64d\n",ans[i]);
return 0;
//NOTICE LONG LONG!!!!!
}
div1+div2的场从来没进过前400,自闭了。
result:rank 420 rating +22
Codeforces Global Round 1 自闭记的更多相关文章
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Global Round 2 题解
Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
- Codeforces Global Round 11 个人题解(B题)
Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...
- 【Codeforces Round 1110】Codeforces Global Round 1
Codeforces Round 1110 这场比赛只做了\(A\).\(B\).\(C\),排名\(905\),不好. 主要的问题在\(D\)题上,有\(505\)人做出,但我没做出来. 考虑的时候 ...
随机推荐
- Java性能优化之String字符串优化
字符串是软件开发中最重要的对象之一.通常,字符串对象在内存中是占据了最大的空间块,因此如何高效地处理字符串,必将是提高整体性能的关键所在. 1.字符串对象及其特点 Java中八大基本数据类型没有Str ...
- 从源码看Spring Security之采坑笔记(Spring Boot篇)
一:唠嗑 鼓捣了两天的Spring Security,踩了不少坑.如果你在学Spring Security,恰好又是使用的Spring Boot,那么给我点个赞吧!这篇博客将会让你了解Spring S ...
- python--Numpy and Pandas 笔记01
博客地址:http://www.cnblogs.com/yudanqu/ 1 import numpy as np import pandas as pd from pandas import Ser ...
- 使用insert ignore来避免向数据库重复插入数据
mysql中 insert ignore 的使用示例如下: INSERT IGNORE INTO `table_name` (`reportid`, `content`) VALUES (‘11111 ...
- 使用git将项目上传到github
使用git将项目上传到github(最简单方法) 首先你需要一个github账号,所有还没有的话先去注册吧! https://github.com/ 我们使用git需要先安装git工具,这里给出下 ...
- [options] 未与 -source 1.6 一起设置引导类路径
用ant与eclipse编译Cassandra 1.2.19,出现了“ [options] 未与 -source1.6一起设置引导类路径”的警告,并出现了一些编译错误,提示编译失败,上网找了很 多资料 ...
- Linux&Windows中VNC协议及使用方法
[转载]window下使用vnc远程登录ubuntu/linux图形界面_五个粽子_新浪博客http://blog.sina.com.cn/s/blog_677265f601012mqg.html V ...
- MySQL之数据导入导出
日常开发中,经常会涉及到对于数据库中数据的导入与导出操作,格式也有很多: TXT,CSV,XLS,SQL等格式,所以,在此总结一下,省的总是百度查询. 一 导出 1) 常用的方式就是使用现成的工具例如 ...
- vue组件内部引入远程js文件
之所以要做这个是因为,在一个组件内部需要引入一个js文件来定位.如果放在index.html,这样每个组件都会有这个js.所以需要在组件内单独引入. 第一种操作 Dom引入js: export def ...
- [转帖]Ipvsadm参数详解(常用命令)
Ipvsadm参数详解(常用命令) 2013年11月29日 12:41:40 怀素1980 阅读数:15901 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.cs ...