竟然?竟然?竟然?

我已经用了半个键盘的编号了$\text{T_T}$

$\mathbb{AFO}$感稍强

h1是不是有点大?

ZJ+TJ:

T1

以为是什么数据结垢,但是是个链表。

所以可以使用 vector  set  list 维护。

复杂度的话,可证为$O(q \sqrt{N})$

在主定理里tui到点什么。

$\Theta$平均复杂度。

$O$最劣复杂度。

$\Omega$最优复杂度。

于是以后尽量用对。

那么就是这样拉。

首先我们的链表维护的是桶,因为总共只有$N$张牌,

于是$\sum\limits_{i=1}^{n}val_i = N$

那么最多只会有$\sqrt{N}$种取值。

为了使值尽量多,我们将数列$\{ 1,2,3,4,5,6,7,\cdots \}$的前$i$项放入$val$

于是由等差数列求和公式$\frac{k(k+1)}{2}$

得到最多时:

$$
\begin{align}
\frac{k(k+1)}{2} &=& N \\
k &=& \sqrt{N}
\end{align}
$$

#include <iostream>
#include <cstring>
#include <cstdio>
#include <set> //#include "debug.h" #define N 111111
#define M 333333
#define LL long long using namespace std; int qn,cn;
int siz[M],pre[M],val[M];
set<int>cd;
int fa[M]; inline int faind(int x){
if(fa[x]!=x)fa[x]=faind(fa[x]);
return fa[x];
}
void unite(int a,int b){
a=faind(a);
b=faind(b);
fa[a]=b;
siz[b]+=siz[a];
}
int main(){
int opt,a,b,c;
scanf("%d%d",&cn,&qn);
for(int i=1;i<=cn;i++){
fa[i]=i;
siz[i]=1;
}
val[1]=cn;cd.insert(1);
pre[1]=cn;
for(int __i=1;__i<=qn;__i++){
scanf("%d",&opt);
if(opt==1){
// pour(val,1,cn,3,"BVal");
// pour(cd,3,"BeforeI");
scanf("%d%d",&a,&b);
a=faind(a),b=faind(b);
if(a==b)continue;
int sa=siz[a],sb=siz[b],sab=siz[a]+siz[b];
unite(a,b);
val[sa]--;
if(val[sa]==0)cd.erase(sa);
val[sb]--;
if(val[sb]==0)cd.erase(sb);
val[sab]++;
cd.insert(sab);
pre[*cd.begin()]=val[*cd.begin()];
for(auto i=cd.begin();;i++){
auto j=i;j++;
if(j==cd.end())break;
pre[*j]=pre[*i]+val[*j];
}
// pour(val,1,cn,3,"AVal");
// pour(cd,3,"AfterI");
}
else{
// pour(val,1,cn,3,"Q");
// pour(cd,3,"Qcd");
scanf("%d",&c);
LL ans=0;
if(c!=0){
auto i=cd.end(),j=cd.end();
i--,j--;
// puts("VVVVVVVVVVVV");
// Out(*i);Out(c);
// puts("^^^^^^^^^^^^");
while(1){
while(i!=cd.begin() && (*j)-(*i)<c)
i--;
if((*j)-(*i)>=c)
ans+=pre[(*i)]*val[(*j)];
if(j==cd.begin())break;
j--;
}
}
else{
auto fi=cd.end();
fi--;
LL va=pre[*fi];
ans=va*(va-1)/2;
}
printf("%lld\n",ans);
}
}
}

T2,买个坑

T3

水果:

于是大声喊: cin 就是行!

卡常不想写快读,马上 cin 解绑直接上!

把 cin , cout 从C风格缓存中解出来就跑飞快。

但是请注意,

cin 解绑后请不要同时使用 scanf 和 cin ,不然会重复读入。

cout 解绑后请不要同时使用 printf 和 cout ,不然可能会错序输出。

挂了不要来找我

#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#define N 1111111 using namespace std; const int Skyh=700;
int arr[N],pn,lim;
int ans[N]; int main(){
cin.sync_with_stdio(false);
memset(ans,-1,sizeof ans);
cin>>pn>>lim;
for(int i=1;i<=pn;i++)
cin>>arr[i];
if(pn<=30000){
for(int i=1;i<=pn;i++){
int maxn=0,
minn=INT_MAX,
orn=0,
andn=INT_MAX,
red=i-1;
for(int j=i;j<=pn;j++){
maxn=max(maxn,arr[j]);
minn=min(minn,arr[j]);
orn |=arr[j];
andn&=arr[j];
int ykst=minn+orn-maxn-andn;
if(ykst>=lim)
red=j;
}
for(int j=i;j<=red;j++){
ans[j]=max(ans[j],red-i+1);
}
}
}
else{
for(int i=1;i<=pn;i++){
int maxn=0,
minn=INT_MAX,
orn=0,
andn=INT_MAX,
red=i-1;
int qj=min(pn,i+Skyh);
for(int j=i;j<=qj;j++){
maxn=max(maxn,arr[j]);
minn=min(minn,arr[j]);
orn |=arr[j];
andn&=arr[j];
int ykst=minn+orn-maxn-andn;
if(ykst>=lim)
red=j;
}
for(int j=i;j<=red;j++){
ans[j]=max(ans[j],red-i+1);
}
}
}
for(int i=1;i<=pn;i++)
printf("%d ",ans[i]);
puts("");
}

