已使用链表,结果还是T飞……
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
const int INF = 2147483647;
const int S = 5*1e4+5;
list <int> s[S];
inline LL read()
{
LL x=0,f=1;
char ch = getchar();
while(!isdigit(ch)) {if(ch == '-') f = -1;ch = getchar();}
while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
return f*x;
}
int main(int argc,char *argv[])
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
int T = read();
for(int ii = 1;ii <= T;++ii)
{
printf("Case %d:\n",ii);
int n = read(),q = read();
while(q--)
{
char op[5];
scanf("%s",op);
int k = read();
if(op[0] == 'p' && op[1] == 'u' && op[2] == 's'){int x = read();s[k].push_front(x);}
else if(op[0] == 'p' && op[1] == 'o' && op[2] == 'p' && !s[k].empty()) s[k].pop_front();
else if(op[0] == 'p' && op[1] == 'u' && op[2] == 't')
{
int k2 = read();
s[k].insert(s[k].begin(),s[k2].begin(),s[k2].end());
s[k2].clear();
}
else s[k].empty()?puts("Empty!"):printf("%d\n",s[k].front());
}
}
//printf("Tide used = %.0lf.ds\n",((double)clock()/(double)CLOCKS_PER_SEC) * 1000.0);
return 0;
}