"bzoj3524/2223" [poi2014]couriersApril 19, 2014 1,2571 Description
Give a sequence of length n. 1≤a[i]≤n.
The M-group asks, each time an interval [l,r] is asked, if there is a number that appears in [L,r] greater than (r-l+1)/2. If present, output this number, otherwise output 0.
Input
The first line is two numbers n,m.
Second row n number, A[i].
The next M-line, two numbers per line, l,r to ask [L,r] this interval.
Output
M lines, one answer per line. /*
#include <iostream>
#include <cstdio>
using namespace Std;
int sum[10000010],ls[10000010],rs[100000010],root[500010];
int N,m,sz;
inline int Read ()
{
Char Ch=getchar ();
while (!) ( ch>= ' 0 ' &&ch<= ' 9 ')) Ch=getchar ();
int x=0;
while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ (ch-' 0 '); Ch=getchar ();}
return x;
}
void update (int l,int r,int x,int &y,int v)
{
Y=++sz;
sum[y]=sum[x]+1;
if (l==r)
Return
LS[Y]=LS[X];
RS[Y]=RS[X];
int mid= (L+R) >>1;
if (V<=mid)
Update (L,MID,LS[X],LS[Y],V);
Else
Update (MID+1,R,RS[X],RS[Y],V);
}
int que (int l,int R)
{
int l=1,r=n,mid,x,y,tmp= ((r-l+1) >>1);
X=ROOT[L-1];
Y=ROOT[R];
for (; l!=r;)
{
if (sum[y]-sum[x]<=tmp)
return 0;
Mid= (l+r) >>1;
if (sum[ls[y]]-sum[ls[x]]>tmp)
{
Y=ls[y];
X=LS[X];
R=mid;
}
else if (sum[rs[y]]-sum[rs[x]]>tmp)
{
Y=rs[y];
X=RS[X];
l=mid+1;
}
Else
return 0;
}
return l;
}
int main ()
{
N=read (); M=read ();
for (int i=1;i<=n;i++)
{
int x;
X=read ();
Update (1,N,ROOT[I-1],ROOT[I],X);
}
for (int i=0;i<m;i++)
{
int l,r;
L=read ();
R=read ();
printf ("%d\n", Que (l,r));
}
return 0;
}*/
Chairman Tree Couriers