Topic 1: Discount Ticket 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
Interval maximum problem line tree RMQ
Default GCC submission It's disgusting. Two questions ce two times
#include <stdio.h> #include <string.h> #include <math.h> #include < Algorithm>using namespace Std;int a[100000+5];int max_num[100000+5][20];void RMQ (int n) {for (int i=1;i<20;i++ {for (int j=1;j<=n;j++) {if (j+ (1<<i) -1<=n) { Max_num[j][i]=max (max_num[j][i-1],max_num[j+ (1<< (i-1))][i-1]); }}}} int main () {int n,m;while (~SCANF ("%d%d", &n,&m) {memset (a,0,sizeof (a)); Memset (max_num , 0,sizeof (max_num)), int max=0;for (int i=0;i<n;i++) {int t,v;scanf ("%d%d", &t,&v); if (a[t]<v) A[t]=v,max _num[t][0]=v;if (T>max) max=t;} RMQ (Max); for (int i=0;i<m;i++) {int c,d;scanf ("%d%d", &c,&d), int pos= (int) (log (d-c+1.0)/log (2.0)); int Max1=max (max_num[c][pos],max_num[d-(1<<pos) +1][pos]), if (MAX1) printf ("%d\n", max1); else printf ("none\n");}} return 0; }
Topic 1: Discounted tickets (Hihocoder Challenge 20)