二次联通门 : 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的更多相关文章

  1. 主席树||可持久化线段树||BZOJ 3524: [Poi2014]Couriers||BZOJ 2223: [Coci 2009]PATULJCI||Luogu P3567 [POI2014]KUR-Couriers

    题目:[POI2014]KUR-Couriers 题解: 要求出现次数大于(R-L+1)/2的数,这样的数最多只有一个.我们对序列做主席树,每个节点记录出现的次数和(sum).(这里忽略版本差值问题) ...

  2. Luogu P3577 [POI2014]TUR-Tourism

    Luogu P3577 [POI2014]TUR-Tourism 题目链接 题目大意:给出一张\(n\)个点,\(m\)条边的无向图,保证任意两点之间没有点数超过\(10\)的简单路径.选择第\(i\ ...

  3. P3567 [POI2014]KUR-Couriers

    题目描述 Byteasar works for the BAJ company, which sells computer games. The BAJ company cooperates with ...

  4. [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 ...

  5. 【BZOJ 3524】【Poi2014】Couriers 可持久化线段树

    为什么这个主席树叫可持久化线段树,我不知道,具体得问达神.我无限T,然后DaD3zZ一针见血地指出了我的N*50爆内存导致无限编译超时O)ZO)ZO)Z真是太神啦.以图为鉴: 达神题解传送门:http ...

  6. 【BZOJ】【3524】【POI2014】Couriers

    可持久化线段树 裸可持久化线段树,把区间第K大的rank改成num即可……(往儿子走的时候不减少) 苦逼的我……MLE了一次(N*30),RE了一次(N*10)……数组大小不会开…… 最后开成N*20 ...

  7. BZOJ4377 Kurs szybkiego czytania \ Luogu 3589[POI2015]KUR - 数学思维题

    Solution 我又双叒叕去看题解啦$QAQ$, 真的想不到鸭 输入 $a$ 和 $n$ 互质, 所以满足 $a \times i \ mod \ n$ $(0<=i<n)$ 肯定是不重 ...

  8. luogu P3565 [POI2014]HOT-Hotels

    传送门 无脑暴力+O2=AC 题目要统计距离两两相等的三个点的组数,这三个点之间显然有一个点,并且这三个点到这个点的距离都相同.所以枚举中间这个点作为根,然后bfs整棵树,对于每一层,把以根的某个儿子 ...

  9. luogu P3576 [POI2014]MRO-Ant colony

    传送门 一群蚂蚁能被吃,也就是走到指定边的两端点之一要走到另一端点时有\(k\)只,我们可以从这两端点逆推,记两个值为走到某个点时最后会被吃掉\(k\)只蚂蚁的蚂蚁数量范围,式子下面有,很好理解(雾) ...

随机推荐

  1. golang开发:环境篇(五)实时加载工具gin的使用

    gin 工具是golang开发中非常有用且有效的工具,有效的提高了开发调试go程序的效率. 为什么要使用gin 我们知道golang是编译型语言,这就表示go程序的每次改动,如果需要查看改动结果都必须 ...

  2. 【计数DP】种树

    种树 题目描述 事实上,小X邀请两位奆老来的目的远不止是玩斗地主,主要是为了抓来苦力,替他的后花园种树……小X的后花园是环形的,他想在花园周围均匀地种上n棵树,但是奆老花园的土壤当然非同寻常,每个位置 ...

  3. sidecar-inject代码分析

    Istio通过对serviceMesh中的每个pod注入sidecar,来实现无侵入式的服务治理能力.其中,sidecar的注入是其能力实现的重要一环(本文主要介绍在kubernetes集群中的注入方 ...

  4. (转)FFMPEG类库打开流媒体的方法(需要传参数的时候)

    本文链接:https://blog.csdn.net/leixiaohua1020/article/details/14215393 使用ffmpeg类库进行开发的时候,打开流媒体(或本地文件)的函数 ...

  5. 玩转【Mock.js】,前端也能跑的很溜

    现在开发已经是前后端分离了,前端和后端可以同时进行开发,互不影响,但是有些时候后端开发的接口慢于前端,导致前端需要等待后端的接口完成才能完成前后端对接,为了解决这个痛点,出现了模拟接口数据的方案,目前 ...

  6. Spring Cloud Alibaba学习笔记(7) - Sentinel规则持久化及生产环境使用

    Sentinel 控制台 需要具备下面几个特性: 规则管理及推送,集中管理和推送规则.sentinel-core 提供 API 和扩展接口来接收信息.开发者需要根据自己的环境,选取一个可靠的推送规则方 ...

  7. git bash push 本地的commit到远程 -- ssh keys设置

    1.  检查是否已经创建 ssh keys git bash 下,cd ~/.ssh 如何出现“No such file or directory”,则表示需要创建一个ssh keys. 2. 创建新 ...

  8. Java 之 字节输出流[OutputStream]

    一.字节输出流 java.io.OutputStream 抽象类是表示字节输出流的所有类的超类,将指定的字节信息写出到目的地. 该类中定义了字节输出流的基本共性功能方法. 公性方法: public v ...

  9. ble编程-外设发送数据到中心

    一.外设 1.在外设的.h文件中定义如下   1 //周边管理者 2 3 @property (nonatomic , strong) CBPeripheralManager *peripheralM ...

  10. Python中@staticmethod和@classmethod的作用和区别

    简单介绍一下两者的区别: 对于一般的函数test(x),它跟类和类的实例没有任何关系,直接调用test(x)即可 #!/usr/bin/python # -*- coding:utf-8 -*- de ...