# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
18448 | chan492811 | Collider (IZhO11_collider) | C++98 | 366 ms | 33992 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <malloc.h>
using namespace std;
int n,m,sqrtn;
struct node{
char data;
node *next,*prev;
};
node *front[100000],*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;
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--; if(a==s) continue;
find(a); data=finding->data; temp=finding; //finding=a
temp->next->prev=temp->prev; temp->prev->next=temp->next;
for(j=0;j*sqrtn<n;j++) if(j*sqrtn>=a) front[j]=front[j]->next; free(temp);
find(s); temp=finding;
newnode=(node *)malloc(sizeof(node)); newnode->data=data; newnode->next=temp; newnode->prev=temp->prev;
temp->prev=newnode; newnode->prev->next=newnode;
for(j=0;j*sqrtn<n;j++) if(j*sqrtn>=s) front[j]=front[j]->prev;
}else{
scanf("%d\n",&a); a--;
find(a);
printf("%c\n",finding->data);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |