#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 time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2136 KB |
Output isn't correct |
2 |
Runtime error |
0 ms |
2136 KB |
SIGSEGV Segmentation fault |
3 |
Incorrect |
16 ms |
5172 KB |
Output isn't correct |
4 |
Incorrect |
98 ms |
27084 KB |
Output isn't correct |
5 |
Incorrect |
185 ms |
27084 KB |
Output isn't correct |
6 |
Incorrect |
243 ms |
30252 KB |
Output isn't correct |
7 |
Incorrect |
266 ms |
33288 KB |
Output isn't correct |
8 |
Incorrect |
131 ms |
33288 KB |
Output isn't correct |
9 |
Incorrect |
319 ms |
33288 KB |
Output isn't correct |
10 |
Incorrect |
218 ms |
33288 KB |
Output isn't correct |