Bzoj 3524: [Poi2014]couriers (Chairman tree)

Source: Internet
Author: User

Card I space ....

This question should be the Chairman Tree entry question ... No modification, no discretization ... The people of the industry conscience AH

At the beginning of the blank tree I build out the result is a whole 2n more Node, and then the MLE ...

(double experience, see also)

----------------------------------------------------------------------------------------------

#include <cstdio>#include <cstring>#include <algorithm>#include <iostream> #define REP (i, n) for (int i = 0; i < n; ++i)#define CLR (x, C) memset (x, C, sizeof (x))#define M (L, R) (((L) + (R)) >> 1)using namespace std;const int MAXN = 500000 + 5;struct Node {Node *l, *r;int s;Node (): s (0) {L = R = this;}inline void Update () {s = L-S + R -S;}} pool[10700000], *pt = Pool, *root[MAXN];int v;node* Modify (node* t, int l, int r) {node* h = pt++;if (L = = r)H-s = t-S + 1;else {int m = m (l, R);if (v <= m) {H-L = Modify (T, L, L, m);h-r = t-r;} else {h-l = t, L;H-r = Modify (T-R, M + 1, R);}H-Update ();}return h;}int query (node* l, node* R, int l, int R) {if (L = = r) return l;int m = m (l, R);if (S > V, L-, S-l, L-R)return Query (L-L, R-L, L, m);else if (S > V, r, R, S-l)return Query (L-R, R-r, M + 1, R);return 0;}int main () {freopen ("test.in", "R", stdin);root[0] = pt++;int n, m;cin >> n >> m;Rep (i, N) {scanf ("%d", &v);root[i + 1] = Modify (root[i], 1, n);}While (m--) {int L, R;scanf ("%d%d", &l, &r);v = (r-l + 1) >> 1;printf ("%d\n", Query (root[l-1], root[R], 1, N));}return 0;} 

----------------------------------------------------------------------------------------------

3524: [Poi2014]couriers time limit: Sec Memory Limit: MB
Submit: 782 Solved: 245
[Submit] [Status] [Discuss] 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.

Sample Input7 5
1 1 3 2 3 4 3
1 3
1 4
3 7
1 7
6 6

Sample Output1
0
3
0
4

HINT

"Data Range"

n,m≤500000


Source

by Dzy

Bzoj 3524: [Poi2014]couriers (Chairman tree)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.