不跟没说过话的打开窗口说bye
wa太多因为搞大新闻哈希,暴力来什么事也没有
大模拟总结 1:写的时候要小心谨慎
2:题目要仔细读不放过任何小点
3:注意long long 数组什么的
4:分析复杂度感觉能过就不用想着优化
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<cstring>
#define maxn 5200
#define LL long long
using namespace std;
int qu[maxn], l, ha[maxn], ha2[maxn]; // 储存编号
map<int,int>index; //相应优先级对应的哈希值
int len; //哈希长度
set<int>se; //储存优先级
LL va[maxn];
int topWindow;
int i1 = 0;
void solve()
{
printf("Operation #%d: ", i1);
}
void Add()
{
int x;
scanf("%d", &x);
solve();
if(se.find(x) != se.end())
{
printf("same priority.\n", i1);
return ;
}
len++;
l++;
se.insert(x);
index[x] = len;
ha2[len] = x;
va[len] = 0;
qu[l] = len;
ha[len] = l;
printf("success.\n");
}
void Close()
{
int x;
scanf("%d", &x);
solve();
if(se.find(x) != se.end())
{
if(topWindow == x) topWindow = -1;
se.erase(x);
int po = index[x];
printf("close %d with %I64d.\n", x, va[po]);
for(int i = ha[po]; i < l; i++)
{
qu[i] = qu[i + 1];
ha[qu[i + 1]] = i;
}
l--;
}
else printf("invalid priority.\n");
}
void Chat()
{
int x;
scanf("%d", &x);
solve();
if(topWindow != -1)
{
int po = index[topWindow];
va[po] = va[po] + x;
printf("success.\n");
}
else if(l)
{
int po = qu[1];
va[po] = va[po] + x;
printf("success.\n");
}
else printf("empty.\n");
}
void Rotate()
{
int x;
scanf("%d", &x);
solve();
if(x > l || x <= 0)printf("out of range.\n");
else {
for(int i = x - 1; i >=1; i--)
{
int xx = qu[i], yy = qu[i + 1];
swap(qu[i], qu[i + 1]);
ha[xx] = i + 1;
ha[yy] = i;
}
printf("success.\n");
}
}
void Prior()
{
solve();
if(l == 0)printf("empty.\n");
else
{
set<int>:: iterator it;
it = se.end();
it --;
int x = *it;
int po = index[x];
x = ha[po];
for(int i = x - 1; i >=1; i--)
{
int xx = qu[i], yy = qu[i + 1];
swap(qu[i], qu[i + 1]);
ha[xx] = i + 1;
ha[yy] = i;
}
printf("success.\n");
}
}
void Choose()
{
int x;
scanf("%d", &x);
solve();
if(se.find(x) != se.end())
{
printf("success.\n");
int po = index[x];
x = ha[po];
for(int i = x - 1; i >= 1; i--)
{
int xx = qu[i], yy = qu[i + 1];
swap(qu[i], qu[i + 1]);
ha[xx] = i + 1;
ha[yy] = i;
}
}
else printf("invalid priority.\n");
}
void Top()
{
int x;
scanf("%d", &x);
solve();
if(se.find(x) != se.end())
{
topWindow = x;
printf("success.\n");
}
else{
printf("invalid priority.\n");
}
}
void Untop()
{
solve();
if(topWindow == -1)printf("no such person.\n");
else {
topWindow = - 1;
printf("success.\n");
}
}
string s;
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
l = len = 0, topWindow = -1;
i1 = 0;
memset(va,0,sizeof(va));
memset(ha,0,sizeof(ha));
memset(ha2,0,sizeof(ha2));
index.clear();
se.clear();
int n;
scanf("%d", &n);
while(n--)
{
i1++;
cin >> s;
if(s == "Add") Add();
else if(s == "Close") Close();
else if(s == "Chat") Chat();
else if(s == "Rotate") Rotate();
else if(s == "Prior") Prior();
else if(s == "Choose") Choose();
else if(s == "Top") Top();
else Untop();
}
if(topWindow != -1 && va[index[topWindow]]) printf("Bye %d: %I64d\n", topWindow, va[index[topWindow]]);
for(int i = 1; i <= l; i++)
if(va[qu[i]] && ha2[qu[i]] != topWindow) printf("Bye %d: %I64d\n",ha2[qu[i]], va[qu[i]]);
}
return 0;
}