description
because Miss Shinjuku's "little Sister", The island Niang plans to go to Tokyo again in June, but this time it looks like she needs her own pocket. After a few days of battle taking, the island Niang finally in exhaustion, with Python grabbed all June, Shanghai to Tokyo, all the total n tickets. Now, please help the debt-laden island Niang to screen out the ticket for the time interval requirements. The first line of the
input
Input data contains two integers n ,? M (1?≤? N ,? m ? ≤?105), which represents the total number of tickets and the total number of queries. Next n lines, two integers per line t ,? v (1?≤? T ,? v ? ≤?105), indicating the time and price of each ticket departure. The next m line, two integers per line a ,? b (1?≤?a?≤?b?≤?105), which represents the time interval required for each query.
output
For each set of queries, the output line represents the price of . If there is no ticket that meets the requirements, the output line is "None".
-
Sample Input
-
7 All-in-all-in-a-kind, 5
-
sample Output
-
919none5none
-
time limit: 10000ms single point time: 1000ms memory limit: 256mb
PS. Really want to vomit groove that picture = day =
This is a static line-of-tree problem.
#include <cstdio> #include <algorithm> #include <cstring>using namespace std;const int maxn = 1e6+7;int a[maxn];struct node{int L, r, X;} Tickt[maxn*4];void buildtree (int x, int left, int.) {TICKT[X].L = left; TICKT[X].R = right; if (left = = right) {tickt[x].x = A[left]; Return } int mid = (left+right) >> 1; Buildtree (X<<1, left, mid); Buildtree (x<<1|1, mid+1, right); tickt[x].x = Max (tickt[x<<1].x, tickt[x<<1|1].x);} int query (int x, int left, int right) {if (left <= tickt[x].l && TICKT[X].R <= right) return tickt[ x].x; int ans = 0; int mid = (tickt[x].l + tickt[x].r) >> 1; If (mid >= left) ans = max (ans, query (x<<1, left, right)); If (Mid < right) ans = max (ans, query (x<<1|1, left, right)); return ans;} int main () {int m, n; scanf ("%d%d", &n, &m); memset (A, 0, sizeof (a)); for (int i = 1; I <= n; i++) { int x, y; scanf ("%d%d", &x, &y); A[X] = max (a[x], y); } buildtree (1, 1, 100000); for (int i = 1; I <= m; i++) {int from, to; scanf ("%d%d", &from, &to); int p = Query (1, from, to); if (p = = 0) printf ("none\n"); else printf ("%d\n", p); } return 0;}
-
Hiho Coder-1299 Discount Ticket