Skip to content

Instantly share code, notes, and snippets.

@veigavitor
Created February 6, 2023 23:00
Show Gist options
  • Save veigavitor/28f10131fd8e15efbce7a54f88e5e7ca to your computer and use it in GitHub Desktop.
Save veigavitor/28f10131fd8e15efbce7a54f88e5e7ca to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// lemos a entrada
int n, p, q, r, s;
cin >> n >> p >> q >> r >> s;
vector<int> v(n+1);
for(int i = 1; i <= n; i++) {
cin >> v[i];
}
// realizamos a troca dos termos do intervalo pq utilizando o swap
for(int i = p; i <= q; i++) {
swap(v[i], v[i+(r-p)]);
}
// printamos o vetor final
for(int i = 1; i <= n; i++) {
cout << v[i] << " ";
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment