Problem:
We don't wanna work!
ACM is an organization of programming contests. The purpose of ACM does not matter to you. The only important thing is that workstyles of ACM members are polarized: each member is either a workhorse or an idle fellow.
Each member of ACM has a motivation level. The members are ranked by their motivation levels: a member who has a higher motivation level is ranked higher. When several members have the same value of motivation levels, the member who joined ACM later have a higher rank. The top 20% highest ranked members work hard, and the other (80%) members never (!) work. Note that if 20% of the number of ACM members is not an integer, its fraction part is rounded down.
You, a manager of ACM, tried to know whether each member is a workhorse or an idle fellow to manage ACM. Finally, you completed to evaluate motivation levels of all the current members. However, your task is not accomplished yet because the members of ACM are dynamically changed from day to day due to incoming and outgoing of members. So, you want to record transitions of members from workhorses to idle fellows, and vice versa.
You are given a list of the current members of ACM and their motivation levels in chronological order of their incoming date to ACM. You are also given a list of incoming/outgoing of members in chronological order.
Your task is to write a program that computes changes of workstyles of ACM members.
Input
The first line of the input contains a single integer $N$ ($1 \leq N \leq 50,000$) that means the number of initial members of ACM. The ($i$ + 1)-th line of the input contains a string $s_i$ and an integer $a_i$ ($0 \leq a_i \leq 10^5$), separated by a single space. $s_i$ means the name of the $i$-th initial member and $a_i$ means the motivation level of the $i$-th initial member. Each character of $s_i$ is an English letter, and $1 \leq |s_i| \leq 20$. Note that those $N$ lines are ordered in chronological order of incoming dates to ACM of each member.
The ($N$ + 2)-th line of the input contains a single integer $M$ ($1 \leq M \leq 20,000$) that means the number of changes of ACM members. The ($N$ + 2 + $j$)-th line of the input contains information of the $j$-th incoming/outgoing member. When the $j$-th information represents an incoming of a member, the information is formatted as "$+ t_j b_j$", where $t_j$ is the name of the incoming member and $b_j$ ($0 \leq b_j \leq 10^5$) is his motivation level. On the other hand, when the $j$-th information represents an outgoing of a member, the information is formatted as "$- t_j$", where $t_j$ means the name of the outgoing member. Each character of $t_j$ is an English letter, and $1 \leq |t_j| \leq 20$. Note that uppercase letters and lowercase letters are distinguished. Note that those $M$ lines are ordered in chronological order of dates when each event happens.
No two incoming/outgoing events never happen at the same time. No two members have the same name, but members who left ACM once ma
...(truncated)

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define D(x)        cout << #x " = " << (x) << endl
#define un(x)       x.erase(unique(x.begin(), x.end()), x.end())
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pb          push_back
#define mp          make_pair
#define xx          first
#define yy          second
#define hp          (LL) 999983
#define MAX         100000
#define eps         1e-9
#define pi          acos(-1.00)
typedef long long int LL;
typedef pair<int,int> pii;

int global_id;
map<string, int> M;

struct node{
    char name[24];
    int ID, motiv;

    node(){}
    node(char *str, int mtv, int _id){
        strcpy(name, str);
        motiv = mtv;
        ID = _id;
    }
};

bool operator < (const node &u, const node &v){
    if(u.motiv == v.motiv) return u.ID > v.ID;
    return u.motiv > v.motiv;
}

bool operator == (const node &u, const node &v){
    return u.ID == v.ID;
}

bool operator <= (const node &u, const node &v){
    return (u < v || u == v);
}

struct Treap{
    node val;
    int prior, cnt;
    Treap *l, *r;

    Treap(node v){
        l = 0;
        r = 0;
        val = v;
        prior = (rand() << 15) + rand();
        cnt = 1;
    }
};

int sz(Treap *t) {return (t == NULL) ? 0:t->cnt;}
void upd_sz(Treap *t){
    if(t) t->cnt = 1 + sz(t->l) + sz(t->r);
}

void split(Treap *t, Treap *&l, Treap *&r, node key)
{
    if(!t) l = r = NULL;
    else if(t->val <= key) {split(t->r, t->r, r, key); l = t;}
    else {split(t->l, l, t->l, key); r = t;}
    upd_sz(t);
}

void merge(Treap *&t, Treap *l, Treap *r){
    if(!l || !r) t = l ? l : r;
    else if(l->prior > r->prior) {merge(l->r, l->r, r); t = l;}
    else {merge(r->l, l, r->l), t = r;}
    upd_sz(t);
}

void insert(Treap *&t, Treap *it){
    if(!t) t = it;
    else if(it->prior > t->prior) {split(t, it->l, it->r, it->val); t = it;}
    else if( (it->val <= t->val) == false) insert(t->r, it);
    else insert(t->l, it);
    upd_sz(t);
}

void erase(Treap *&t, node key){
    if(!t) return;
    else if(t->val == key) {Treap *temp = t; merge(t, t->l, t->r); delete(temp);}
    else if( (key <= t->val) == false) erase(t->r, key);
    else erase(t->l, key);
    upd_sz(t);
}

node find_kth(Treap *cur, int k)
{
    if(sz(cur->l) < k)
    {
        k -= sz(cur->l);
        if(k == 1) return cur->val;
        return find_kth(cur->r, k - 1);
    }
    return find_kth(cur->l, k);
}

int canWork(int n) {return n / 5;}


int n;
Treap *working, *idle;
char str[33], sgn[3];
string S;
set<int> working_id, idle_id;
int motivation[5000000];
char pending_print[1111];

void welcomeNewMember(bool printFlag)
{
    n++;

    int mtv;
    Treap *current;
    node lastOne;


    global_id++;
    scanf("%s %d", str, &mtv);
    motivation[global_id] = mtv;

    S = string(str);
    M[S] = global_id;

    current = new Treap(node(str, mtv, global_id));
    pending_print[0] = 0;

    if(canWork(n) != canWork(n - 1))
    {
        node idleFront = find_kth(idle, 1);
        if(idleFront.motiv > mtv){
            erase(idle, idleFront);
            idle_id.erase(idleFront.ID);

            insert(working, new Treap(idleFront));
            working_id.insert(idleFront.ID);

            strcat(pending_print, idleFront.name);
            strcat(pending_print, " is working hard now.");
        }
    }

    if(sz(working) < canWork(n))
    {
        insert(working, current);
        if(printFlag) printf("%s is working hard now.\n", str);
        working_id.insert(global_id);
    }
    else{
        if(sz(working)){
            lastOne = find_kth(working, sz(working));
            if(lastOne.motiv <= mtv){
                erase(working, lastOne);
                insert(working, current);
                insert(idle, new Treap(lastOne));

                working_id.insert(global_id);
                working_id.erase(M[lastOne.name]);
                idle_id.insert(M[lastOne.name]);

                if(printFlag) printf("%s is working hard now.\n", str);
                if(printFlag) printf("%s is not working now.\n", lastOne.name);
            }
            else
            {
                idle_id.insert(global_id);
                insert(idle, current);
                if(printFlag) printf("%s is not working now.\n", str);
            }
        }
        else
        {
            idle_id.insert(global_id);
            insert(idle, current);
            if(printFlag) printf("%s is not working now.\n", str);
        }
    }

    if(pending_print[0] && printFlag) puts(pending_print);
}

void removeSomeone(){
    n--;

    Treap *current;
    node lastOne, firstOne;

    scanf("%s", str);
    int getID = M[str];


    if(idle_id.find(getID) != idle_id.end()){
        idle_id.erase(getID);
        erase(idle, node(str, motivation[getID], getID));
    }
    else{
        working_id.erase(getID);
        erase(working, node(str, motivation[getID], getID));
    }

    while(sz(working) > canWork(n)){
        lastOne = find_kth(working, sz(working));

        working_id.erase(lastOne.ID);
        erase(working, lastOne);


        idle_id.insert(lastOne.ID);
        insert(idle, new Treap(lastOne));
        printf("%s is not working now.\n", lastOne.name);
    }

    while(sz(working) < canWork(n)){
        firstOne = find_kth(idle, 1);

        idle_id.erase(firstOne.ID);
        erase(idle, firstOne);


        working_id.insert(firstOne.ID);
        insert(working, new Treap(firstOne));
        printf("%s is working hard now.\n", firstOne.name);
    }
}