给正解买个坑

19-10-28-A的更多相关文章

  1. 开发笔记-19/10/28 -SpringBoot @Value 获取配置参数

    1. 在application.properties 定义参数 role.taskEvent :参数名称 4:值 ## ---------------------任务角色--------------- ...

  2. 使用yum快速升级CentOS 6.5内核到 3.10.28

    网上有不少升级CentOS内核的文章,如<CentOS 6.5 升级内核到 3.10.28>,大部分都是下载源码编译,有点麻烦. 在yum的ELRepo源中,有mainline(3.13. ...

  3. 背水一战 Windows 10 (28) - 控件(文本类): TextBox, PasswordBox

    [源码下载] 背水一战 Windows 10 (28) - 控件(文本类): TextBox, PasswordBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) T ...

  4. CentOS6.5升级内核到3.10.28 --已验证

    本文适用于CentOS 6.4, CentOS 6.5,估计也适用于其他Linux发行版. 1. 准备工作 确认内核及版本信息 [root@hostname ~]# uname -r 2.6.32-2 ...

  5. 小白的python之路Linux部分10/28&29

    属主属组其他人对文件的rwx权限 1.userdel删东西不全,会有残留,

  6. 第16次Scrum会议(10/28)【欢迎来怼】

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华小组照片 二.开会信息 时间:2017/10/28 17:20~17:32,总计12min.地点:东北师范 ...

  7. CentOS 6.5 升级内核到 3.10.28

    本文适用于CentOS 6.4, CentOS 6.5,亲测可行,估计也适用于其他Linux发行版. 1. 准备工作 1.1 下载源码包 Linux内核版本有两种:稳定版和开发版 ,Linux内核版本 ...

  8. 2016 10 28考试 dp 乱搞 树状数组

    2016 10 28 考试 时间 7:50 AM to 11:15 AM 下载链接: 试题 考试包 这次考试对自己的表现非常不满意!! T1看出来是dp题目,但是在考试过程中并没有推出转移方程,考虑了 ...

  9. Ubuntu 19.10 发布 | 云原生生态周报 Vol. 24

    作者 | 木苏.进超.冬岛.元毅.心水.衷源 业界要闻 1.云原生编程语言 Pulumi 1.0 pulumi ,一款中立的开源云开发平台,Pulumi 支持多语言.混合云环境.完全可扩展.初期支持 ...

  10. [Linux] 在 Ubuntu 19.10 上开启 SSH 服务并允许远程登录

    在 Ubuntu 19.10 上安装 SSH,并开启服务 0.检查并确认系统当前是否已安装SSH: sudo ps -e | grep ssh 如果只有 ssh-agent 说明 ssh-server ...

随机推荐

  1. 20130318 word2013 mathtype

    1.word2013 下如何安装mathtype 1.word2013已经装好 2.下载mathtype6.9 3.   公式编辑器Mathtype安装后无法加载到word的解决办法http://w5 ...

  2. 大道浮屠诀---NBU报错代码之status2

    在一次windows2008R2系统上部署7.7.3备份过程中遇到了此报错 当备份catalog时,会出现status 2报错 经过一系列排查后,得出如下解决方法 1.任务进程中有大量的nbtelem ...

  3. 【23. 合并K个排序链表】【困难】【优先队列/堆排序】

    合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例: 输入: [ 1->4->5, 1->3->4, 2->6] 输出: 1->1-> ...

  4. idea在ssm项目中引入本地的jar

    在对应的lib下,右键找到add...,即可

  5. iOS进阶五-RunLoop

    简介 RunLoop 运行循环.跑圈 RunLoop的作用主要体现在三方面: 1.保持程序持续运行 2.处理App中的各种事件(比如触摸事件.定时器事件.Selector事件) 3.节省CPU资源,提 ...

  6. arm-linux-strip 的使用

    3.2.1    1. 移除所有的符号信息 [arm@localhost gcc]#cp hello hello1 [arm@localhost gcc]#arm­linux­strip ­strip ...

  7. 解决vagrant上使用Homestead很慢(响应速度10s+)

    说明: 使用vagrant和Homestead 在vBox上面跑laravel, 响应速度非常缓慢(大概在10+s), 尝试过增加虚拟机配置, 但是没有任何效果, 经验证也不是数据库的原因 . 通过网 ...

  8. Sublime Text最舒服的主题

    Theme - Afterglow (官网链接) 贴上 preferences -> settings 里面的配置 { "theme": "Afterglow-gr ...

  9. 分享安装Apache、MySQL、PHP、LAMP的完整教程

    Operation timed out after 30000 milliseconds with 0 out of -1 bytes received请注意,在Linux中输入密码时,不会显示您输入 ...

  10. MySQL语句基本操作增删改查

    select * from 表名; --------->效率低