loj2341「WC2018」即时战略(随机化,LCT/动态点分治)

loj

Luogu

题解时间

对于 $ datatype = 3 $ 的数据,explore操作次数只有 $ n+log n $ 。

毫无疑问无论什么时候已经探索的区域都是一条链。

每当要探索出一个新点,不是在左侧就是在右侧。

最劣情况下调用次数为 $ 2n $ 。

只要随机打乱探索顺序,额外浪费的次数类似于上升子序列长度,期望 $ logn $ ,可以解决。

而对于其余数据,依然随机打乱探索顺序,

每次对于目标点,要点在于找到距离该点最近的已知点。

可以用动态点分治严格 $ nlogn $ 或LCT均摊 $ nlogn $ 。

#include<bits/stdc++.h>
// #include"rts.h"
int explore(int,int);
using namespace std;
typedef long long lint;
const int N=300011;
int n;
bool vis[N];int lst[N];
namespace task1
{
int fa[N],son[N][2];
int isroot(int x){return son[fa[x]][0]!=x&&son[fa[x]][1]!=x;}
void rot(int x)
{
int y=fa[x],z=fa[y],xis=son[y][1]==x,yis=son[z][1]==y;
if(!isroot(y)) son[z][yis]=x;
fa[x]=z,fa[y]=x,fa[son[x][xis^1]]=y;
son[y][xis]=son[x][xis^1],son[x][xis^1]=y;
}
void splay(int x)
{
while(!isroot(x))
{
int y=fa[x],z=fa[y],xis=son[y][1]==x,yis=son[z][1]==y;
if(!isroot(y)) rot(xis^yis?x:y);rot(x);
}
}
void access(int x){for(int lst=0;x;lst=x,x=fa[x]) splay(x),son[x][1]=lst;}
int anc(int x){while(!isroot(x)) x=fa[x];return x;}
int pre(int x){x=son[x][0];while(son[x][1]) x=son[x][1];return x;}
int nxt(int x){x=son[x][1];while(son[x][0]) x=son[x][0];return x;}
void find(int ep)
{
int x=anc(1);
while(x!=ep)
{
int y=explore(x,ep);if(!vis[y]) vis[y]=1,fa[y]=x,x=y;
else if(y==pre(x)) x=son[x][0];
else if(y==nxt(x)) x=son[x][1];
else x=anc(y);
}access(x);
}
void play(){for(int i=2;i<=n;i++)if(!vis[lst[i]]) find(lst[i]);}
}
namespace task2
{
void access(int &x,int ep){while(x!=ep) vis[x=explore(x,ep)]=1;}
void play()
{
for(int i=2,l=1,r=1,x=0;i<=n;i++)if(!vis[lst[i]])
access(vis[x=explore(r,lst[i])]?l:(vis[x]=1,r=x),lst[i]);
}
}
void play(int n,int lim,int type)
{
::n=n;srand(time(NULL));vis[1]=1;
for(int i=2;i<=n;i++) lst[i]=i;random_shuffle(lst+2,lst+1+n);
if(type!=3) task1::play();else task2::play();
}

最新文章

  1. Unity3D 学习——入门资料整理
  2. spring mvc参数绑定
  3. ASIHTTPRequest实现https双向认证请求
  4. Java的正则表达式
  5. HDU 5046 Airport ( Dancing Links 反复覆盖 )
  6. fetch默认不携带cookie
  7. ubuntu14.04 64位 安装Tomcat
  8. redis 开启远程访问权限
  9. [C++]深入解析结构化异常处理(SEH)
  10. MYSQL ERROR 2003 (HY000): Can&#39;t connect to MySQL server on &#39;192.168.10.210&#39; (111) 解决方法
  11. sqoop导入导出
  12. 2019.01.13 loj#6515. 贪玩蓝月(线段树分治+01背包)
  13. Android4.0 Launcher 源码分析1——Launcher整体结构
  14. Kafka压力测试(自带测试脚本)(单机版)
  15. 【20181031T2】几串字符【数位DP思想+组合数】
  16. zabbix使用之打造邮件报警
  17. Mosquitto服务器的搭建以及SSL/TLS安全通信配置
  18. Java并发(二):Java内存模型
  19. 微软发布SQL Server on Linux
  20. springboot2.1.1 中集成websocket 单元测试异常

热门文章

  1. MySQL快速入门(二)
  2. Django ORM 多表操作
  3. MMU 以及 TLB
  4. Oracle数据库对象(表空间/同义词/序列/视图/索引)
  5. Oracle之SQL语句的分类
  6. 实用TCP协议(1):TCP 协议简介
  7. 爬虫之爬取B站视频及破解知乎登录方法(进阶)
  8. WPF优秀组件推荐之FreeSpire
  9. 基于 vite2 + Vue3 写一个在线帮助文档工具
  10. php session 的使用方法