#include<bits/stdc++.h>
#include<deque>
using namespace std;
typedef long long ll;
const int maxn= 1e6+5;
const int inf = 0x3f3f3f3f;
int cnt,t,n;
struct node{
int pro;
ll w;
bool operator == (const node &A) const
{
if (pro == A.pro) return true;
return false;
};
// bool operator < (const node &A) const
// {
// if (pro < A.pro) return true;
// return false;
// };
};
char s[100];
bool top =0;
int tmp;
deque<node>::iterator pos;
deque<node>::iterator tpos;
deque<node> q;
int opt = 0;
void doAdd(int u){
node tt;
tt.pro = u;
pos = find(q.begin(), q.end(), tt);
if (pos != q.end())
printf("same priority");
else{
printf("success");
node x ;
x.pro=u;
x.w=0;
// cout<<endl<<"add:"<<x.pro<<endl;
q.push_back(x);
}
}
void doClose(int u){
node tt ;
tt.pro = u;
pos = find(q.begin(), q.end(), tt);
if (pos != q.end()){
printf("close %d with %lld",u,(*pos).w);
if(pos==tpos)top=0;
q.erase(pos);
}else{
printf("invalid priority");
}
}
void doChat(ll u){
if(q.empty()){
printf("empty");
}else{
printf("success");
if(!top){
node x = q.front();
x.w+=u;
q.pop_front();
q.push_front(x);
}else{
node x;x.pro = (*tpos).pro;
x.w = (*tpos).w;
// cout<<"chat:"<<x.pro<<":"<<x.w<<"->"<<u<<endl;
x.w+=u;
deque<node>::iterator ttpos = q.erase(tpos);
// cout<<"output:"<<endl;
// for(pos=q.begin();pos!=q.end();pos++){
// cout<<(*pos).pro<<" "<<(*pos).w<<endl;
// }
// cout<<"output:"<<endl;
// for(pos=q.begin();pos!=q.end();pos++){
// cout<<(*pos).pro<<" "<<(*pos).w<<endl;
// }
// x.w=666;
// x.pro = 777;
// cout<<x.w<<endl;
// cout<<(*tpos).pro<<endl;
// if(x.pro==q.front().pro){
// cout<<111111<<endl;
// q.push_front(x);
// }
// else
q.insert(ttpos,x);
// cout<<q.size()<<endl;
// cout<<"output:"<<endl;
// for(pos=q.begin();pos!=q.end();pos++){
// cout<<(*pos).pro<<" "<<(*pos).w<<endl;
// }
}
}
}
void doRotate (int u){
int sz = q.size();
if(u<1 || u>sz)printf("out of range");
else{
printf("success");
int ct = 0;
for(pos=q.begin();pos!=q.end();pos++){
ct++;
if(ct==u)break;
}
node x = (*pos);
if(top && pos==tpos){
q.erase(pos);
q.push_front(x);
tpos = q.begin();
}else{
q.erase(pos);
q.push_front(x);
}
}
}
void doPrior (){
if(q.empty()){
printf("empty");
}else {
printf("success");
deque<node>::iterator pos1;
ll mxu = 0;
for(pos=q.begin();pos!=q.end();pos++){
if((*pos).pro>mxu){
mxu=(*pos).pro;
pos1=pos;
}
}
node x = (*pos1);
// cout<<"Prior:"<<(*tpos).pro<<" "<<x.pro<<endl;
// cout<<top<<endl;
if(top && x.pro==(*tpos).pro){
// cout<<endl<<"here"<<endl;
q.erase(pos1);
q.push_front(x);
tpos = q.begin();
// cout<<"output:"<<endl;
// for(pos=q.begin();pos!=q.end();pos++){
// cout<<(*pos).pro<<" "<<(*pos).w<<endl;
// }
}else{
q.erase(pos1);
q.push_front(x);
}
}
}
void doChoose(int u){
bool fd = 0;
for(pos=q.begin();pos!=q.end();pos++){
if((*pos).pro==u){
fd =1;
node x = (*pos);
if(top && pos==tpos){
q.erase(pos);
q.push_front(x);
tpos = q.begin();
}else{
q.erase(pos);
q.push_front(x);
}
break;
}
}
if(fd)printf("success");
else printf("invalid priority");
}
void doTop(int u){
top =1;
bool fd = 0;
for(pos=q.begin();pos!=q.end();pos++){
if((*pos).pro==u){
fd = 1;
tpos = pos;
// cout<<"top:"<<(*pos).w <<endl;
break;
}
}
if(fd)printf("success");
else printf("invalid priority");
}
void doUntop (){
if(!top)printf("no such person");
else printf("success");
top=0;
}
void ext(){
node x;
if(top){
if((*tpos).w!=0){
printf("Bye %d: %I64d\n",x.pro,x.w);
q.erase(tpos);
}
}
while(!q.empty()){
// cout<<"font "<<q.size()<<" "<< q.front().pro<<endl;
x = (*q.begin());
if(x.w!=0)printf("Bye %d: %I64d\n",x.pro,x.w);
q.pop_front();
}
}
void init(){
opt = 0;
top = 0;
q.clear();
}
int main()
{
//freopen("in.txt","r",stdin);
// ios::sync_with_stdio(false);
scanf("%d",&cnt);
while(cnt--){
scanf("%d",&n);
init();
for(int i=0;i<n;i++){
scanf("%s",s);
printf("Operation #%d: ",++opt);
switch(s[0]){
case 'A':
scanf("%d",&tmp);
doAdd(tmp);
break;
case 'C':
if(s[1]=='l'){
scanf("%d",&tmp);
doClose(tmp);
}else if(s[1]=='h' && s[2]=='a'){
ll ttmp;
scanf("%I64d",&ttmp);
doChat(ttmp);
}else if(s[1]=='h' && s[2]=='o'){
scanf("%d",&tmp);
doChoose(tmp);
}
break;
case 'R':
scanf("%d",&tmp);
doRotate(tmp);
break;
case 'P':
doPrior();
break;
case 'T':
scanf("%d",&tmp);
doTop(tmp);
break;
case 'U':
doUntop();
break;
}
printf(".\n");
}
ext();
}
return 0;
}
Beijing.zip_2014 ACM_ACM Beijing_acm icpc _beijing_icpc
版权申诉
16 浏览量
2022-09-15
00:09:11
上传
评论
收藏 8KB ZIP 举报
寒泊
- 粉丝: 75
- 资源: 1万+
最新资源
- Docker容器配置进阶
- tensorflow-gpu-2.7.4-cp37-cp37m-manylinux2010-x86-64.whl
- 多段线、 圆、弧转多段线(仅我可见)
- tensorflow-2.7.2-cp38-cp38-manylinux2010-x86-64.whl
- yeyue-p8Yi4-ve4a83792.apk
- tensorflow-gpu-2.7.3-cp38-cp38-manylinux2010-x86-64.whl
- 五相感应电机矢量控制模型MATLAB
- RGLED (1) (1).circ
- IMG_20240427_215747.jpg
- python下前端WEB学习笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