fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int Max = 2e5;
  5. int num[Max+1];
  6. int pos[Max+1];
  7. int main()
  8. {
  9. int N,X;
  10. cin >> N >> X;
  11. for(int i=1;i<=N;i++)
  12. {
  13. num[i]=i;
  14. pos[i]=i;
  15. }
  16. for(int j=0;j<X;j++)
  17. {
  18. int A,nxt;
  19. cin >> A;
  20. if(pos[A]<N)
  21. {
  22. nxt=num[pos[A]+1];
  23. swap(num[pos[A]+1],num[pos[A]]);
  24. swap(pos[A],pos[nxt]);
  25. }
  26. else
  27. {
  28. nxt=num[pos[A]-1];
  29. swap(num[pos[A]-1],num[pos[A]]);
  30. swap(pos[A],pos[nxt]);
  31. }
  32. for(int i=1;i<=N;i++)
  33. cout << num[i] << ' ';
  34. cout << '\n';
  35. for(int i=1;i<=N;i++)
  36. cout << pos[i] << ' ';
  37. cout << '\n';
  38. }
  39. for(int i=1;i<=N;i++)
  40. cout << num[i] << ' ';
  41. }
Success #stdin #stdout 0.01s 5548KB
stdin
10 6
1
5
2
9
6
6
stdout
2 1 3 4 5 6 7 8 9 10 
2 1 3 4 5 6 7 8 9 10 
2 1 3 4 6 5 7 8 9 10 
2 1 3 4 6 5 7 8 9 10 
1 2 3 4 6 5 7 8 9 10 
1 2 3 4 6 5 7 8 9 10 
1 2 3 4 6 5 7 8 10 9 
1 2 3 4 6 5 7 8 10 9 
1 2 3 4 5 6 7 8 10 9 
1 2 3 4 5 6 7 8 10 9 
1 2 3 4 5 7 6 8 10 9 
1 2 3 4 5 7 6 8 10 9 
1 2 3 4 5 7 6 8 10 9