B. Pasha and String
The topic is simple, that is, the string from one position to another position between the fragments in reverse order, the basic idea is to use swap 22 exchange. At this point the problem is the time limit exceeded, 22 exchange too time-consuming, because there is exchange in the past and exchange back to the equivalent of no change in exchange wasted time, there is no better way? Because the upside is the middle number, so you can count the number of times each letter in the fragment is reversed, if it is odd several times, then the number of times will not be exchanged. There is also a place to note, because the topic is prompted, each time the AI is less than or equal to One-second times the length of the string, so the statistical reversal of the number of times the loop variable to reach half the length of the string. Because it is a fragment, the characters in the middle of the fragment are reversed, so there are a[i] + + a[i-1], before there are similar statistical methods, should learn.
1#include <iostream>2#include <string>3 using namespacestd;4 inta[100005];5 intMain ()6 {7 strings;8CIN >>s;9 intLen =s.size ();Ten intm; OneCIN >>m; A for(inti =0; I < m; i++) - { - intT; theCIN >>T; -a[t]++; - } - for(inti =1; I <= Len/2; i++) +A[i] + = a[i-1]; - for(inti =0; I <= Len/2; i++) + if(A[i] &1) ASwap (s[i-1], S[len-i]); atcout << S <<Endl; - return 0; -}
Solution to the tle problem caused by violent swap