CSU 1982: Small M's mobile HDD

Source: Internet
Author: User

1982: Small M's mobile HDD

Submit Page    Summary Time Limit: 1 Sec Memory Limit: Ten Mb submitted: Solved: >

Description

Small m recently bought a mobile hard drive to store files that are not commonly used on their computers. But after he threw the files into the hard drive, he felt that the files didn't seem to be well categorized, so wouldn't it be a hassle to find them later?
Little M finally decided to classify the files and move the same class to the same place. So now little m has these kinds of operations:
1 u means to put the file numbered U on top
2 U means put the file numbered U at the bottom
3 U v indicates that a file numbered U is placed behind a file of number V
It is known that at the very beginning, file number 1th is arranged from top to n
Now that little M has given him all the work he has done, can you tell him what the sequence after the operation is going to look like?

Input

First behavior a number T (t<=10) indicates the number of data groups
Second act two numbers n, m (1<=n,m<=300000) indicate the sequence length and the number of operations of a small m
The next m line is two or three digits per line, with the exact meaning of the face
Ensure data is valid

Output

The output line represents the sequence after the end of the small m operation

Sample Input
110 51 52 32 63 4 83 1 3
Sample Output
5 2 7 8 4 9 10 3 1 6
Hintsource

2017 Summer Training School team selection

Author

Lu Ming Wei

Exercises

Use a linked list to simulate the size of the data and the time it takes to look at it.

You know, you can only use a linked list

But the lookup time of the list is O (n)

So we're going to set more pointers A[i]->next point to the location where I

The time to find this is O (n)

1#include <cstdio>2#include <time.h>3#include <stdlib.h>4#include <cstring>5 using namespacestd;6 structDoublenode7 {8     intdata;9     structDoublenode *next, *Prior;Ten};//define a doubly linked list OnetypedefstructDoublenode Dnode;//Formatting Definitions A  - intMain () - { the     intT; -scanf"%d",&t); -      while(t--) -     { +         intn,m; -scanf"%d%d",&n,&m); +Dnode *pnew,*phead,*ptail,*pend,*pk_1,*pk,*pk1,*p1,*p2, *mp[300009]; APhead= (Dnode *) malloc (sizeof(Dnode));//Designing a head node for a linked list atmp[0]= (Dnode *) malloc (sizeof(Dnode)); -Phead->data=0; -Phead->next =NULL; -Phead->prior =NULL; -Ptail=Phead; -mp[0]->next=Phead; inmp[0]->prior=NULL; -mp[0]->data=0; to          for(intI=1; i<=n; i++) +         { -pnew= (Dnode *) malloc (sizeof(Dnode));//generate head node, tail interpolation method thePnew->data=i; *Ptail->next =pnew; $Pnew->prior =Ptail;Panax NotoginsengPtail=pnew; -Ptail->next =NULL; themp[i]= (Dnode *) malloc (sizeof(Dnode)); +mp[i]->next=Ptail; AMp[i]->prior=NULL; theMp[i]->data=i; +         } -Pend= (Dnode *) malloc (sizeof(Dnode)); $  $Pend->prior=Ptail; -ptail->next=Pend; -pend->next=NULL; the         intHaha=0; -          while(m--)Wuyi         { the  -             intc,k,d; Wuscanf"%d",&c); -             if(c==1) About             { $scanf"%d",&k); -Pk=mp[k]->Next; -Pk_1=pk->Prior; -Pk1=pk->Next; APk_1->next=pk_1->next->Next; +Pk1->prior=pk1->prior->Prior; theP1=phead->Next; -pk->next=P1; $Pk->prior=Phead; thephead->next=PK; theP1->prior=PK; the             } the             Else if(c==2) -             { inscanf"%d",&k); thePk=mp[k]->Next; thePk_1=pk->Prior; AboutPk1=pk->Next; thePk_1->next=pk_1->next->Next; thePk1->prior=pk1->prior->Prior; the  +P1=pend->Prior; -pk->next=Pend; thePk->prior=P1;Bayip1->next=PK; thePend->prior=PK; the             } -             Else -             { thescanf"%d%d",&k,&d); the  thePk=mp[k]->Next; thePk_1=pk->Prior; -Pk1=pk->Next; thePk_1->next=pk_1->next->Next; thePk1->prior=pk1->prior->Prior; the 94P1=mp[d]->Next; theP2=p1->Next; thepk->next=P2; thePk->prior=P1;98p1->next=PK; AboutP2->prior=PK; -             }101             //printf ("Step%d has been completed \ n", ++haha);102         }103       //printf ("Operation completed \ n");104       //scanf ("%d", &m); thePnew=phead->Next;106          while(pnew->next)107         {108printf"%d",pnew->data);109Pnew=pnew->Next; the         }111printf"\ n"); the     }113     return 0; the}

CSU 1982: Small M's mobile HDD

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.