int main()
{
    //freopen("in.txt", "r", stdin);
    srand(time(0));
    int i, j, k, mtv, q, N;
    Treap *current;
    node lastOne;

    sf(N);
    for(i = 1; i <= N; i++)
        welcomeNewMember(false);

    sf(q);
    while(q--){
        scanf("%s", sgn);

        if(sgn[0] == '+') welcomeNewMember(true);
        else removeSomeone();
    }

    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 13628
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
struct node
{
	string name;
	int id,val;
	node(){}
	node(string _s,int _id,int _val)
	{
		name=_s,id=_id,val=_val;
	}
	bool operator<(const node &A)const
	{
		if(val!=A.val)return val>A.val;
		return id>A.id;
	}
};
set<node>se;
set<node>::iterator it;
node la=node("",inf,inf);
map<string,node>mp;
void init()
{
	int t=se.size()/5;
	it=se.begin();
	for(int i=0;i<t;i++)
	{
		la=*(it);
		it++;
	}
}
void add(node no)
{
	se.insert(no);
	mp[no.name]=no;
	int x=se.size()/5,y=se.size()%5;
	if(x==0)
	{
		cout<<no.name<<" is not working now.\n";
	}
	else if(x==1&&y==0)
	{
		it=se.begin();
		la=*(se.begin());
		if(la<no)
		{
			cout<<no.name<<" is not working now.\n";
			cout<<la.name<<" is working hard now.\n";
		}
		else
		{
			cout<<no.name<<" is working hard now.\n";
		}
	}
	else if(y==0)
	{
		if(la<no)
		{
			it=se.find(la);
			it++;
			la=*(it);
			if(la.name==no.name)
			{
				cout<<no.name<<" is working hard now.\n";
			}
			else
			{
				cout<<no.name<<" is not working now.\n";
				cout<<la.name<<" is working hard now.\n";
			}
		}
		else
		{
			cout<<no.name<<" is working hard now.\n";
		}
	}
	else
	{
		if(la<no)
		{
			cout<<no.name<<" is not working now.\n";
		}
		else
		{
			cout<<no.name<<" is working hard now.\n";
			cout<<la.name<<" is not working now.\n";
			it=se.find(la);
			it--;
			la=*(it);
		}
	}
}
void sub(node no)
{
	int x=(se.size()-1)/5,y=(se.size()-1)%5;
	if(y==4)
	{
		if(la<no)
		{
			cout<<la.name<<" is not working now.\n";
			it=se.find(la);
			if(it!=se.begin())
			{
				it--;la=*(it);
			}
			else
			{
				la=node("",inf,inf);
			}
		}
	}
	else
	{
		if(!(la<no))
		{
			it=se.find(la);
			it++;
			la=*(it);
			cout<<la.name<<" is working hard now.\n";
		}
	}
	se.erase(no);
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		char s[25];int k;
		scanf("%s %d",s,&k);
		se.insert(node(s,i,k));
		mp[s]=node(s,i,k);
	}
	init();
	int m;
	scanf("%d",&m);
	for(int i=n;i<n+m;i++)
	{
		char s[25];
		scanf("%s",s);
		if(s[0]=='+')
		{
			int k;
			scanf("%s %d",s,&k);
			add(node(s,i,k));
		}
		else
		{
			scanf("%s",s);
			sub(mp[s]);
		}
	}
	return 0;
}
accuracy: 0.2878787878787879
time_ms: 50
memory_kb: 13716
final_rank: 17

code_snippet: #include <map>
#include <queue>
#include <string>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 70007;

struct A{ int val, id;  char nm[25];  A(){} };;
struct B{
        int val, id;  char nm[25];
        bool operator<(const B& b)const{
                if (val==b.val) return id<b.id;
                return val<b.val;
        }
};

struct cmp{
        bool operator()(A a, A b){
                if (a.val==b.val) return a.id<b.id;
                return a.val<b.val;
        }
};

struct ccmp{
        bool operator()(A a, A b){
                if (a.val==b.val) return a.id>b.id;
                return a.val>b.val;
        }
};

int n, m, id, a, num, lft, rht, sl, sr, fl;
char ss[25], ch[5];
B ini[50005];
map<string, int> mbig, msma;

int main(){
        int i, j, k;
        while (~scanf("%d", &n)){
                num = n;  id = n-1;
                lft = num/5;  rht = num-lft;
                for (i=0; i<n; ++i){
                        scanf("%s%d", ini[i].nm, &ini[i].val);
                        ini[i].id = i;
                }
                sort(ini, ini+n);
                priority_queue<A, vector<A>, cmp> big;
                priority_queue<A, vector<A>, ccmp> sma;

                A tmp, nw;
                mbig.clear();  msma.clear();
                for (i=0; i<rht; ++i){
                        tmp.id = ini[i].id;
                        tmp.val = ini[i].val;
                        strcpy(tmp.nm, ini[i].nm);
                        mbig[ini[i].nm] = tmp.id;
                        big.push(tmp);
                }
                for (i=rht; i<n; ++i){
                        tmp.id = ini[i].id;
                        tmp.val = ini[i].val;
                        strcpy(tmp.nm, ini[i].nm);
                        msma[ini[i].nm] = tmp.id;
                        sma.push(tmp);
                }

                scanf("%d", &m);
                for (k=0; k<m; k++){
                        scanf("%s", ch);
                        if (ch[0]=='-'){
                                scanf("%s", ss);  num--;
                                sl = num/5;  sr = num-sl;
                                if (mbig.find(ss)!=mbig.end()){
                                        mbig.erase(ss);  rht--;
                                        if(rht<sr){
                                                while (!sma.empty()){
                                                        tmp = sma.top();  sma.pop();
                                                        if (msma.find(tmp.nm)!=msma.end()){
                                                                msma.erase(tmp.nm);
                                                                mbig[tmp.nm] = tmp.id;
                                                                big.push(tmp); rht++; lft--;
                                                                printf("%s is not working now.\n", tmp.nm);
                                                                break;
                                                        }
                                                }
                                        }
                                }else{
                                        msma.erase(ss);  lft--;
                                        if (lft<sl){
                                                while (!big.empty()){
                                                        tmp = big.top(); big.pop();
                                                        if (mbig.find(tmp.nm)!=mbig.end()){
                                                                mbig.erase(tmp.nm);
                                                                msma[tmp.nm] = tmp.id;
                                                                printf("%s is working hard now.\n", tmp.nm);
                                                                sma.push(tmp); lft++; rht--;
                                                                break;
                                                        }
                                                }
                                        }
                                }
                        }else{
                                scanf("%s%d", ss, &a);  num++; id++;
                                sl = num/5;  sr = num-sl;
                                strcpy(nw.nm, ss);
                                nw.val = a; nw.id = id;
                                if (lft<sl){
                                        while (!big.empty()){
                                                tmp = big.top(); big.pop();
                                                if (mbig.find(tmp.nm)!=mbig.end()){
                                                        mbig.erase(tmp.nm);
                                                        break;
                                                }
                                        }
                                        if (nw.val>=tmp.val){
                                                msma[nw.nm] = nw.id;
                                                mbig[tmp.nm] = tmp.id;
                                                big.push(tmp);
                                                sma.push(nw);
                                                printf("%s is working hard now.\n", nw.nm);
                                        }else{
                                                mbig[nw.nm] = nw.id;
                                                msma[tmp.nm] = tmp.id;
                                                big.push(nw);
                                                sma.push(tmp);
                                                printf("%s is not working now.\n", nw.nm);
                                                printf("%s is working hard now.\n", tmp.nm);
                                        }
                                        lft++;
                                }else if (rht<sr){
                                        if (sma.empty()){
                                                mbig[nw.nm] = nw.id;
                                                big.push(nw);
                                                printf("%s is not working now.\n", nw.nm);
                                        }else{
                                                while (!sma.empty()){
                                                        tmp = sma.top(); sma.pop();
                                                        if (msma.find(tmp.nm)!=msma.end()){
                                                                msma.erase(tmp.nm);
                                                                break;
                                                        }
                                                }
                                                if (tmp.val<=nw.val){
                                                        mbig[tmp.nm] = tmp.id;
                                                        msma[nw.nm] = nw.id;
                                                        sma.push(nw);
                                                        big.push(tmp);
                                                        printf("%s is working hard now.\n", nw.nm);
                                                        printf("%s is not working now.\n", tmp.nm);
                                                }else{
                                                        mbig[nw.nm] = nw.id;
                                                        msma[tmp.nm] = tmp.id;
                                                        sma.push(tmp);
                                                        big.push(nw);
                                                        printf("%s is not working now.\n", nw.nm);
                                                }
                                        }
                                        rht++;
                                }
                        }
                }
        }
        return 0;
}
accuracy: 0.19696969696969696
time_ms: 40
memory_kb: 10656
final_rank: 18

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <map>
#include <set>
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
std::map<std::string, int> map;
int get_id(std::string S) {
    auto it = map.find(S);
    if (it != map.end()) {
        return it->second;
    }
    else {
        int res = map.size();
        return map[S] = res;
    }
}
int SIZE = 0;
std::pair<int, int> id[50010+20010]; // power, time
using item = std::tuple<int, int, std::string>; // power, time, name
std::multiset<item> small, big;

