洛谷

Codeforces


思路

有一个定理:Erdős–Gallai定理

然后观察样例,可以猜到答案必定是奇偶性相同的一段区间,那么二分左右端点即可。

定理和这个猜测暂时都懒得学/证,留坑。


#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
using namespace std;
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,x,y) for (int i=(x);i>=(y);i--)
#define go(x) for (int i=head[x];i;i=edge[i].nxt)
#define templ template<typename T>
#define sz 505005
typedef long long ll;
typedef double db;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
templ inline void read(T& t)
{
t=0;char f=0,ch=getchar();double d=0.1;
while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
t=(f?-t:t);
}
template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
inline void print(register int x)
{
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
void file()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
#endif
}
inline void chktime()
{
#ifndef ONLINE_JUDGE
cout<<(clock()-t)/1000.0<<'\n';
#endif
}
#ifdef mod
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
ll inv(ll x){return ksm(x,mod-2);}
#else
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
#endif
// inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std; int n;
int aa[sz],a[sz];
ll s[sz]; int check(int w) // return value : 0:ok;1:big;-1:small
{
int n=::n+1,t=1;
rep(i,1,n-1) a[i]=aa[i];a[n]=w;
drep(i,n,2)
if (a[i-1]<=a[i]) swap(a[i-1],a[i]);
else {t=i;break;}
drep(i,n,1) s[i]=s[i+1]+a[i];
int p=n+1;
rep(k,1,n)
{
while (p>1&&a[p-1]<=k) --p;
ll S;
if (p<=k+1) S=1ll*k*(k-1)+s[k+1];
else S=1ll*k*(k-1)+s[p]+1ll*k*(p-1-(k+1)+1);
if (s[1]-s[k+1]<=S) continue;
return p>t?1:-1;
}
return 0;
} int main()
{
file();
int s=0;
read(n);
rep(i,1,n) read(aa[i]),s+=(aa[i]&1);
sort(aa+1,aa+n+1);reverse(aa+1,aa+n+1);
s&=1;
int l,r,L=-1,R=-1;
l=0,r=n/2;
while (l<=r)
{
int mid=(l+r)>>1;
if (check(mid*2+s)>=0) L=mid*2+s,r=mid-1;
else l=mid+1;
}
l=0,r=n/2;
while (l<=r)
{
int mid=(l+r)>>1;
if (check(mid*2+s)<=0) R=mid*2+s,l=mid+1;
else r=mid-1;
}
if (L==-1||R==-1||L>R) puts("-1");
else for (int i=L;i<=R;i+=2) printf("%d ",i);
return 0;
}

Codeforces 1091E New Year and the Acquaintance Estimation [图论]的更多相关文章

  1. Codeforces 1091E New Year and the Acquaintance Estimation Erdős–Gallai定理

    题目链接:E - New Year and the Acquaintance Estimation 题解参考: Havel–Hakimi algorithm 和 Erdős–Gallai theore ...

  2. CF1091E New Year and the Acquaintance Estimation

    题目地址:CF1091E New Year and the Acquaintance Estimation 首先,易知 \(ans\) 的奇偶性与所有给出的数的和的奇偶性相同 其次,易证 \(ans\ ...

  3. Codeforces Round #302 (Div. 2) D - Destroying Roads 图论,最短路

    D - Destroying Roads Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544 ...

  4. codeforces#999 E. Reachability from the Capital(图论加边)

    题目链接: https://codeforces.com/contest/999/problem/E 题意: 在有向图中加边,让$S$点可以到达所有点 数据范围: $ 1 \leq n \leq 50 ...

  5. Codeforces 1299D - Around the World(线性基+图论+dp)

    Codeforces 题目传送门 & 洛谷题目传送门 一道线性基的综合题 %%%%%% 首先注意到"非简单路径""异或和"等字眼,可以本能地想到线性基. ...

  6. 【做题】Codeforces Round #436 (Div. 2) F. Cities Excursions——图论+dfs

    题意:给你一个有向图,多次询问从一个点到另一个点字典序最小的路径上第k个点. 考虑枚举每一个点作为汇点(记为i),计算出其他所有点到i的字典序最小的路径.(当然,枚举源点也是可行的) 首先,我们建一张 ...

  7. Codeforces Round #594 (Div. 1) D. Catowice City 图论

    D. Catowice City In the Catowice city next weekend the cat contest will be held. However, the jury m ...

  8. Codeforces Round #599 (Div. 1) C. Sum Balance 图论 dp

    C. Sum Balance Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to ...

  9. Codeforces Round #599 (Div. 1) B. 0-1 MST 图论

    D. 0-1 MST Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math ...

随机推荐

  1. CorelDrawX8安装时提示已安装另一个版本

    (1)首先卸载VIsualC++ 2015 运行库. (2)如果有VisualC++ 2017运行库,卸载VisualC++2017运行库,即可.

  2. 关于TCP/IOCP构架中出现的Socket假死连接解决方案

    如果在2台不同的公网机器,对TCP的c/s做过详细的压力测试,那么很不幸,会有很多人发现自己的server端会出现大量的假死连接. 假死连接具体表现如下: 1.在s端机器上,会有一些处于TCP_EST ...

  3. 小程序开发 从简单的 crud 开始

    关键字:“小程序 API” [WXML 完成布局] <view> == <div> {{}}  == <%= %> ejs | jsp2 <block wx: ...

  4. pycharm中创建包时加入的_init_.py文件及_all_的作用

    init__.py的主要作用是: 1. Python中package的标识,不能删除 2. 定义__all__用来模糊导入 3. 编写Python代码(不建议在__init__中写python模块,可 ...

  5. 快速安装nginx

    1.创建nignx用户 /usr/sbin/groupadd -f nginx /usr/sbin/useradd -g nginx nginx 2.安装依赖 yum install gcc gcc- ...

  6. [css]将textarea前的文字设置在左上角

    在使用textarea的时候,默认前面的文字是在最下面的,好丑,然后百度了一下,要在textarea加上vertical-align:top的css属性 代码: <div class=" ...

  7. ASP.NET EF 延迟加载,导航属性延迟加载

    ASP.NET EF 延迟加载,导航属性延迟加载   EF(EntityFramework)原理:属于ORM的一种实现 通过edmx文件来查看三部分:概念模型,数据模型,映射关系,上下文DbConte ...

  8. Leetcode#561. Array Partition I(数组拆分 I)

    题目描述 给定长度为 2n 的数组, 你的任务是将这些数分成 n 对, 例如 (a1, b1), (a2, b2), ..., (an, bn) ,使得从1 到 n 的 min(ai, bi) 总和最 ...

  9. Axure8破解码

    升级了 8.0.0.3321 版本后,原来的 license 失效了,解决方法就是使用下面的这组注册码 License:米 业成 (STUDENT)Key:nFmqBBvEqdvbiUjy8NZiyW ...

  10. Python 10 协程,异步IO,Paramiko

    本节内容 Gevent协程 异步IO Paramiko 携程 协程,又称为微线程,纤程(coroutine).是一种用户态的轻量级线程. 协程拥有自己的寄存器上下文和栈.协程调度切换时,将寄存器上下文 ...