ADS proposal
Time Limit: 10000/5000 MS (Java/others) memory limit: 65768/65768 K (Java/Others)
Total submission (s): 1063 accepted submission (s): 410
Problem descriptionthere are n MERs set their m different advertisements on Baidu. each advertisement is owned by single customer. the ADS system of Baidu records the number of clicks of each advertisement this year. the proposal system wants to analysis the advertisements about the relativity of the description length and the number of clicks of the advertisements. during the analysis, it is very important to do such a query to ask the total length of the advertisements with top K clicking times for each customer. you may assume the number of clicks of all advertisements are distinct.
Your task is to help Baidu to design this little toolkit.
Inputthe input consist multiple test cases. The number of test cases is given in the first line of the input.
For each test case, the first line contains three integers n, m and Q, denoting the number customer, the number of advertisement instances and the number of queries. (n <= 100000, m <= 500000, q <= 100000)
Then M lines follow, each line contains three numbers, U, C and L, indicating the owner of this advertisement, the clicks for this advertisement and the length. (1 <= u <= N, 0 <= C, L <= 1000000000)
Finally Q lines come. Each line contains only one integer k, representing the query for top K clicking advertisements for each customer.
Outputfor each test case, output Q lines, each line contains only one integer, denoting the sum of total length of the top k Number of clicks for each customer.
Sample input2 2 4 3 1 12 13 2 23 41 1 21 46 1 22 31 1 2 3 6 15 3 5 2677139 2 731358928 347112028 6 239095183 6 27407970 85994789 6 767687908 6 734935764 3 255454855 813158671 5 617524049 55413590 3 338773814 6 7907652 810348880 2 736644178 777664288 6 63811422 5 590330120 616490361 1 552407488 136492190 5 416295130 448298060 811513162 4 232437061 43273262 4 9 13
Sample outputcase #1: 72 118 131 case #2: 5801137622 5887132411 5887132411
Sourcethe 36th ACM/ICPC Asia Regional Shanghai site -- warmup
The recommendlcy idea is very good, but it feels like it will time out, and it will be OK after optimization... I have not thought of a better solution for the moment.
# Include <stdio. h>
# Include <algorithm>
# Include <iostream>
# Include <stdlib. h>
# Include < String . H>
Using Namespace STD;
Const Int Maxn = 100005 ;
Const Int Maxm = 500005 ;
Int U [maxm], C [maxm], L [maxm];
Int Rank [maxm];
Int Hash [maxn];
Long Long Res [maxm];
Int CMP ( Const Void *, Const Void * B)
{
Return C [*( Int *) B]-C [*( Int *) A];
}
Int Main ()
{
// Freopen ("test. In", "r", stdin );
// Freopen ("test. Out", "W", stdout );
Int T;
Int Icase;
Int I;
Icase = 0 ;
Scanf ( " % D " , & T );
Int N, m, Q;
Int K;
While (T --)
{
Icase ++;
Scanf ( " % D " , & N, & M, & Q );
For (I = 0 ; I <m; I ++)
{
Scanf ( " % D " , & U [I], & C [I], & L [I]);
Rank [I] = I;
}
Memset (hash, 0 , Sizeof (Hash ));
Memset (Res, 0 , Sizeof (RES ));
Qsort (rank, m, Sizeof (Rank [ 0 ]), CMP );
For (I = 0 ; I <m; I ++)
{
Res [++ hash [U [rank [I] + = L [rank [I];
}
For (I = 1 ; I <= m; I ++)
Res [I] + = res [I- 1 ];
Printf ( " Case # % d: \ n " , Icase );
While (Q --)
{
Scanf ( " % D " , & K );
If (K> = m) printf ( " % I64d \ n " , Res [m]);
Else Printf ( " % I64d \ n " , Res [k]);
}
}
Return 0 ;
}