void working(const std::string& S) {
    std::cout << S << " is working hard now.\n";
}
void idle(const std::string& S) {
    std::cout << S << " is not working now.\n";
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int N;
    std::cin >> N;
    for (int i = 0 ; i < N ; i++) {
        std::string S;
        int a;
        std::cin >> S >> a;
        int j = get_id(S);
        id[j] = {a, i};
        SIZE++;
        big.insert(item{a, i, S});
    }
    while ((int)big.size() > SIZE / 5) {
        auto it = big.begin();
        small.insert(*it);
        big.erase(it);
    }
    int M;
    std::cin >> M;
    for (int i = 0 ; i < M ; i++) {
        char c;
        std::string S;
        std::cin >> c >> S;
        if (c == '+') {
            int p;
            std::cin >> p;
            int j = get_id(S);
            id[j] = {p, N+i};
            SIZE++;
            item cur{p, N+i, S};
            if ((int)big.size() < SIZE/5 and (small.empty() or *small.rbegin() < cur)) {
                working(S);
                big.insert(cur);
            }
            else if ((int)big.size() == SIZE/5 and big.size() and *big.begin() < cur) {
                working(S);
                big.insert(cur);
            }
            else {
                idle(S);
                small.insert(cur);
            }
        }
        else if (c == '-') {
            auto [p, t] = id[get_id(S)];
            item cur{p, t, S};
            {
                auto it = small.find(cur);
                if (it != small.end()) small.erase(it);
                else {
                    it = big.find(cur);
                    assert(it != big.end());
                    big.erase(it);
                }
            }
            SIZE--;
        }
        else assert(false);
        if ((int)big.size() < SIZE / 5 and small.size()) {
            auto it = std::prev(small.end());
            working(std::get<2>(*it));
            big.insert(*it);
            small.erase(it);
        }
        else if ((int)big.size() > SIZE / 5) {
            auto it = big.begin();
            idle(std::get<2>(*it));
            small.insert(*it);
            big.erase(it);
        }
    }
}
accuracy: 1
time_ms: 50
memory_kb: 12288
final_rank: 6

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <map>
#include <set>
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
std::map<std::string, int> map;
int get_id(std::string S) {
    auto it = map.find(S);
    if (it != map.end()) {
        return it->second;
    }
    else {
        int res = map.size();
        return map[S] = res;
    }
}
int SIZE = 0;
std::pair<int, int> id[50010+20010]; // power, time
using item = std::tuple<int, int, std::string>; // power, time, name
std::multiset<item> small, big;

void working(const std::string& S) {
    std::cout << S << " is working hard now.\n";
}
void idle(const std::string& S) {
    std::cout << S << " is not working now.\n";
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int N;
    std::cin >> N;
    for (int i = 0 ; i < N ; i++) {
        std::string S;
        int a;
        std::cin >> S >> a;
        int j = get_id(S);
        id[j] = {a, i};
        SIZE++;
        big.insert(item{a, i, S});
    }
    while ((int)big.size() > SIZE / 5) {
        auto it = big.begin();
        small.insert(*it);
        big.erase(it);
    }
    int M;
    std::cin >> M;
    for (int i = 0 ; i < M ; i++) {
        char c;
        std::string S;
        std::cin >> c >> S;
        if (c == '+') {
            int p;
            std::cin >> p;
            int j = get_id(S);
            id[j] = {p, N+i};
            SIZE++;
            item cur{p, N+i, S};
            if ((int)big.size() < SIZE/5 and (small.empty() or *small.rbegin() < cur)) {
                working(S);
                big.insert(cur);
            }
            else if ((int)big.size() == SIZE/5 and big.size() and *big.begin() < cur) {
                working(S);
                big.insert(cur);
            }
            else {
                idle(S);
                small.insert(cur);
            }
        }
        else if (c == '-') {
            auto [p, t] = id[get_id(S)];
            item cur{p, t, S};
            {
                auto it = small.find(cur);
                if (it != small.end()) small.erase(it);
                else {
                    it = big.find(cur);
                    assert(it != big.end());
                    big.erase(it);
                }
            }
            SIZE--;
        }
        else assert(false);
        if ((int)big.size() < SIZE / 5 and small.size()) {
            auto it = std::prev(small.end());
            working(std::get<2>(*it));
            big.insert(*it);
            small.erase(it);
        }
        else if ((int)big.size() > SIZE / 5) {
            auto it = big.begin();
            idle(std::get<2>(*it));
            small.insert(*it);
            big.erase(it);
        }
    }
}
accuracy: 1
time_ms: 50
memory_kb: 12288
final_rank: 6

code_snippet: // AOJ #2782 We don't wanna work!
// 2025.3.2

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

struct M {
    int m, j;
    string n;
};

struct cmp {
    bool operator()(const M &a, const M &b) const {
        if(a.m != b.m) return a.m > b.m;
        return a.j > b.j;
    }
};

