The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack

时间:2023-11-10 21:43:32

题目链接

题意:

题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!!

代码:

#include <stdio.h>
#include <iostream>
#include <vector>
#include <deque>
#include <list>
#define IO ios::sync_with_stdio(0);\
    cin.tie();cout.tie();
using namespace std;
*+;
list <int > q[N];
int main()
{
    int T;
    scanf("%d",&T);
    //cin >> T;
    while(T--)
    {
        int n,q1;
        scanf("%d%d",&n,&q1);
        ; i <= n; i++)
            q[i].clear();
        while(q1--)
        {
            int op,s,v,t;
            scanf("%d",&op);
            )
            {
                scanf("%d%d",&s,&v);
                q[s].push_back(v);
            }
            )
            {
                scanf("%d",&s);
                if(q[s].empty())
                {
                    //cout << "EMPTY" << endl;
                    printf("%s\n", "EMPTY");
                }
                else
                {
                    //cout << q[s].back() <<endl;
                    printf("%d\n",q[s].back());
                    q[s].pop_back();
                }
            }
            )
            {
                scanf("%d%d",&s,&t);
                q[s].splice(q[s].end(),q[t]); //将s,t合并,并清除t中元素
                //q[t].clear();
            }
        }

    }
     ;
}