社区讨论

代码求调

P2776[SDOI2007] 小组队列参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@lo2ww61r
此快照首次捕获于
2023/10/23 21:06
2 年前
此快照最后确认于
2023/10/23 21:06
2 年前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
int weee[200000+5];
struct node
{
    int data,weee;//小组和元素
    node *nxt;
    node *pre;
    node()
    {
        data=0;
        weee=0;
    }
};
node head,*p;
void init()
{
    head.pre=&head;
    head.nxt=&head;
    head.weee=-1;
}
void push(int x)
{
    p=new node;
    p->data=x;
    p->weee=weee[x];
    p->pre=&head;
    while((p->pre!=head.pre)&&(p->weee!=p->pre->weee))
        p->pre=p->pre->nxt;
    p->nxt=p->pre->nxt;
    p->pre->nxt=p;
    p->nxt->pre=p;
}
int pop()
{
    p=head.pre;
    head.pre->pre->nxt=&head;
    head.pre=head.pre->pre;
    return p->data;
}
int main()
{
    init();
    int n,m,T;
    cin>>n>>m;
    for(int i=0;i<m;i++)cin>>weee[i];
    cin>>T;
    int rf=0;
    string jjj="";
    while(T--)
    {
        cin>>jjj;
        if(jjj=="push")
        {
            cin>>rf;
            push(rf);
        }
        if(jjj=="pop")
            cout<<pop()<<'\n';
    }
    return 0;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...