Submission #18445

#TimeUsernameProblemLanguageResultExecution timeMemory
18445chan492811Collider (IZhO11_collider)C++98
0 / 100
319 ms33288 KiB
#include <cstdio> #include <malloc.h> using namespace std; int n,m,sqrtn; struct node{ char data; node *next,*prev; }; node *front[10000],*finding; char arr[1000010]; void find(int a){ int i=0; while(i*sqrtn+sqrtn<a) i++; finding=front[i]; i=i*sqrtn; while(i<a) finding=finding->next,i++; } int main(){ int i,j,a,s; char flag,data; node *temp,*prev,*newnode,*free1,*free2; scanf("%d %d %s\n",&n,&m,arr); for(i=1;i*i<n;i++); sqrtn=i; j=0; prev=(node *)malloc(sizeof(node)); for(i=0;i<n;i++){ temp=(node *)malloc(sizeof(node)); temp->data=arr[i]; temp->prev=prev; prev->next=temp; if(j*sqrtn==i){ front[j++]=temp; } prev=temp; } for(i=0;i<m;i++){ scanf("%c ",&flag); if(flag=='a'){ scanf("%d %d\n",&a,&s); j=0; a--; s--; find(a); data=finding->data; free1=finding; find(s); temp=finding; newnode=(node *)malloc(sizeof(node)); newnode->data=data; newnode->prev=temp; newnode->next=temp->next; temp->next=newnode; newnode->next->prev=newnode; find(a); temp=finding; temp->next->prev=temp->prev; temp->prev->next=temp->next; for(j=0;j*sqrtn<n;j++){ if(j*sqrtn>s) front[j]=front[j]->prev; else if(j*sqrtn>=a) front[j]=front[j]->next; } free(free1); }else{ scanf("%d\n",&a); find(a); printf("%c\n",finding->data); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...