QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#487054 | #5347. Trending Topic | PetroTarnavskyi# | AC ✓ | 26ms | 4584kb | C++20 | 1.6kb | 2024-07-22 15:38:38 | 2024-07-22 15:38:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
string str;
int day = 0;
vector<vector<string>> vec;
vector<VI> queries;
while (cin >> str)
{
if (str == "<text>")
{
vec.PB({});
queries.PB({});
continue;
}
if (str == "</text>")
{
day++;
continue;
}
if (str == "<top")
{
int n;
cin >> n;
queries.back().PB(n);
cin >> str;
assert(str == "/>");
continue;
}
if (SZ(str) >= 4)
vec[day].PB(str);
}
map<string, int> cnt;
set<pair<int, string>> se;
auto updCnt = [&](const string& s, int d)
{
se.erase({-cnt[s], s});
cnt[s] += d;
if (cnt[s] != 0)
se.insert({-cnt[s], s});
};
FOR(i, 0, SZ(vec))
{
for (const string& s : vec[i])
{
updCnt(s, 1);
}
if (i >= 7)
{
for (const string& s : vec[i - 7])
{
updCnt(s, -1);
}
}
for (int n : queries[i])
{
cout << "<top " << n << ">\n";
int j = 0, lastC = 0;
for (const auto& [c, s] : se)
{
if (j < n || c == lastC)
cout << s << " " << -c << "\n";
else
break;
if (j == n - 1)
lastC = c;
j++;
}
cout << "</top>\n";
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
input:
<text> imagine you are in the hiring process of a company whose main business is analyzing the information that appears in the web </text> <text> a simple test consists in writing a program for maintaining up to date a set of trending topics </text> <text> you will be hired depending on the effic...
output:
<top 5> analyzing 1 appears 1 business 1 company 1 consists 1 date 1 depending 1 efficiency 1 hired 1 hiring 1 imagine 1 information 1 main 1 maintaining 1 process 1 program 1 simple 1 solution 1 test 1 that 1 topics 1 trending 1 whose 1 will 1 writing 1 your 1 </top> <top 3> text 4 corresponding 3 ...
result:
ok 42 lines
Test #2:
score: 0
Accepted
time: 26ms
memory: 4584kb
input:
<text> toemfzsoh aauxoc xl rwsvqz aunwkfuev vsa jwmnnblo ke euvmkmyar wopmiajy apfbpkrt hqkf jrtakzq esrg gzbbhknq wpwba drhngdluaa zbd lvgb bqytogrue yaerdkuoj tyjo jcjsw vy asdkczmqtm wlcffkmpu hgusecll nom gxitylzzr vwvzaib my kyxuccl xpywatbgz jqgyylaeym yoj uexmzwom owslgfs art eorgb hedqw...
output:
<top 13> gxitylzzr 3 jcjsw 3 qfybmbiw 3 qpgmoeer 3 wqjtgrskg 3 bayftuyvor 2 bhjhtnr 2 bktkh 2 bsaguzp 2 btamz 2 bwkebm 2 bxjoupz 2 bxlyuqsfq 2 cmgpcn 2 epeaib 2 esrg 2 fjmwasuysa 2 fukvcvgzuw 2 grqygpol 2 gsoz 2 immrlyqp 2 iqfx 2 kctg 2 kdhdon 2 kirntu 2 lepl 2 lqkdald 2 lsxn 2 lvgb 2 lzei 2 mngi 2 ...
result:
ok 701 lines
Test #3:
score: 0
Accepted
time: 14ms
memory: 4460kb
input:
<text> fxzhahvb yspjq oqnbzecydo nvuwroet agtztuanyk elrylh rq rvrti npfvpsrm eilrhws lqqjrmlj olnj pxyrkfyylg wbbpxta lfzzhyrulf lo bzzdmocb xi taxbynywbm zfjzrmmmj obhgzje mxtcklvem qwp nkmiducibh ikq earer fwowyer scblvtfgse i efnvk bebnnea tjwxp tkgd vs qznfae sxxcatnm hsrjns bxclxmb xwve b...
output:
<top 4> fxzhahvb 3 dygz 2 gppknmt 2 gqckh 2 letnqzlu 2 mnahkt 2 tbfbtgjxtw 2 </top> <top 14> ewrnpsvqwe 4 fxzhahvb 4 uhckx 4 bngy 3 chztiippi 3 cngkxrou 3 crmorfu 3 eihnk 3 fvlbzfpn 3 gppknmt 3 gqckh 3 hxyoowdnv 3 kbusimta 3 kiivn 3 mnahkt 3 pvaig 3 qaujhhbjo 3 sallx 3 slrpc 3 tkgd 3 uxzorelyfy 3 vh...
result:
ok 861 lines
Test #4:
score: 0
Accepted
time: 19ms
memory: 4580kb
input:
<text> wltnikg zjdephhpa crdf mmd dpqhb vlfiqwuwhh lnvbrm qttdaxo ymdsqram ilablufmag bbvnb eyhkrnsmyt hanhzexvt rstuii tvavfezla clx ipoti htymixqfoh tx qiyjuz wyur qrzgts ckrqn sx hzqdfk ugjvun ygsrdrtch cklyuy msdixk xeswkxgsey caorb rlumerwpc vlcdta vxdzi cdzcasjl zehcnchl dncarqwz vtvgjth b...
output:
<top 19> aasolcigmb 2 aklwsaj 2 csdnzm 2 duzqqslvk 2 idomi 2 ncqvouwbzy 2 neseaf 2 nmwmilnrq 2 nqrrqrl 2 qiyjuz 2 qjsqwa 2 qrzgts 2 rndsswoh 2 rwxhwijjxu 2 slvbucx 2 snhxsdyf 2 srpredv 2 ttyjuhxzig 2 txnujbe 2 vepptqg 2 vkpzcsjlj 2 vtvgjth 2 vuatu 2 wboaiqocqi 2 wuoxk 2 xgwsspag 2 yqalm 2 zehcnchl 2...
result:
ok 797 lines
Test #5:
score: 0
Accepted
time: 15ms
memory: 4448kb
input:
<text> kfsxxmavu vvp rxrft tdpyzjacec m phes lvlhm wdwqgq dkpi zdce ifa xsmkkhpx cm hji ejdfx kpnpfde xns kkd hwpkzkonkp vlcwfznakp vcni bowacd mmogw saxmfrivw oslahncn qsvdgsdce hhwnun qxy kgddzrg iqyp jsszuvtit pdfnnefmp znr otxxv yi vvp jomh ude xvxpxvc ldxrftii hett ve jj llyxx yppqksy ait ...
output:
<top 12> bwkvdit 2 dkpi 2 hwpkzkonkp 2 iqyp 2 jsszuvtit 2 kivj 2 ldxrftii 2 lvlhm 2 mndfd 2 ovvhyiqdr 2 reyayp 2 rxrft 2 sanrniigdb 2 tdpyzjacec 2 tjeq 2 vcni 2 wdwqgq 2 wezhbkvt 2 wjxtrk 2 yhfhpek 2 </top> <top 17> uncef 4 lvlhm 3 reyayp 3 vcni 3 wjxtrk 3 bswj 2 bwkvdit 2 byjc 2 ckompyhk 2 coip 2 d...
result:
ok 477 lines