/********************************************************************************
模拟,用个set再派个序就好了~
********************************************************************************/
#include <iostream>
#include <functional>
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <utility>
#include <bitset>
#include <cstdio>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) ( (x) & ( (x) ^ (x - 1) ) )
//typedef long long LL; //GMU C++
//typedef unsigned long long ULL;
typedef __int64 LL; //Visual C++ 2010
typedef unsigned __int64 ULL;
typedef double LF;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef map<int, int>::iterator MI;
typedef vector<int>::iterator VI;
typedef list<LL>::iterator LI;
typedef set<int>::iterator SI;
const int INF_INT = 0x3f3f3f3f;
const LL INF_LL = 0x7fffffffffffffffLL;
const double oo = 10e9;
const double eps = 10e-7;
const double PI = acos(-1.0);
const int MAXN = 100004;
const int MAXM = 500004;
const int MAXQ = 100004;
struct Ads
{
int own, clk, len;
}ads[MAXM];
struct Qst
{
int id, key;
LL ans;
}qst[MAXQ];
set<int>ST;
int test, n, m, q;
int ptr[MAXN], ptt[MAXN], ncnt[MAXN];
inline bool cmp_own_clk(const Ads &na, const Ads &nb)
{
return na.own != nb.own ? na.own < nb.own : na.clk > nb.clk;
}
inline bool cmp_id(const Qst &qa, const Qst &qb)
{
return qa.id < qb.id;
}
inline bool cmp_key(const Qst &qa, const Qst &qb)
{
return qa.key < qb.key;
}
void solve()
{
int crt;
for (SI it = ST.begin(); it != ST.end(); )
{
crt = *it;
while (ptt[crt] - ptr[crt] + 1 <= ncnt[crt] && ptt[crt] - ptr[crt] + 1 <= qst[0].key)
{
qst[0].ans += ads[ ptt[crt]++ ].len;
}
if (ptt[crt] - ptr[crt] + 1 > ncnt[crt])
{
SI ip = it;
++it;
ST.erase(ip);
continue ;
}
++it;
}
for (int ind = 1; ind < q; ++ind)
{
qst[ind].ans = qst[ind - 1].ans;
if (qst[ind].key == qst[ind - 1].key || ST.empty())
{
continue ;
}
for (SI it = ST.begin(); it != ST.end(); )
{
crt = *it;
while (ptt[crt] - ptr[crt] + 1 <= ncnt[crt] && ptt[crt] - ptr[crt] + 1 <= qst[ind].key)
{
qst[ind].ans += ads[ ptt[crt]++ ].len;
}
if (ptt[crt] - ptr[crt] + 1 > ncnt[crt])
{
SI ip = it;
++it;
ST.erase(ip);
continue ;
}
++it;
}
}
return ;
}
void ace()
{
int cas = 1;
for (scanf("%d", &test); test--; ++cas)
{
scanf("%d %d %d", &n, &m, &q);
memset(ncnt, 0, sizeof(ncnt));
ST.clear();
for (int i = 0; i < m; ++i)
{
scanf("%d %d %d", &ads[i].own, &ads[i].clk, &ads[i].len);
}
sort(ads, ads + m, cmp_own_clk);
ST.insert(ads[0].own);
++ncnt[ ads[0].own ];
ptr[ ads[0].own ] = ptt[ ads[0].own ] = 0;
for (int i = 1; i < m; ++i)
{
++ncnt[ ads[i].own ];
if (ads[i].own != ads[i - 1].own)
{
ST.insert(ads[i].own);
ptr[ ads[i].own ] = ptt[ ads[i].own ] = i;
}
}
for (int i = 0; i < q; ++i)
{
scanf("%d", &qst[i].key);
qst[i].id = i;
qst[i].ans = 0;
}
sort(qst, qst + q, cmp_key);
solve();
sort(qst, qst + q, cmp_id);
printf("Case #%d:\n", cas);
for (int i = 0; i < q; ++i)
{
printf("%I64d\n", qst[i].ans);
}
}
return ;
}
int main()
{
ace();
return 0;
}
hdu 4020 模拟
最新推荐文章于 2020-02-16 10:57:32 发布