萌新求调,玄关
查看原帖
萌新求调,玄关
964019
ybc2027_chenyibo楼主2024/6/9 08:30

链表有什么错吗QAQ

//                                                     ^
//	                                                   ||
//	     ^                             ^               ||
//	    | \                           | \             / \
//	  _/   \_________________________/   \_         _/   \_
//	 <_      _________________________    _>       <__    __>
//	   \_   /		 / \           ___\__/__/\ |\____\____/___/|
//	     |  |   |\____\ /______/|  __ | | \_/  |  _____  _____ |
//	     |  |   |  ____________ | | | | | | |  | |    /  \   | |
//	     |  |   | |__________ | | | | | | | |  | |__/     \__| |
//	     |  |   | |___________| | | | | | | |  |  __       __  |
//	     |  |   |_____  ________| | | | | | |  | |  \     /  | |
//	     |  |    __  |  |   __   / /  | | | |  | _____________ |          
//	     |  |   / _\ |  |  /_ \/ /    | | |/   |/    /   \    \|
//	     |  |  | /_  |  |   /   /     | |       ____/     \____ 
//	     |  |   \_/  |_/   /__/       |_/      <_____       ___> 
//	    /__-                                         \_  _/
//	                                                  \  /
//	                                                   \ /
//	                                                   | |
//	                                                   | |
//	                                                   ||
//	                                                   ||
//	                                                   V
#include <bits/stdc++.h>
using namespace std;

const int M=1e5+5;

struct node
{
	int next;
}a[M];

int group[M];
int last[M];

int main()
{
	int n,QAQ;
	scanf("%d %d",&n,&QAQ);
	for (int i=1; i<=n; i++)
	{
		scanf("%d",&group[i]);
	}
	int m;
	scanf("%d",&m);
	int tail=1,head=0;
	while (m--)
	{
		string s;
		cin>>s;
		if (s[1]=='u')
		{
			int x;
			scanf("%d",&x);
			x++;
			if (last[group[x]]==0)
			{
				last[group[x]]=x;
				if (tail<=head)
				{
					a[tail].next=x;
				}
				else
				{
					head=x;
				}
				tail=x;
			}
			else
			{
				a[x].next=a[last[group[x]]].next;
				a[last[group[x]]].next=x;
				last[group[x]]=x;
			}
		}
		else
		{
			printf("%d\n",head-1);
			if (last[group[head]]==head) last[group[head]]=0;
			head=a[head].next;
		}
	}
	return 0; 
}
/*
  1 1
  1
  4
  push 0 pop push 0 pop
 */
2024/6/9 08:30
加载中...