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\)只蚂蚁的蚂蚁数量范围,式子下面有,很好理解(雾) ...
随机推荐
- CH09 开机自动烧录QSPI
版本信息: 版本 REV2018 时间 05/22/2018 XILINX ZYNQ LINUX篇 基于米联MZ7X系列 电子版自学资料 常 ...
- unittest之makeSuite\testload\discover及测试报告teseReport
转载:http://www.cnblogs.com/sunny0/p/7771089.html 测试套件suite除了使用addTest以外,还有使用操作起来更更简便的makeSuite\testlo ...
- jQuery控制页面滚动条上下滚动
.向上滚动 $(); .向下滚动 $(); 参数解读:$(this)表示要实现上下滚动的对象,-50表示向上滚动50px , +50表示向下滚动50px ,1000表示滚动速度
- 90% 的 Python 开发者不知道的描述符应用
经过上面的讲解,我们已经知道如何定义描述符,且明白了描述符是如何工作的. 正常人所见过的描述符的用法就是上篇文章提到的那些,我想说的是那只是描述符协议最常见的应用之一,或许你还不知道,其实有很多 Py ...
- VBA Exit For语句
当想要根据特定标准退出For循环时,就可以使用Exit For语句.当执行Exit For时,控件会立即跳转到For循环之后的下一个语句. 语法 以下是在VBA中Exit For语句的语法. Exit ...
- 【转载】常见面试题:C#中String和string的区别分析
在很多人面试C#开发工程师的时候,会遇到一个面试题,就是C#中String和string有啥区别.其实针对这个问题C#中String和string没有本质上的区别,两者在程序中都可使用,稍微的一个区别 ...
- MySQL 数据库的安装与卸载
一.安装 (1)打开下载的 mysql 安装文件双击解压缩,运行“mysql-5.5.40-win32.msi” (2)选择安装类型, 有“Typical(默认) ”. “Complete(完全) ” ...
- 利用 CAKeyframeAnimation实现任意轨迹移动
自定义 View,实现以下方法即可 - (void)drawRect:(CGRect)rect { // Drawing code // 初始化UIBezierPath UIBezierPath ...
- springboot学习入门简易版四---springboot2.0静态资源访问及整合freemarker视图层
2.4.4 SpringBoot静态资源访问(9) Springboot默认提供静态资源目录位置需放在classpath下,目录名需要符合如下规则 /static /public /resourc ...
- ansible自动化部署之场景应用
ansible自动化配置管理 官方网站: https://docs.ansible.com 一.安装 配置 启动 (ansible由红帽收购) (1)什么是ansible ansible是IT自动化配 ...