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\)只蚂蚁的蚂蚁数量范围,式子下面有,很好理解(雾) ...
随机推荐
- Scala 数组操作之数组转换
使用yield和函数式编程转换数组 // 对Array进行转换,获取的还是Array val a = Array(1, 2, 3, 4, 5) val a2 = for (ele <- a) y ...
- CH08 QSPI启动并从EMMC运行APP
8.1 概述 在前一节课,我们必须手动挂载TF卡到mnt,然后输入./a.out程序才能启动.而在嵌入式系统里面,我们很多时候需要实现开机启动程序.很多时候我们会把程序固化到FLASH,然后从EMMC ...
- (转) [组合数学] 第一类,第二类Stirling数,Bell数
一.第二类Stirling数 定理:第二类Stirling数S(p,k)计数的是把p元素集合划分到k个不可区分的盒子里且没有空盒子的划分个数. 证明:元素在哪些盒子并不重要,唯一重要的是各个盒子里装的 ...
- JQuery 文本框控制验证数字
$("input[name=XUEFEN]").keypress(function(event) { var keyCode = event.which; if (keyCode ...
- SVN_05用戶管控
安全性设置 [1]在左侧的User上点击右键 输入上面的信息,点击OK,我们就创建一个用户了. 说明:注意到了下面图中的Groups,是的,也可以先创建组,把用户添加到各个组中,然后对组进行授权,操作 ...
- 艾瑞克·弗洛姆 ( Erich Fromm )
艾瑞克·弗洛姆 ( Erich Fromm ) 来源 https://www.zhihu.com/question/22891103 ------------------------------ 作者 ...
- JS如何做爬虫
JS如何做爬虫,JS做爬虫要靠node节点环境,cheerio(主要是解析下载的网页可以像jquery一样,这是必要的,使用它在npm上查看文档也很简单). Iconv-lite(主要解决下载资源的乱 ...
- dvaJS Model之间的调用
const Model: ModelType = { namespace: 'namesps', state: { data: {} }, effects: { *fetch({ payload, c ...
- iOS Touch Id 开发
Touch Id Touch Id是iPhone5S后加入的一项新的功能,也就是大家熟知的指纹识别技术.大家用得最多的可能是手机的解屏操作,不用在和以前一样输入手机的四位数密码进行验证.一方面不用担心 ...
- USB原理简单叙述
USB简介: USB的几种版本: 1. USB 1.0:速度 1.5Mb/s 2. USB 1.1:速度 12Mb/s 3. USB 2.0:速度 60MbB/s 4. USB 3.0:速度 640M ...