代码求调
查看原帖
代码求调
552688
clx201022楼主2023/3/19 15:31
#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;
}
2023/3/19 15:31
加载中...