typedef tree<M, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update> ost;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int N; cin >> N;
    ost T;
    unordered_map<string, M> R;
    unordered_map<string, bool> S;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        string s; int a; cin >> s >> a;
        cnt++;
        M x{a, cnt, s};
        T.insert(x);
        R[s] = x;
    }
    int t = (int)T.size() * 20 / 100;
    for(auto it = T.begin(); it != T.end(); it++){
        int pos = T.order_of_key(*it);
        S[it->n] = (pos < t);
    }
    int Mcnt; cin >> Mcnt;
    for(int i = 0; i < Mcnt; i++){
        char op; cin >> op;
        int oldSize = T.size();
        int oldt = (oldSize * 20) / 100;
        if(op == '+'){
            string s; int a; cin >> s >> a;
            cnt++;
            M x{a, cnt, s};
            T.insert(x);
            R[s] = x;
            int newSize = T.size();
            int nt = (newSize * 20) / 100;
            int pos = T.order_of_key(x);
            bool w = (pos < nt);
            S[s] = w;
            cout << s << (w ? " is working hard now." : " is not working now.") << endl;
            if(nt > 0){
                M cand = *T.find_by_order(nt - 1);
                if(!S[cand.n]){
                    S[cand.n] = true;
                    cout << cand.n << " is working hard now." << endl;
                }
            }
            if(nt < newSize){
                M cand = *T.find_by_order(nt);
                if(S[cand.n]){
                    S[cand.n] = false;
                    cout << cand.n << " is not working now." << endl;
                }
            }
        } else {
            string s; cin >> s;
            M x = R[s];
            T.erase(x);
            R.erase(s);
            S.erase(s);
            int newSize = T.size();
            int nt = (newSize * 20) / 100;
            if(newSize > 0){
                if(nt > 0){
                    M cand = *T.find_by_order(nt - 1);
                    if(!S[cand.n]){
                        S[cand.n] = true;
                        cout << cand.n << " is working hard now." << endl;
                    }
                }
                if(nt < newSize){
                    M cand = *T.find_by_order(nt);
                    if(S[cand.n]){
                        S[cand.n] = false;
                        cout << cand.n << " is not working now." << endl;
                    }
                }
            }
        }
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 16504
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

struct Human {
    string name;
    int power;
    int joined;
};

bool operator<(const Human &a1, const Human &a2) {
    if (a1.power > a2.power) return true;
    if (a1.power < a2.power) return false;
    if (a1.joined > a2.joined) return true;
    return false;
}

int main() {
    // Input (Former)
    int N; cin >> N;
    vector<Human> P(N);
    for (int i = 0; i < N; i++) cin >> P[i].name >> P[i].power;
    for (int i = 0; i < N; i++) P[i].joined = i;
    int Q; cin >> Q;

    // Input (Latter)
    vector<pair<char, Human>> Change(Q);
    map<string, pair<int, int>> PowerList;
    for (int i = 0; i < N; i++) PowerList[P[i].name] = make_pair(P[i].power, P[i].joined);
    for (int i = 0; i < Q; i++) {
        cin >> Change[i].first;
        if (Change[i].first == '+') {
            cin >> Change[i].second.name >> Change[i].second.power;
            Change[i].second.joined = N + i;
            PowerList[Change[i].second.name] = make_pair(Change[i].second.power, Change[i].second.joined);
        }
        if (Change[i].first == '-') {
            cin >> Change[i].second.name;
            Change[i].second.power = PowerList[Change[i].second.name].first;
            Change[i].second.joined = PowerList[Change[i].second.name].second;
            PowerList[Change[i].second.name] = make_pair(0, 0);
        }
    }

    // Step 2. Query Init
    set<Human> Strong;
    set<Human> Weak;
    for (int i = 0; i < N; i++) Strong.insert(P[i]);
    while (Strong.size() * 4 > Weak.size()) {
        auto itr = Strong.end(); itr--;
        Weak.insert(*itr);
        Strong.erase(*itr);
    }

    // Step 3. Update
    for (int i = 0; i < Q; i++) {
        // Addition
        if (Change[i].first == '+') {
            int sz = Strong.size() + Weak.size();
            string verdict = "lazy";
            if (sz % 5 == 4) {
                auto itr = Weak.begin();
                if (Change[i].second < (*itr)) verdict = "hard";
            }
            else if (sz >= 5) {
                auto itr = Strong.end(); itr--;
                if (Change[i].second < (*itr)) verdict = "hard";
            }
            if (verdict == "lazy") {
                cout << Change[i].second.name << " is not working now." << endl;
                Weak.insert(Change[i].second);
            }
            else {
                cout << Change[i].second.name << " is working hard now." << endl;
                Strong.insert(Change[i].second);
            }
        }

        // Deletion
        if (Change[i].first == '-') {
            Strong.erase(Change[i].second);
            Weak.erase(Change[i].second);
        }

        // Update
        while (Strong.size() * 4 > Weak.size()) {
            auto itr = Strong.end(); itr--;
            cout << (*itr).name << " is not working now." << endl;
            Weak.insert(*itr);
            Strong.erase(*itr);
        }
        while (Strong.size() * 4 + 4 < Weak.size()) {
            auto itr = Weak.begin();
            cout << (*itr).name << " is working hard now." << endl;
            Strong.insert(*itr);
            Weak.erase(*itr);
        }
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 14464
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

map<string,int> mps;
vector<string> SV;
vector<int> X;
int scur = 0;
int getstring() {
    string s;
    cin >> s;
    if (mps.count(s)) return mps[s];
    SV.push_back(s);
    X.push_back(0);
    mps[s] = scur;
    scur++;
    return scur-1;
}

int main() {
    int N;
    cin >> N;
    set<pair<int,int>> Left, Right;
    int LC = N, RC = 0;
    rep(i,0,N) {
        int A = getstring();
        int B;
        cin >> B;
        Left.insert({B,A});
        X[A] = B;
    }
    while(RC < N/5) {
        pair<int,int> P = *Left.rbegin();
        Left.erase(P);
        Right.insert(P);
        LC--, RC++;
    }
    auto Balancing = [&]() -> void {
        int RS = (LC+RC)/5;
        while(RC < RS) {
            pair<int,int> P = *Left.rbegin();
            Left.erase(P);
            Right.insert(P);
            LC--, RC++;
            cout << SV[P.second] << " is working hard now." << endl;
        }
        while(RC > RS) {
            pair<int,int> P = *Right.begin();
            Right.erase(P);
            Left.insert(P);
            LC++, RC--;
            cout << SV[P.second] << " is not working now." << endl;
        }
    };
    int Q;
    cin >> Q;
    while(Q--) {
        char C;
        cin >> C;
        int A = getstring();
        if (C == '+') {
            int B;
            cin >> B;
            X[A] = B;
            pair<int,int> P = {B,A};
            X.push_back(B);
            int RS = (LC+RC+1)/5;
            pair<int,int> L1, R1;
            if (Left.empty()) L1 = {-inf,-inf};
            else L1 = *Left.rbegin();
            if (Right.empty()) R1 = {inf,inf};
            else R1 = *Right.begin();
            if (P < L1) {
                Left.insert(P);
                LC++;
                cout << SV[P.second] << " is not working now." << endl;
            }
            else if (R1 < P) {
                Right.insert(P);
                RC++;
                cout << SV[P.second] << " is working hard now." << endl;
            }
            else {
                if (RS == RC) {
                    Left.insert(P);
                    LC++;
                    cout << SV[P.second] << " is not working now." << endl;
                }
                else {
                    Right.insert(P);
                    RC++;
                    cout << SV[P.second] << " is working hard now." << endl;
                }
            }
            Balancing();
        }
        else {
            pair<int,int> P = {X[A],A};
            if (Left.count(P)) Left.erase(P), LC--;
            if (Right.count(P)) Right.erase(P), RC--;
            Balancing();
            mps.erase(SV[A]);
        }
    }
}
accuracy: 1
time_ms: 80
memory_kb: 11656
final_rank: 8

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

map<string,int> mps;
vector<string> SV;
vector<int> X;
int scur = 0;
int getstring() {
    string s;
    cin >> s;
    if (mps.count(s)) return mps[s];
    SV.push_back(s);
    X.push_back(0);
    mps[s] = scur;
    scur++;
    return scur-1;
}

int main() {
    int N;
    cin >> N;
    set<pair<int,int>> Left, Right;
    int LC = N, RC = 0;
    rep(i,0,N) {
        int A = getstring();
        int B;
        cin >> B;
        Left.insert({B,A});
        X[A] = B;
    }
    while(RC < N/5) {
        pair<int,int> P = *Left.rbegin();
        Left.erase(P);
        Right.insert(P);
        LC--, RC++;
    }
    auto Balancing = [&]() -> void {
        int RS = (LC+RC)/5;
        while(RC < RS) {
            pair<int,int> P = *Left.rbegin();
            Left.erase(P);
            Right.insert(P);
            LC--, RC++;
            cout << SV[P.second] << " is working hard now." << endl;
        }
        while(RC > RS) {
            pair<int,int> P = *Right.begin();
            Right.erase(P);
            Left.insert(P);
            LC++, RC--;
            cout << SV[P.second] << " is not working now." << endl;
        }
    };
    int Q;
    cin >> Q;
    while(Q--) {
        char C;
        cin >> C;
        int A = getstring();
        if (C == '+') {
            int B;
            cin >> B;
            X[A] = B;
            pair<int,int> P = {B,A};
            X.push_back(B);
            int RS = (LC+RC+1)/5;
            pair<int,int> L1, R1;
            if (Left.empty()) L1 = {-inf,-inf};
            else L1 = *Left.rbegin();
            if (Right.empty()) R1 = {inf,inf};
            else R1 = *Right.begin();
            if (P < L1) {
                Left.insert(P);
                LC++;
                cout << SV[P.second] << " is not working now." << endl;
            }
            else if (R1 < P) {
                Right.insert(P);
                RC++;
                cout << SV[P.second] << " is working hard now." << endl;
            }
            else {
                if (RS == RC) {
                    Left.insert(P);
                    LC++;
                    cout << SV[P.second] << " is not working now." << endl;
                }
                else {
                    Right.insert(P);
                    RC++;
                    cout << SV[P.second] << " is working hard now." << endl;
                }
            }
            Balancing();
        }
        else {
            pair<int,int> P = {X[A],A};
            if (Left.count(P)) Left.erase(P), LC--;
            if (Right.count(P)) Right.erase(P), RC--;
            Balancing();
        }
    }
}
accuracy: 0.15151515151515152
time_ms: 70
memory_kb: 12172
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> ppi;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
int main(){
    ll N;cin>>N;
    set<pi>workhorse,idle;
    map<ll,string>name;
    map<string,pi>st;
    REP(i,N){
        string t;cin>>t;
        name[i]=t;
        ll m;cin>>m;
        st[t]=pi(m,i);
        idle.insert(pi(m,i));
    }
    while(workhorse.size()<N/5){
        workhorse.insert(*prev(idle.end()));
        idle.erase(prev(idle.end()));
    }
    ll Q,now=N;cin>>Q;
    REP(i,Q){
        char c;string t;cin>>c>>t;
        if(c=='+'){
            ll m;cin>>m;
            name[now]=t;
            N++;
            pi p=pi(m,now++);
            st[t]=p;
            if(workhorse.size()&&*workhorse.begin()<p){
                workhorse.insert(p);
                cout<<t<<" is working hard now."<<endl;
            }
            else if(idle.size()&&*prev(idle.end())>p){
                idle.insert(p);
                cout<<t<<" is not working now."<<endl;
            }
            else if(N%5==0){
                workhorse.insert(p);
                cout<<t<<" is working hard now."<<endl;
            }
            else{
                idle.insert(p);
                cout<<t<<" is not working now."<<endl;
            }
        }
        else{
            N--;
            auto p=st[t];
            workhorse.erase(p);
            idle.erase(p);
        }
        while(workhorse.size()!=N/5){
            if(workhorse.size()>N/5){
                auto p=*workhorse.begin();
                cout<<name[p.second]<<" is not working now."<<endl;
                idle.insert(p);
                workhorse.erase(p);
            }
            else{
                auto p=*prev(idle.end());
                cout<<name[p.second]<<" is working hard now."<<endl;
                workhorse.insert(p);
                idle.erase(p);
            }
        }
    }
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 16608
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef pair<ll,ll> pi;
typedef pair<ll,pi> ppi;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,l,r) for(ll i=r-1;i>=l;i--)
#define RREP(i,n) RFOR(i,0,n)
#define sz(A) (ll)(A.size())
#define ALL(A) A.begin(),A.end()
#define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin())
#define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin())
#define COU(A,x) (UB(A,x)-LB(A,x))
#define F first
#define S second
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.F<<" "<<p.S;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.F>>p.S;return is;}
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){REP(i,sz(v))os<<v[i]<<(i+1!=sz(v)?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
const ll mod=998244353;
int main(){
    while(1){
        ll N;cin>>N;
        vector<string>S(N);
        vi A(N);
        REP(i,N)cin>>S[i]>>A[i];
        set<pair<pi,string>>Q1;
        set<pair<pi,string>>Q2;
        map<string,pi>memo;
        REP(i,N)memo[S[i]]=pi(A[i],i-N);
        REP(i,N)Q1.insert(make_pair(pi(A[i],i-N),S[i]));
        while(sz(Q1)>N/5){
            Q2.insert(*Q1.begin());Q1.erase(Q1.begin());
        }
        //for(auto i:Q1)cout<<i<<" ";cout<<endl;
        //for(auto i:Q2)cout<<i<<" ";cout<<endl;
        ll M;cin>>M;
        REP(_,M){
            char c;cin>>c;
            if(c=='+'){
                string s;cin>>s;
                ll a;cin>>a;
                memo[s]=pi(a,_);
                N++;
                if(N/5==0){
                    cout<<s<<" is not working now."<<endl;
                    Q2.insert(make_pair(memo[s],s));
                }
                else if(!sz(Q1)){
                    auto p=*prev(Q2.end());
                    if(p.F<memo[s]){
                        cout<<s<<" is working hard now."<<endl;
                        Q1.insert(make_pair(memo[s],s));
                    }
                    else{
                        cout<<s<<" is not working now."<<endl;
                        Q2.insert(make_pair(memo[s],s));
                        cout<<p.S<<" is working hard now."<<endl;
                        Q2.erase(p);
                        Q1.insert(p);
                    }
                }
                else if(memo[s]>(*Q1.begin()).F){
                    cout<<s<<" is working hard now."<<endl;
                    Q1.insert(make_pair(memo[s],s));
                    if(sz(Q1)>N/5){
                        auto p=*Q1.begin();
                        cout<<p.S<<" is not working now."<<endl;
                        Q1.erase(p);
                        Q2.insert(p);
                    }
                }
                else if(memo[s]<(*prev(Q2.end())).F){
                    cout<<s<<" is not working now."<<endl;
                    Q2.insert(make_pair(memo[s],s));
                    if(sz(Q1)<N/5){
                        auto p=*prev(Q2.end());
                        cout<<p.S<<" is working hard now."<<endl;
                        Q2.erase(p);
                        Q1.insert(p);
                    }
                }
                else if(sz(Q1)==N/5){
                    cout<<s<<" is not working now."<<endl;
                    Q2.insert(make_pair(memo[s],s));
                }
                else{
                    cout<<s<<" is working hard now."<<endl;
                    Q1.insert(make_pair(memo[s],s));
                }
            }
            else{
                string s;cin>>s;
                if(Q1.count(make_pair(memo[s],s)))Q1.erase(make_pair(memo[s],s));
                else Q2.erase(make_pair(memo[s],s));
                N--;
                if(sz(Q1)>N/5){
                    cout<<(*Q1.begin()).S<<" is not working now."<<endl;
                    Q2.insert(*Q1.begin());
                    Q1.erase(Q1.begin());
                }
                if(sz(Q1)<N/5&&N){
                    cout<<(*prev(Q2.end())).S<<" is working hard now."<<endl;
                    Q1.insert(*prev(Q2.end()));
                    Q2.erase(prev(Q2.end()));
                }
            }
        }
        break;
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 14976
final_rank: 11

code_snippet: /*  -*- coding: utf-8 -*-
 *
 * 2782.cc: We don't wanna work!
 */

#include<cstdio>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 50000 + 20000;

/* typedef */

typedef pair<int,int> pii;
typedef map<string,int> msi;
typedef set<pii> spii;

/* global variables */

string ss[MAX_N];
int as[MAX_N];
pii ps[MAX_N];

/* subroutines */

int normalize(spii &q0, spii &q1) {
  int l0 = q0.size(), l1 = q1.size(), l = l0 + l1;
  int r = -1;

  if (l1 > l / 5) { // q1->q0
    auto sit = q1.begin();
    r = sit->second;
    q0.insert(*sit);
    q1.erase(sit);
  }
  else if (l0 > l - l / 5) { // q0->q1
    auto sit = q0.end(); sit--;
    r = sit->second;
    q1.insert(*sit);
    q0.erase(sit);
  }

  return r;
}

inline bool working(spii &q1, int i) {
  return q1.find(pii(as[i], i)) != q1.end();
}

/* main */

int main() {
  int n;
  scanf("%d", &n);

  msi smap;
  for (int i = 0; i < n; i++) {
    char s[32];
    scanf("%s%d", s, as + i);
    ss[i] = string(s);
    smap[ss[i]] = i;
    ps[i] = pii(as[i], i);
  }
  sort(ps, ps + n);

  int l1 = n / 5, l0 = n - l1;
  spii q0(ps, ps + l0), q1(ps + l0, ps + n);
  
  int m;
  scanf("%d", &m);

  while (m--) {
    char op[4], s[32];
    scanf("%s%s", op, s);

    if (op[0] == '+') {
      scanf("%d", as + n);
      ss[n] = string(s);
      smap[ss[n]] = n;
      pii pi(as[n], n);

      if (! q1.empty() && *(q1.begin()) < pi) q1.insert(pi);
      else q0.insert(pi);
      int r = normalize(q0, q1);

      if (working(q1, n))
	printf("%s is working hard now.\n", ss[n].c_str());
      else
	printf("%s is not working now.\n", ss[n].c_str());

      if (r >= 0 && r != n) {
	if (working(q1, r))
	  printf("%s is working hard now.\n", ss[r].c_str());
	else
	  printf("%s is not working now.\n", ss[r].c_str());
      }

      n++;
    }
    else { // op[0] == '-'
      int k = smap[string(s)];

      if (working(q1, k)) {
	q1.erase(pii(as[k], k));
	//printf("%s is not working now.\n", ss[k].c_str());
      }
      else {
	q0.erase(pii(as[k], k));
      }

      int r = normalize(q0, q1);
      if (r >= 0) {
	if (working(q1, r))
	  printf("%s is working hard now.\n", ss[r].c_str());
	else
	  printf("%s is not working now.\n", ss[r].c_str());
      }
    }
  }

  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 12628
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define N 100010
using namespace std;
typedef pair<pair<int, int>, int> Type;
map<string, int> A;
set<Type> Q1, Q2;
set<Type>::iterator it;
int n, cnt, m, val[N], Time[N];
char name[N][30], s[30], opt[30];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int v, id;
    scanf("%s%d", s, &v);
    if (!A.count((string)s)) {
      A[(string)s] = ++cnt;
      int l = strlen(s);
      for (int j = 0; j < l; j++)
        name[cnt][j] = s[j];
      name[cnt][l] = 0;
    }
    id = A[(string)s];
    val[id] = v;
    Time[id] = i;
    Q2.insert(make_pair(make_pair(v, i), id));
  }
  int size = cnt;
  int K = size / 5;
  while (Q1.size() < K) {
    it = Q2.end();
    it--;
    Q1.insert(*it);
    Q2.erase(it);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int v, id;
    scanf("%s", opt);
    if (opt[0] == '+') {
      scanf("%s%d", s, &v);
      if (!A.count((string)s)) {
        A[(string)s] = ++cnt;
        int l = strlen(s);
        for (int j = 0; j < l; j++)
          name[cnt][j] = s[j];
        name[cnt][l] = 0;
      }
      id = A[(string)s];
      val[id] = v;
      Time[id] = i + n;
      size++;
      K = size / 5;
      Type now = make_pair(make_pair(v, i + n), id);
      it = Q2.end();
      it--;
      if ((*it).first.first > v) {
        printf("%s is not working now.\n", name[id]);
        Q2.insert(now);
        while (Q1.size() < K) {
          Q1.insert(*it);
          printf("%s is working hard now.\n", name[(*it).second]);
          Q2.erase(it);
        }
      } else {
        Q1.insert(now);
        it = Q1.begin();
        if ((*it).second == id && Q1.size() > K) {
          printf("%s is not working now.\n", name[id]);
          Q2.insert(*it);
          Q1.erase(it);
        } else {
          printf("%s is working hard now.\n", name[id]);
          while (Q1.size() > K) {
            printf("%s is not working now.\n", name[(*it).second]);
            Q2.insert(*it);
            Q1.erase(it);
          }
        }
      }
    } else {
      scanf("%s", s);
      size--;
      K = size / 5;
      int id = A[(string)s];
      Type now = make_pair(make_pair(val[id], Time[id]), id);
      it = Q1.find(now);
      if (it == Q1.end())
        it = Q2.find(now), Q2.erase(it);
      else
        Q1.erase(it);
      while (Q1.size() > K) {
        it = Q1.begin();
        printf("%s is not working now.\n", name[(*it).second]);
        Q2.insert(*it);
        Q1.erase(it);
      }
      while (Q1.size() < K) {
        it = Q2.end();
        it--;
        printf("%s is working hard now.\n", name[(*it).second]);
        Q1.insert(*it);
        Q2.erase(it);
      }
    }
  }
}
accuracy: 1
time_ms: 110
memory_kb: 14768
final_rank: 16

code_snippet: #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#define maxn 100100
using namespace std;
struct node {
  int val, time;
  node(int val, int time) : val(val), time(time) {}
  bool operator<(const node &A) const {
    if (val == A.val)
      return time > A.time;
    return val > A.val;
  }
};
int n, m, val;
int tval[maxn];
string op, name, mp[maxn];
map<string, int> tid;
set<node> st1, st2;
int main(void) {
  while (cin >> n) {
    st1.clear();
    st2.clear();
    tid.clear();
    for (int i = 1; i <= n; i++) {
      cin >> name >> val;
      mp[i] = name;
      tid[name] = i;
      tval[i] = val;
      st2.insert(node(val, i));
    }
    for (int i = 1; i <= n / 5; i++) {
      st1.insert(*st2.begin());
      st2.erase(st2.begin());
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
      cin >> op >> name;
      if (op == "+") {
        scanf("%d", &val);
        tval[n + i] = val;
        mp[n + i] = name;
        tid[name] = n + i;
        if ((st1.size() + st2.size() + 1) % 5 == 0) {
          st2.insert(node(val, n + i));
          node tmp = *st2.begin();
          st2.erase(st2.begin());
          st1.insert(tmp);
          if (mp[tmp.time] != name)
            cout << name << " is not working now." << endl;
          cout << mp[tmp.time] << " is working hard now." << endl;
          continue;
        }
        if (!st1.empty() && val >= (*--st1.end()).val) {
          cout << name << " is working hard now." << endl;
          node tmp = *--st1.end();
          st1.erase(--st1.end());
          st2.insert(tmp);
          cout << mp[tmp.time] << " is not working now." << endl;
          st1.insert(node(val, n + i));
          continue;
        }
        st2.insert(node(val, n + i));
        cout << name << " is not working now." << endl;
      } else {
        int ti = tid[name];
        if ((st1.size() + st2.size()) % 5 == 0) {
          if (st2.find(node(tval[ti], ti)) != st2.end()) {
            set<node>::iterator it1 = st2.find(node(tval[ti], ti));
            st2.erase(it1);
            node temp = *--st1.end();
            st1.erase(--st1.end());
            st2.insert(temp);
            cout << mp[temp.time] << " is not working now." << endl;
          } else {
            set<node>::iterator it2 = st1.find(node(tval[ti], ti));
            st1.erase(it2);
          }
        } else if (st1.find(node(tval[ti], ti)) != st1.end()) {
          set<node>::iterator it3 = st1.find(node(tval[ti], ti));
          st1.erase(it3);
          node temp = *st2.begin();
          st1.insert(temp);
          st2.erase(st2.begin());
          cout << mp[temp.time] << " is working hard now." << endl;
        } else {
          set<node>::iterator it4 = st2.find(node(tval[ti], ti));
          st2.erase(it4);
        }
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 13140
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define maxn 100100
struct P1 {
  string name;
  int v, tim;
  bool operator<(const P1 &pp) const {
    if (v != pp.v)
      return v < pp.v;
    else
      return tim < pp.tim;
  }
};
struct P2 {
  string name;
  int v, tim;
  bool operator<(const P2 &pp) const {
    if (v != pp.v)
      return v > pp.v;
    else
      return tim > pp.tim;
  }
} a[maxn];
set<P1> s1;
set<P2> s2;
int n, m;
string man;
int v;
#define P pair<int, int>
map<string, P> mp;
P1 p2top1(P2 tmp) {
  P1 ans;
  ans.name = tmp.name;
  ans.v = tmp.v;
  ans.tim = tmp.tim;
  return ans;
}
P2 p1top2(P1 tmp) {
  P2 ans;
  ans.name = tmp.name;
  ans.v = tmp.v;
  ans.tim = tmp.tim;
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    a[i].tim = i;
    cin >> a[i].name;
    scanf("%d", &a[i].v);
    mp[a[i].name] = P(a[i].v, i);
  }
  sort(a + 1, a + n + 1);
  int lx = n / 5;
  for (int i = 1; i <= lx; ++i)
    s1.insert(p2top1(a[i]));
  for (int i = lx + 1; i <= n; ++i)
    s2.insert(a[i]);
  scanf("%d", &m);
  int tot = n;
  for (int i = 1; i <= m; ++i) {
    int now = n + i;
    char op[5];
    scanf("%s", op);
    if (*op == '+') {
      cin >> man;
      scanf("%d", &v);
      mp[man] = P(v, now);
      tot++;
      set<P1>::iterator it;
      it = s1.begin();
      P1 tmp, this_man;
      if (it != s1.end()) {
        tmp = (*it);
        this_man.name = man;
        this_man.v = v;
        this_man.tim = now;
      }
      if (it != s1.end() && tmp < this_man) {
        s1.insert(this_man);
        cout << man;
        puts(" is working hard now.");
        if (tot % 5 != 0) {
          P1 tmp = (*it);
          P2 ttmp = p1top2(tmp);
          s1.erase(it);
          s2.insert(ttmp);
          cout << tmp.name;
          puts(" is not working now.");
        }
      } else {
        if (tot % 5 == 0) {
          set<P2>::iterator it;
          it = s2.begin();
          P2 this_, tmp;
          if (it != s2.end()) {
            tmp = (*it);
            this_.name = man;
            this_.v = v;
            this_.tim = now;
          } else
            tmp.v = -100000;
          if (this_ < tmp) {
            P1 cpy = p2top1(this_);
            s1.insert(cpy);
            cout << man;
            puts(" is working hard now.");
          } else {
            s2.erase(*it);
            P1 cpy = p2top1(tmp);
            s1.insert(cpy);
            s2.insert(this_);
            cout << man;
            puts(" is not working now.");
            cout << tmp.name;
            puts(" is working hard now.");
          }
        } else {
          P2 this_;
          this_.name = man;
          this_.v = v;
          this_.tim = now;
          s2.insert(this_);
          cout << man;
          puts(" is not working now.");
        }
      }
    } else {
      tot--;
      cin >> man;
      P sx = mp[man];
      set<P1>::iterator it;
      P1 tmp1;
      tmp1.name = man;
      tmp1.v = sx.first;
      tmp1.tim = sx.second;
      it = s1.find(tmp1);
      if (it == s1.end()) {
        P2 tmp2;
        tmp2 = p1top2(tmp1);
        s2.erase(tmp2);
        if (tot % 5 == 4) {
          it = s1.begin();
          tmp1 = (*it);
          s1.erase(it);
          tmp2 = p1top2(tmp1);
          s2.insert(tmp2);
          cout << tmp1.name;
          puts(" is not working now.");
        }
      } else {
        s1.erase(it);
        if (tot % 5 != 4) {
          set<P2>::iterator it2;
          it2 = s2.begin();
          P2 ss = (*it2);
          s2.erase(it2);
          P1 tt = p2top1(ss);
          s1.insert(tt);
          cout << ss.name;
          puts(" is working hard now.");
        }
      }
    }
  }
  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 14392
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)

#define all(c) std::begin(c), std::end(c)

#ifdef LOCAL
#define debug(...) debug_impl(#__VA_ARGS__, __VA_ARGS__)
template <class T, class ...Args> void debug_impl(string s, T&& f, Args &&...args) {
    cerr << "(" << s << "): " << "(" << forward<T>(f);
    ((cerr << ", " << forward<Args>(args)), ..., (cerr << ")\n"));
}
#else
#define debug(...) void(0)
#endif

template <class T> bool chmax(T& a, const T& b) { return b > a ? (a = b, true) : false; }
template <class T> bool chmin(T& a, const T& b) { return b < a ? (a = b, true) : false; }


template <class T> istream& operator>>(istream& in, vector<T>& v) {
    for (auto& e : v) in >> e;
    return in;
}
template <class ...Args> void read(Args&... args) {
    (cin >> ... >> args);
}

template <class T> ostream& operator<<(ostream& out, const vector<T>& v) {
    int n = v.size();
    rep(i, n) {
        out << v[i];
        if (i + 1 != n) out << ' ';
    }
    return out;
}

template <class T, class ...Tails> void print(T&& h, Tails &&... tails) {
    cout << h, ((cout << ' ' << forward<Tails>(tails)), ..., (cout << '\n'));
}

template <typename T, T(*op)(T, T), T(*e)()>
struct segtree {
    int n, siz;
    vector<T> dat;
    segtree(int n) : segtree(vector<T>(n, e())) {}
    segtree(vector<T> a) : n(a.size()) {
        siz = 1;
        while (siz < n) siz <<= 1;
        dat.assign(2 * siz, e());
        rep(i, n) {
            dat[siz + i] = a[i];
        }
        for (int i = n - 1; i > 0; --i) {
            dat[i] = op(dat[2 * i], dat[2 * i + 1]);
        }
    }

    T get(int p) const {
        return dat[siz + p];
    }

    T prod(int l, int r) const {
        T sml = e(), smr = e();
        l += siz, r += siz;
        for (; l < r; l >>= 1, r >>= 1) {
            if (l & 1) sml = op(sml, dat[l++]);
            if (r & 1) smr = op(dat[--r], smr);
        }
        return op(sml, smr);
    }

    T all_prod() const {
        return dat[1];
    }

    void set(int p, T v) {
        p += siz;
        dat[p] = v;
        while (p >>= 1) {
            dat[p] = op(dat[2 * p], dat[2 * p + 1]);
        }
    }
};

int op(int x, int y) {
    return x + y;
}
int e() {
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<string> names;

    vector<pair<int, int>> a(n);

    map<string, pair<int, int>> mp;

    rep(i, n) {
        string s;
        int x;
        read(s, x);
        a[i] = { x, i };

        names.push_back(s);

        mp[s] = { x, i };
    }

    int m;
    cin >> m;

    vector<tuple<bool, int, int>> b(m);

    int nxt_id = n;
    rep(i, m) {
        char c;
        string name;
        read(c, name);

        if (c == '+') {
            int x;
            read(x);
            b[i] = { true, x, nxt_id };
            mp[name] = { x, nxt_id };
            names.push_back(name);
            ++nxt_id;
        } else {
            auto [x2, i2] = mp[name];
            b[i] = { false, x2, i2 };
        }
    }

    vector<pair<int, int>> sorted;
    for (auto [x, id] : a) {
        sorted.emplace_back(x, id);
    }
    for (auto [is_join, x, id] : b) {
        if (is_join) {
            sorted.emplace_back(x, id);
        }
    }
    sort(all(sorted), greater<>());

    auto get_index = [&](int x, int id) {
        return lower_bound(all(sorted), make_pair(x, id), greater<>()) - sorted.begin();
    };
    auto get_original_index = [&](int id) {
        return sorted[id].second;
    };

    const int k = sorted.size();

    vector<int8_t> hard(k, false);

    segtree<int, op, e> seg(k);

    // debug(k);

    {
        int top20 = n / 5;

        vector<pair<int, int>> xs(n);
        rep(i, n) {
            auto [x, id] = a[i];

            int idx = get_index(x, id);
            xs[i] = { x, id };
            assert(seg.get(idx) == 0);
            seg.set(idx, 1);
        }
        sort(all(xs), greater<>());

        rep(i, top20) {
            hard[xs[i].second] = true;
        }
    }

    // debug(seg.all_prod());

    auto max_index_active = [&](int num) {
        int l = -1, r = k + 1;
        while (r - l > 1) {
            int p = (l + r) >> 1;
            if (seg.prod(0, p) < num) {
                l = p;
            } else {
                r = p;
            }
        }
        // seg[0, l) < num
        // seg[0, l] >= num
        // l is last active person.
        return l;
    };

    auto min_index_lazy = [&](int max_active) {
        if (max_active == k) return k;
        int l = max_active + 1, r = k + 1;
        while (r - l > 1) {
            int p = (l + r) >> 1;
            if (seg.prod(max_active + 1, p) == 0) {
                l = p;
            } else {
                r = p;
            }
        }
        // seg[max_active + 1, l) = 0
        // seg[max_active + 1, l] = 1
        return l;
    };

    auto print_active = [&](int id) {
        print(names[id], "is working hard now.");
    };
    auto print_inactive = [&](int id) {
        print(names[id], "is not working now.");
    };

    for (auto [is_join, x, id] : b) {
        // debug(x, id);
        if (is_join) {
            int pos = get_index(x, id);
            assert(seg.get(pos) == 0);
            seg.set(pos, 1);

            int num = seg.all_prod() / 5;

            if (seg.prod(0, pos + 1) <= num) {
                print_active(id);
                hard[get_original_index(pos)] = true;
            } else {
                print_inactive(id);
                hard[get_original_index(pos)] = false;
            }
        } else {
            int pos = get_index(x, id);
            assert(seg.get(pos) == 1);
            seg.set(pos, 0);
        }

        // debug(seg.all_prod());

        int cand1 = max_index_active(seg.all_prod() / 5);
        int cand2 = min_index_lazy(cand1);

        // debug(cand1, cand2);

        if (0 <= cand1 and cand1 < k) {
            int i = get_original_index(cand1);
            if (not hard[i]) {
                print_active(i);
                hard[i] = true;
            }
        }
        if (0 <= cand2 and cand2 < k) {
            int i = get_original_index(cand2);
            if (hard[i]) {
                print_inactive(i);
                hard[i] = false;
            }
        }
    }
}
accuracy: 1
time_ms: 40
memory_kb: 11712
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=2167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}
template<class T> T min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T sum(vector<T> &a){assert(!a.empty());T ans=a[0]-a[0];for(auto &x:a) ans+=x;return ans;}



void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	map<string,pair<int,int>> m;
	set<pair<pair<int,int>,string>> s1,s2;
	auto work_hard=[&](string S)->void{
		cout<<S<<" is working hard now.\n";
	};
	auto not_work=[&](string S)->void{
		cout<<S<<" is not working now.\n";
	};
	auto outcoming=[&](string S,bool output)->void{
		auto val=m[S];
		pair<pair<int,int>,string> dat={val,S};
		if((int)(s1.size()+s2.size())%5==0){
			if(s1.count(dat)){
				s1.erase(dat);
			}else{
				s2.erase(dat);
				auto tmp=(*s1.begin());
				s1.erase(tmp);
				s2.insert(tmp);
				if(output) not_work(tmp.second);
			}
		}else{
			if(s2.count(dat)){
				s2.erase(dat);
			}else{
				s1.erase(dat);
				auto tmp=(*s2.rbegin());
				s2.erase(tmp);
				s1.insert(tmp);
				if(output) work_hard(tmp.second);
			}
		}
		m.erase(S);
	};
	auto incoming=[&](string S,int level,int ind,bool output)->void{
		pair<int,int> val={level,ind};
		pair<pair<int,int>,string> dat={val,S};
		m[S]=val;
		if((int)(s1.size()+s2.size())%5==4){
			auto tmp=(*s2.rbegin());
			if(tmp.first<val){
				s1.insert(dat);
				if(output) work_hard(S);
			}else{
				s2.insert(dat);
				s2.erase(tmp);
				s1.insert(tmp);
				if(output) not_work(S),work_hard(tmp.second);
			}
		}else{
			if(s1.empty()){
				s2.insert(dat);
				if(output) not_work(S);
				return;
			}
			auto tmp=(*s1.begin());
			if(tmp.first>val){
				s2.insert(dat);
				if(output) not_work(S);
			}else{
				s1.insert(dat);
				s1.erase(tmp);
				s2.insert(tmp);
				if(output) work_hard(S),not_work(tmp.second);
			}
		}
	};
	int N;
	cin>>N;
	rep(i,N){
		string S;
		int A;
		cin>>S>>A;
		incoming(S,A,i,0);
	}
	int M;
	cin>>M;
	rep(i,M){
		char c;
		string S;
		int A;
		cin>>c>>S;
		//cout<<i<<endl;
		if(c=='+') cin>>A,incoming(S,A,i+N,1);
		else outcoming(S,1);
	}
}
accuracy: 1
time_ms: 50
memory_kb: 11284
final_rank: 3

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<pair<pair<int,int>,string>> v(n);
    for(int i=0;i<n;i++){
        cin >> v[i].second >> v[i].first.first;
        v[i].first.second = i;
    }
    sort(v.rbegin(), v.rend());
    map<string, pair<int,int>> mp;
    for(int i=0;i<n;i++){
        mp[v[i].second] = v[i].first;
    }

    map<pair<int,int>,string> hw,nw;
    for(int i=0;i<n;i++){
        if(i<n/5){
            hw[v[i].first] = v[i].second;
        }
        else{
            nw[v[i].first] = v[i].second;
        }
    }
    int num = n;
    int q; cin >> q;
    while(q--){
        char c; cin >> c;
        vector<string> change;
        if(c == '+'){
            string s; int a; cin >> s >> a;
            pair<int,int> p = pair<int,int>(a,num);
            mp[s] = p;
            num++;

            if(nw.size() == 0){
                nw[p] = s;
            }
            else{
                auto itr = nw.end(); itr--;
                auto uo = *itr;
                if(uo.first < p){
                    hw[p] = s;
                }
                else{
                    nw[p] = s;
                }
            }

            while(hw.size() < mp.size()/5){
                auto itr = nw.end(); itr--;
                auto uo = *itr;
                hw[uo.first] = uo.second;
                nw.erase(itr);
                change.push_back(uo.second);
            }
            while(hw.size() > mp.size()/5){
                auto itr = hw.begin();
                auto uo = *itr;
                nw[uo.first] = uo.second;
                hw.erase(itr);
                change.push_back(uo.second);
            }

            {
                if(hw.find(p) != hw.end()){
                    cout << s << " is working hard now." << "\n";
                }
                else{
                    cout << s << " is not working now." << "\n";
                }
            }
            sort(change.begin(), change.end());
            for(auto t:change){
                if(s == t)continue;
                if(hw.find(mp[t]) != hw.end()){
                    cout << t << " is working hard now." << "\n";
                }
                else{
                    cout << t << " is not working now." << "\n";
                }
            }
        }
        else{
            string s; cin >> s;
            auto p = mp[s];
            if(hw.find(p) != hw.end()){
                hw.erase(p);
            }
            else{
                nw.erase(p);
            }
            mp.erase(s);

            while(hw.size() < mp.size()/5){
                auto itr = nw.end(); itr--;
                auto uo = *itr;
                hw[uo.first] = uo.second;
                nw.erase(itr);
                change.push_back(uo.second);
            }
            while(hw.size() > mp.size()/5){
                auto itr = hw.begin();
                auto uo = *itr;
                nw[uo.first] = uo.second;
                hw.erase(itr);
                change.push_back(uo.second);
            }

            sort(change.begin(), change.end());
            for(auto t:change){
                if(hw.find(mp[t]) != hw.end()){
                    cout << t << " is working hard now." << "\n";
                }
                else{
                    cout << t << " is not working now." << "\n";
                }
            }
        }
    }
}
accuracy: 1
time_ms: 40
memory_kb: 12904
final_rank: 5

code_snippet: #pragma GCC ta g("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//#include <atcoder/maxflow>
//using namespace atcoder;
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
const int mod = 1e9 + 7;
//const int mod = 998244353;

struct dat{
    int a,t;
    string name;
    dat(int a, int t, string name) : a(a), t(t), name(name) {}
    bool operator< (const dat &d) const {
        if(a != d.a) return a > d.a;
        if(t != d.t) return t > d.t;
        return name < d.name;
    }
};

int main(){
    int n; cin >> n;
    map<string,pii> mp;
    int sz = n;
    set<dat> se;
    se.emplace(inf,inf,"");
    rep(i,n){
        string s; cin >> s;
        int a; cin >> a;
        se.emplace(a,i,s);
        mp[s] = {a,i};
    }
    int q; cin >> q;
    auto itr = se.begin();
    int hard = n/5;
    int h = hard;
    while(h > 0){
        h--;
        itr++;
    }
    rep(i,q){
        char c; cin >> c;
        if(c == '+'){
            string s; cin >> s;
            int a; cin >> a;
            dat d(a,i+n,s);
            mp[s] = {a,i+n};
            sz++;
            int nh = sz/5;
            se.emplace(d);
            if(d < *itr){
                cout << d.name << " is working hard now.\n";
                if(hard < nh) hard = nh;
                else{
                    cout << (*itr).name << " is not working now.\n";
                    itr--;
                }
            }else{
                if(hard < nh){
                    itr++;
                    if((*itr).t == d.t){
                        cout << d.name << " is working hard now.\n";
                    }else{
                        cout << d.name << " is not working now.\n";
                        cout << (*itr).name << " is working hard now.\n";
                    }
                    hard = nh;
                }else{
                    cout << d.name << " is not working now.\n";
                }
            }
        }else{
            string s; cin >> s;
            dat d(mp[s].first,mp[s].second,s);
            sz--;
            int nh = sz/5;
            if(d < *itr){
                se.erase(d);
                if(hard > nh) hard = nh;
                else{
                    itr++;
                    cout << (*itr).name << " is working hard now.\n"; 
                }
            }else if((*itr).name == d.name){
                itr = se.erase(itr);
                if(hard > nh){
                    hard = nh;
                    itr--;
                }else{
                    cout << (*itr).name << " is working hard now.\n";
                }
            }else{
                se.erase(d);
                if(hard > nh){
                    hard = nh;
                    cout << (*itr).name << " is not working now.\n";
                    itr--;
                }
            }
            mp.erase(s);
        }
    }
}
accuracy: 1
time_ms: 60
memory_kb: 11184
final_rank: 4

code_snippet: #pragma GCC ta g("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//#include <atcoder/maxflow>
//using namespace atcoder;
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
const int mod = 1e9 + 7;
//const int mod = 998244353;

struct dat{
    int a,t;
    string name;
    dat(int a, int t, string name) : a(a), t(t), name(name) {}
    bool operator< (const dat &d) const {
        if(a != d.a) return a > d.a;
        if(t != d.t) return t > d.t;
        return name < d.name;
    }
};

int main(){
    int n; cin >> n;
    map<string,pii> mp;
    int sz = n;
    set<dat> se;
    se.emplace(inf,inf,"");
    rep(i,n){
        string s; cin >> s;
        int a; cin >> a;
        se.emplace(a,i,s);
        mp[s] = {a,i};
    }
    int q; cin >> q;
    auto itr = se.begin();
    int hard = n/5;
    int h = hard;
    while(h > 0){
        h--;
        itr++;
    }
    rep(i,q){
        char c; cin >> c;
        if(c == '+'){
            string s; cin >> s;
            int a; cin >> a;
            dat d(a,i+n,s);
            mp[s] = {a,i+n};
            sz++;
            int nh = sz/5;
            se.emplace(d);
            if(d < *itr){
                cout << d.name << " is working hard now.\n";
                if(hard < nh) hard = nh;
                else{
                    cout << (*itr).name << " is not working now.\n";
                    itr--;
                }
            }else{
                if(hard < nh){
                    itr++;
                    if((*itr).t == d.t){
                        cout << d.name << " is working hard now.\n";
                    }else{
                        cout << d.name << " is not working now.\n";
                        cout << (*itr).name << " is working hard now.\n";
                    }
                    hard = nh;
                }else{
                    cout << d.name << " is not working now.\n";
                }
            }
        }else{
            string s; cin >> s;
            dat d(mp[s].first,mp[s].second,s);
            sz--;
            int nh = sz/5;
            if(d < *itr){
                cout << d.name << " is not working now.\n";
                se.erase(d);
                if(hard > nh) hard = nh;
                else{
                    itr++;
                    cout << (*itr).name << " is working hard now.\n"; 
                }
            }else if((*itr).name == d.name){
                itr = se.erase(itr);
                if(hard > nh){
                    hard = nh;
                    itr--;
                }else{
                    cout << (*itr).name << " is working hard now.\n";
                }
            }else{
                se.erase(d);
                if(hard > nh){
                    hard = nh;
                    cout << (*itr).name << " is not working now.\n";
                    itr--;
                }
            }
            mp.erase(s);
        }
    }
}
accuracy: 0.15151515151515152
time_ms: 60
memory_kb: 11264
final_rank: 19