Poke here: HDU 4020
To facilitate the processing of input information and sequencing it is a classic offline operation method
1#include"bits/stdc++.h"2 using namespacestd;3 intT, N, M, Q;4 structAds5 {6 intU, C, L, Final_rank;7}ads[500010];8 Long Longres[500010];9 Ten BOOLcmp_1 (Ads A, ads B) One { A if(A.u! =b.u) { - returnA.u <b.u; - } the returnA.C >B.C; - } - - BOOLcmp_2 (Ads A, ads B) + { - returnA.final_rank <B.final_rank; + } A at intMain () - { - intT; -scanf"%d", &T); - for(t =1; T <= t; ++t) { - inti; inscanf"%d%d%d", &n, &m, &Q); - for(i =1; I <= M; ++i) { toscanf"%d%d%d", &ads[i]. U, &ads[i]. C, &Ads[i]. L); + } -Sort (ads +1, Ads +1+M, cmp_1); the * //For (i = 1; I <= M; ++i) { $ //printf ("Sorted%d%d%d\n", Ads[i]. U, Ads[i]. C, Ads[i]. L);Panax Notoginseng // } - the intRank =1; +ads[1]. Final_rank =Rank; A for(i =2; I <= M; ++i) { the if(Ads[i]. U = = Ads[i-1]. U) { +++Rank; -Ads[i]. Final_rank =Rank; $ } $ Else { -Rank =1; -Ads[i]. Final_rank =Rank; the } - }WuyiSort (ads +1, Ads +1+M, cmp_2); the - //For (i = 1; I <= M; ++i) { Wu //printf ("Rank = =%d%d%d%d\n", Ads[i]. Final_rank, Ads[i]. U, Ads[i]. C, Ads[i]. L); - // } About $Rank =1; -Res[rank] = ads[1]. L; - for(i =2; I <= M; ++i) { - if(Ads[i]. Final_rank = = Ads[i-1]. Final_rank) { ARes[rank] + =Ads[i]. L; + } the Else { -++Rank; $Res[rank] =Ads[i]. L; theRes[rank] + = Res[rank-1]; the } the } the intRead_rank; -printf"Case #%d:\n", T); in for(i =1; I <= Q; ++i) { thescanf"%d", &Read_rank); theprintf"%i64d\n", Read_rank <= Rank?Res[read_rank]: Res[rank]); About } the } the}
HDU 4020 Ads Proposal offline operation