https://acm.bnu.edu.cn/v3/statments/jag2016.pdf
无脑大模拟啊。。。
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
const int N=100005;
typedef long long ll;
struct node
{
int x,ti,ran;
node(int a,int b,int c)
{
x=a,ti=b,ran=c;
}
bool operator<(const node &b)const
{
if (ran!=b.ran)
return ran<b.ran;
return ti<b.ti;
}
};
map<string,int>mp;
map<int,string>rev;
int rankk[N];
int tttt[N];
set<node>sb;
set<node>working;
set<node>::iterator it;
int vis[100000+50];
int main()
{
// freopen("out","w",stdout);
int n;
cin>>n;
int id=0;
char tmp[100];
string ss;
int v;
for (int i=1; i<=n; i++)
{
scanf("%s%d",tmp,&v);
ss=tmp;
if (mp[ss]==0)
mp[ss]=++id,rev[id]=ss;
rankk[ mp[ss]]=v,tttt[mp[ss]]=i;
sb.insert(node(mp[ss],i,v));
}
int tot=n;
int need=tot/5;
int cun=1;
it=sb.end();
it--;
for (; cun<=need;)
{
int id=it->x;
vis[id]=1,working.insert(node(id,tttt[id],rankk[id]));
it--;
cun++;
sb.erase(node(id,tttt[id],rankk[id]));
}
int m;
cin>>m;
char tmp2[100];
char stmp[100];
getchar();
for (int i=1; i<=m; i++)
{
gets(stmp);
int ret= sscanf(stmp,"%s%s%d",tmp2,tmp,&v);
ss=tmp;
if (mp[ss]==0)
mp[ss]=++id,rev[id]=ss;
if (ret==3)
{
rankk[ mp[ss]]=v,tttt[mp[ss]]=i+n;
node newpeo(mp[ss],i+n,v);
tot++;
int nd=(tot)/5;
if (nd==need)
{
if (!working.empty())
{
node minn=*working.begin();
if (minn<newpeo)
{
printf("%s is working hard now.\n",ss.c_str());
printf("%s is not working now.\n",rev[working.begin()->x].c_str());
vis[working.begin()->x]=0;
sb.insert(*working.begin());
working.erase(working.begin());
working.insert(newpeo);
vis[newpeo.x]=1;
continue;
}
sb.insert(newpeo);
printf("%s is not working now.\n",ss.c_str());
}
else
{
sb.insert(newpeo);
printf("%s is not working now.\n",ss.c_str());
}
continue;
}
need=nd;
sb.insert(newpeo);
it=sb.end();
it--;
vis[it->x]=1;
if (it->x!=newpeo.x) printf("%s is not working now.\n",ss.c_str());
printf("%s is working hard now.\n",rev[it->x].c_str());
working.insert(*it);
sb.erase(it);
}
else
{
tot--;
int id=mp[ss];
int nd=tot/5;
if (nd==need)
{
if (vis[id]==1)
{
// printf("%s is not working now.\n",rev[id].c_str());
vis[id]=0 ;
working.erase(node(id,tttt[id],rankk[id]) );
it=sb.end();
it--;
vis[it->x]=1;
printf("%s is working hard now.\n",rev[it->x].c_str());
working.insert(*it);
sb.erase(it);
}
else
sb.erase(node(id,tttt[id],rankk[id]) );
continue;
}
need=nd;
if (vis[id]==1)
{
//printf("%s is not working now.\n",rev[id].c_str());
vis[id]=0 ;
working.erase(node(id,tttt[id],rankk[id]) );
}
else
{
sb.erase(node(id,tttt[id],rankk[id]));
vis[id]=0;
node minn=*working.begin();
printf("%s is not working now.\n",rev[working.begin()->x].c_str());
vis[minn.x]=0;
sb.insert(minn);
working.erase(working.begin());
}
}
}
return 0;
}