Let's take a look at the boost: detail: addr_impl_ref template, In the addressof. hpp file:

Source: Internet
Author: User

Question: Give you an inserted sequence, and then output the final sequence. If you use the general method to query as o (n ), the line segment tree query can be optimized to log (n )....
AC code:

[Cpp]
# Include <iostream>
# Include <string. h>
# Include <algorithm>
# Include <cstdio>
# Define CLR (arr, val) memset (arr, val, sizeof (arr ))
# Define lson l, mid, rt <1
# Define rson mid + 1, r, rt <1 | 1
# Define N 200005
Using namespace std;
Typedef struct {
Int l;
Int r;
Int sum;
} Node;
Node node [N <2];
Struct Point
{
Int x;
Int y;
} S1 [N];
Int s [N];
Void push_up (int rt)
{
Node [rt]. sum = node [rt <1]. sum + node [rt <1 | 1]. sum;
}
Void build (int l, int r, int rt)
{
Node [rt]. l = l;
Node [rt]. r = r;
If (l = r ){
Node [rt]. sum = 1;
Return;
}
Int mid = (l + r)> 1;
Build (lson );
Build (rson );
Push_up (rt );
}
Void Quary (int l, int r, int rt, int val, int x)
{
If (node [rt]. l = node [rt]. r)
{
Node [rt]. sum = 0;
S [node [rt]. l] = x;
Return;
}
Int mid = (l + r)> 1;
If (node [rt <1]. sum> = val) Quary (lson, val, x );
Else Quary (rson, val-node [rt <1]. sum, x );
Push_up (rt );
}
Void in (int &)
{
Char ch;
While (ch = getchar () <'0' | ch> '9 ');
For (a = 0; ch> = '0' & ch <= '9'; ch = getchar () a = a * 10 + ch-'0 ';
 
}
Int main ()
{
Int n;
While (~ Scanf ("% d", & n ))
{
CLR (s,-1 );
CLR (node, 0 );
Build (1, n, 1 );
For (int I = 0; I! = N; ++ I) in (s1 [I]. x), s1 [I]. x ++, in (s1 [I]. y );
For (int I = n-1; I> = 0; -- I) Quary (1, n, 1, s1 [I]. x, s1 [I]. y );
For (int I = 1; I <n; ++ I)
Printf ("% d", s [I]);
Printf ("% d \ n", s [n]);
} Return 0;
}

Related Article

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.