Reference: http://blog.csdn.net/htt_h/article/details/44862813
Test instructions
Give you a string of no more than 1e6, and no more than 2000 operations
The operations are divided into two types:
1. Insert a character in front of a position
2. Ask the character of the current position
Ideas:
Learned a block array, is to divide 1e6 of the original string into 1E3 parts, each part of the same length,
Since the operation does not exceed 2000 times, the length of each part will not exceed 3e3,
You can open a 1e3*3e3 character array to store the string, open a 1e3 length array to record the length of each part
This allows you to complete the insert and find operations in a relatively short period of time
/************************************************author:d evil*********************************************** * */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespaceStd;typedefLong LongLL;Const intinf=0x3f3f3f3f;Const intmod=1e9+7;Const intn=1e3+Ten;Chars[n*n],eg[n][n*3],inch[2];intl[n],n,m,x;voidAddCharChintx) { intNl=0, PN; for(intI=0; i<n;i++) { if(nl+l[i]>=x) {pn=i; Break;} if(i==n-1) {pn=n-1; Break;} NL+=L[i]; } intP=min (l[pn],x-nl-1); for(inti=l[pn];i>p;i--) eg[pn][i]=eg[pn][i-1]; EG[PN][P]=ch; L[PN]++;}CharQueryintx) { intNl=0; for(intI=0; i<n;i++) { if(nl+l[i]>=x)returneg[i][x-nl-1]; NL+=L[i]; }}intMain () {//freopen ("In.txt", "R", stdin); while(~SCANF ("%s", s)) { intlen=strlen (s); intAve= (len+999)/ +; N= (len-1)/ave+1; for(intI=0; i<n;i++) l[i]=Ave; for(intI=0; i<len;i++) eg[i/ave][i%ave]=S[i]; L[n-1]= (len-1)%ave+1; scanf ("%d",&m); while(m--) {scanf ("%s",inch); if(inch[0]=='Q') {scanf ("%d",&x); printf ("%c\n", query (x)); } Else{scanf ("%s%d",inch,&x); Add (inch[0],x); } } } return 0;}
POJ2887 Big String (block array)