luogu P3567 [POI2014]KUR-Couriers
二次联通门 : luogu P3567 [POI2014]KUR-Couriers
MMP
指针 RE + MLE + WA.....
不得已...向黑恶的数组实力低头

/*
指针 */
#include <algorithm>
#include <cstdio> #define Max 2000009 void read (int &now)
{
now = ;
register char word = getchar ();
while (word < '' || word > '')
word = getchar ();
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
} inline int min (int a, int b)
{
return a < b ? a : b;
} inline int max (int a, int b)
{
return a > b ? a : b;
} struct Segment_Tree_Data
{
Segment_Tree_Data *Left, *Right; int key; Segment_Tree_Data ()
{
key = ;
Left = Right = NULL;
}
}; Segment_Tree_Data *Root[Max]; int N, M; class Lasting_Segment_Tree_Type
{
private : int Query (Segment_Tree_Data *&Last, Segment_Tree_Data *&now, int l, int r)
{
if (l == r)
return l;
register int Mid = l + r >> ;
if (now->Left->key - Last->Left->key > Need)
return Query (Last->Left, now->Left, l, Mid);
else if (now->Left->key - Last->Right->key > Need)
return Query (Last->Right, now->Right, Mid + , r);
return ;
} int Need; public : void Build (Segment_Tree_Data *&now, int l, int r)
{
now = new Segment_Tree_Data;
if (l == r)
return ;
register int Mid = l + r >> ;
Build (now->Left, l, Mid);
Build (now->Right, Mid + , r);
} void Updata (Segment_Tree_Data *Last, Segment_Tree_Data *&now, int pos, int l, int r)
{
now = new Segment_Tree_Data;
now->key = Last->key + ;
if (l == r)
return ;
register int Mid = l + r >> ;
if (pos <= Mid)
{
now->Right = Last->Right;
Updata (Last->Left, now->Left, pos, l, Mid);
}
else
{
now->Left = Last->Left;
Updata (Last->Right, now->Right, pos, Mid + , r);
}
} int Query_Section (int l, int r)
{
Need = r - l + >> ;
return Query (Root[l - ], Root[r], , N);
}
}; Lasting_Segment_Tree_Type Tree; int rank[Max];
int number[Max]; int main (int argc, char *argv[])
{
read (N);
read (M);
Tree.Build (Root[], , N);
for (int i = ; i <= N; i++)
{
read (number[i]);
Root[i] = Root[i - ];
Tree.Updata (Root[i - ], Root[i], number[i], , N);
}
for (int x, y; M--; )
{
read (x);
read (y);
printf ("%d\n", Tree.Query_Section (x, y));
}
return ;
}
数组...
/*
luogu P3567 [POI2014]KUR-Couriers 主席树 + 权值线段树 + 离散化 每次查询的时候向大于r-l+1 / 2的一边走 若查不到则返回0 */
#include <algorithm>
#include <cstdio> #define Max 800006 void read (int &now)
{
now = ;
register char word = getchar ();
while (word < '' || word > '')
word = getchar ();
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
} struct Segment_Tree_Date
{
int Left, Right;
int key; }; int Root[Max]; Segment_Tree_Date tree[Max << ]; class Lasting_Segment_Tree_Type
{ private : int Tree_Count; public : void Build (int &now, int l, int r)
{
now = ++Tree_Count;
if (l == r)
return ;
register int Mid = l + r >> ;
Build (tree[now].Left, l, Mid);
Build (tree[now].Right, Mid + , r);
} void Updata (int Last, int &now, int l, int r, int pos)
{
now = ++Tree_Count;
tree[now].key = tree[Last].key + ;
if (l == r)
return ;
int Mid = l + r >> ;
if (pos <= Mid)
{
tree[now].Right = tree[Last].Right;
Updata (tree[Last].Left, tree[now].Left, l, Mid, pos);
}
else
{
tree[now].Left = tree[Last].Left;
Updata (tree[Last].Right, tree[now].Right, Mid + , r, pos);
}
} int Query (int Last, int now, int l, int r, int Need)
{
if (l == r)
return l;
register int Mid = l + r >> ;
if (tree[tree[now].Left].key - tree[tree[Last].Left].key > Need)
return Query (tree[Last].Left, tree[now].Left, l, Mid, Need);
else if (tree[tree[now].Right].key - tree[tree[Last].Right].key > Need)
return Query (tree[Last].Right, tree[now].Right, Mid + , r, Need);
return ;
}
}; int N, M; int number[Max];
int rank[Max]; Lasting_Segment_Tree_Type Tree; int main (int argc, char *argv[])
{
read (N);
read (M);
for (int i = ; i <= N; i++)
{
read (number[i]);
rank[i] = number[i];
}
std :: sort (rank + , rank + + N);
int Size = std :: unique (rank + , rank + + N) - rank - ;
Tree.Build (Root[], , Size);
for (int i = ; i <= N; i++)
{
number[i] = std :: lower_bound (rank + , rank + + Size, number[i]) - rank;
Tree.Updata (Root[i - ], Root[i], , Size, number[i]);
}
for (int x, y; M--; )
{
read (x);
read (y);
printf ("%d\n", rank[Tree.Query (Root[x - ], Root[y], , Size, y - x + >> )]);
}
return ;
}
luogu P3567 [POI2014]KUR-Couriers的更多相关文章
- 主席树||可持久化线段树||BZOJ 3524: [Poi2014]Couriers||BZOJ 2223: [Coci 2009]PATULJCI||Luogu P3567 [POI2014]KUR-Couriers
题目:[POI2014]KUR-Couriers 题解: 要求出现次数大于(R-L+1)/2的数,这样的数最多只有一个.我们对序列做主席树,每个节点记录出现的次数和(sum).(这里忽略版本差值问题) ...
- Luogu P3577 [POI2014]TUR-Tourism
Luogu P3577 [POI2014]TUR-Tourism 题目链接 题目大意:给出一张\(n\)个点,\(m\)条边的无向图,保证任意两点之间没有点数超过\(10\)的简单路径.选择第\(i\ ...
- P3567 [POI2014]KUR-Couriers
题目描述 Byteasar works for the BAJ company, which sells computer games. The BAJ company cooperates with ...
- [luogu]P3572 [POI2014]PTA-Little Bird(单调队列)
P3572 [POI2014]PTA-Little Bird 题目描述 In the Byteotian Line Forest there are nn trees in a row. On top ...
- 【BZOJ 3524】【Poi2014】Couriers 可持久化线段树
为什么这个主席树叫可持久化线段树,我不知道,具体得问达神.我无限T,然后DaD3zZ一针见血地指出了我的N*50爆内存导致无限编译超时O)ZO)ZO)Z真是太神啦.以图为鉴: 达神题解传送门:http ...
- 【BZOJ】【3524】【POI2014】Couriers
可持久化线段树 裸可持久化线段树,把区间第K大的rank改成num即可……(往儿子走的时候不减少) 苦逼的我……MLE了一次(N*30),RE了一次(N*10)……数组大小不会开…… 最后开成N*20 ...
- BZOJ4377 Kurs szybkiego czytania \ Luogu 3589[POI2015]KUR - 数学思维题
Solution 我又双叒叕去看题解啦$QAQ$, 真的想不到鸭 输入 $a$ 和 $n$ 互质, 所以满足 $a \times i \ mod \ n$ $(0<=i<n)$ 肯定是不重 ...
- luogu P3565 [POI2014]HOT-Hotels
传送门 无脑暴力+O2=AC 题目要统计距离两两相等的三个点的组数,这三个点之间显然有一个点,并且这三个点到这个点的距离都相同.所以枚举中间这个点作为根,然后bfs整棵树,对于每一层,把以根的某个儿子 ...
- luogu P3576 [POI2014]MRO-Ant colony
传送门 一群蚂蚁能被吃,也就是走到指定边的两端点之一要走到另一端点时有\(k\)只,我们可以从这两端点逆推,记两个值为走到某个点时最后会被吃掉\(k\)只蚂蚁的蚂蚁数量范围,式子下面有,很好理解(雾) ...
随机推荐
- gopacket 在 windows 上面遇到的问题
前阵子有个需求是使用 golang 抓包改包,我用到了 gopacket 这个包,但是出了一些小问题. 我按照网上的方法进行使用 OpenLive 抓包,发现并不行,报错 error open ada ...
- Docker 镜像 && 容器的基本操作
镜像 && 容器 docker 镜像好比操作系统的镜像(iso) docker 容器好比是已安装运行的操作系统 所以说 docker 镜像文件运行起来之后,就是我们所说的 docker ...
- Pytorch 1.0升级到Pytorch 1.1.0
Pytorch 1.0Pytorch 1.0于2018-12-8发布,详见https://github.com/pytorch/pytorch/releases/tag/v1.0.0 主要更新JIT全 ...
- List<T> or IList<T>
If you are exposing your class through a library that others will use, you generally want to expos ...
- ORA-01790 错误处理 SQL同一数据库中,两个查询结果数据类型不同时的union all 合
转自: 出现这种错误,要先看一下是不是sql中有用到连接:union,unio all之类的,如果有,需要注意相同名称字段的数据类型一定要相同. 所以在union 或者union all 的时候造成了 ...
- nginx: [emerg] directive "upstream" has no opening "{" in /application/nginx-1.6.3/conf/nginx.conf:13 ...
修改nginx.conf配置文件时,报以下错误: [root@bqh-lb- nginx]# vim conf/nginx.conf [root@bqh-lb- nginx]# sbin/nginx ...
- Linux建立虚拟ip的方法
文章来源 运维公会:Linux建立虚拟ip的方法 1.虚拟ip的介绍 虚拟IP地址(VIP) 是一个不与特定计算机或一个计算机中的网络接口卡(NIC)相连的IP地址.数据包被发送到这个VIP地址, ...
- 国内首本免费深度学习书籍!还有人没Get么?
这本书的作者很有趣鸭. 一开篇别的不说,先跟大家讲哲学,讨论人工智能实现的可能性.摘录一些他的结论: 人工智能可以实现 自由意志并不存在 量子力学并不能证明自由意志的存在 幸福感和物质水平提高并没有绝 ...
- Python_逻辑运算符
1.逻辑运算符
- javascript方法注释
参考资源 文章标题:Javascript注释规范 文章地址:https://blog.csdn.net/lianlin21212411/article/details/78530913 /** * @ ...