Topic 1: Discounted tickets (Hihocoder 20 Challenge)

Source: Internet
Author: User


Time limit:10000msSingle Point time limit:1000msMemory Limit:256MB
Describe

Because Miss Shinjuku's "little Sister", the island Niang plans to go to Tokyo in June, but this time it seems she needs to pay her own pocket. After a few days of battle taking, the island Niang finally exhausted, with Python grabbed all June, Shanghai to Tokyo, all n tickets. Now, please help the debt-laden island Niang to screen out the most expensive tickets that meet the requirements of the time range.

Input

The first line of the input data contains two integers n . m (1?≤ n ,? m ? ≤?105), indicating the total number of tickets, and the total number of inquiries. The next n line, two integers per line t ,? v (1?≤ t ,? v ? ≤?105), indicating the time and price per ticket departure. The next m line, two integers per line a ,? b (1?≤?a?≤?b?≤?105), which indicates the time interval required for each inquiry.

Output

For each set of queries, the output line represents the most expensive price. If there is no ticket that meets the requirements, the output line is "None".

Sample input
7 61 12 14 34 44 56 97 91 71 26 73 34 45 5
Sample output
919none5none
Analysis: It is obvious that the segment tree interval to find the most value, the difference: there is discontinuity point special treatment
 
/*7-5919none5none*/#include <cstdio> #include <cstring> #include <vect---- or> #include <iostream> #include <algorithm> #define INF-0XFCONST int maxn=1000005;using namespace STD;    struct node{int id; int price;};    int segtree[maxn];int a[maxn];void Build (int node, int b, int e) {if (b = = e) Segtree[node] = a[b];        else {Build (2*node, B, (b+e)/2);        Build (2*node+1, (b+e)/2+1, E);        if (SEGTREE[2 * node] >= segtree[2 * node + 1]) Segtree[node] = segtree[2 * node];    else Segtree[node] = segtree[2 * node + 1];    }}int Query (int node,int b,int e,int left,int right) {if (B>=left && e<=right) return Segtree[node];    int m= (b+e)/2;    int sum=0;    if (left<=m) Sum=max (Sum,query (node<<1,b,m,left,right));    if (right>m) Sum=max (Sum,query (node<<1|1,m+1,e,left,right)); return sum;}    int main () {int n,m; scanf ("%d%d", &n,&m);   int a1,a2;    for (int i=1;i<=n;i++) A[i]=inf;        for (int i=1;i<=n;i++) {scanf ("%d%d", &AMP;A1,&AMP;A2);        if (a[a1] = = INF) a[a1]=a2;    else A[a1]=max (A[A1],A2);    } Build (1,1,n);        for (int i=1;i<=m;i++) {scanf ("%d%d", &AMP;A1,&AMP;A2);        int Ans=query (1,1,N,A1,A2);    if (ans = = 0) printf ("none\n");//Special for Else printf ("%d\n", ans); } return 0;}

Topic 1: Discounted tickets (Hihocoder 20 Challenge)

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.