TLE!!!怎么改?
查看原帖
TLE!!!怎么改?
712464
KvX07楼主2022/7/17 07:42
#include<bits/stdc++.h>
using namespace std;
typedef long long Data;
typedef struct Node
{
	Data data;
	struct Node *next;
	struct Node *prev;
}Node,List;

Node *CreateList()
{
	Node *head = new Node;
	head->next = NULL;
	return head;
}

Node *CreateNode()
{
	Node *newNode = new Node;
	newNode->next = NULL;
	return newNode;
}

void PushNode(List *list,Data data)
{
	Node *newNode = CreateNode();
	newNode->data = data;
	Node *curNode = list;
	while(curNode != NULL)
	{
		if(curNode->next == NULL)
		{
			curNode->next = newNode;
			break;
		}
		curNode = curNode->next;
	}
}

signed main()
{
	List *list=CreateList();
	Node *curNode=list;
	#define int long long
	int n,m;
    cin>>n>>m;
	for(int i=1;i<=n;++i)
	{
	    int x;
	    cin>>x;
	    PushNode(list,x);
	}
	for(int i=1;i<=m;++i)
	{
	    int y;
	    cin>>y;
	    int cnt;
	    while(curNode!=NULL)
	    {
	        curNode=curNode->next;
	        cnt++;
	        if(cnt==y)
	        {   cout<<curNode->data<<endl;
	            break;
	        }
	    }
	}
	return 0; 
}
2022/7/17 07:42
加载中...