fork(1) download
  1. #include<bits/stdc++.h>
  2. #define FOR(i,a,b,k) for (ll i=a;i<=b;i+=k)
  3. #define FORD(i,a,b,k) for (ll i=a;i>=b;i-=k)
  4. #define pb(i) push_back(i)
  5. #define ll long long int
  6. #define MOD 1000000007
  7. #define lim 1e16
  8. using namespace std;
  9. ll q,a;
  10. ll head=0,m[100001]={0};
  11. string s;
  12.  
  13. void dao(ll i, ll j)
  14. {
  15. ll l=s.length();
  16.  
  17. FOR(chiso,i,j,1) swap(s[chiso-1],s[l-chiso]);
  18. }
  19.  
  20. int main()
  21. {
  22. ios_base::sync_with_stdio(false);
  23. cin.tie(NULL);cout.tie(NULL);
  24. cin>>s>>q;
  25. ll l=s.length();
  26.  
  27. FOR(i,1,q,1)
  28. {
  29. cin>>a;
  30. if(a>l/2) a=l-a+1;
  31. head=max(head,a);
  32. m[a]++;
  33. }
  34.  
  35. if(q%2==1) dao(head,l/2);
  36. q-=m[head];
  37. head--;
  38.  
  39. FORD(i,head,1,1)
  40. {
  41. if(m[i]!=0)
  42. {
  43. if(q%2==1) dao(i,head);
  44. q-=m[i];
  45. head=i-1;
  46. cout<<i<<" ";
  47. }
  48. }
  49.  
  50. cout<<s;
  51. return 0;
  52. }
Success #stdin #stdout 0s 5424KB
stdin
Standard input is empty
stdout
Standard output is empty