AC 250, tried atcoder virtual contest, wasn't even half bad
This commit is contained in:
51
atcoder/beginner_contests/250/c.cpp
Normal file
51
atcoder/beginner_contests/250/c.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
int n, q;
|
||||
cin >> n >> q;
|
||||
|
||||
// Denoting what ball is on the ith position
|
||||
vector<int> numberBall(n);
|
||||
// Denoting where the ith ball is
|
||||
vector<int> ballPosition(n);
|
||||
|
||||
for(int i = 0; i < n; ++i){
|
||||
numberBall[i] = i;
|
||||
ballPosition[i] = i;
|
||||
}
|
||||
|
||||
for(int j = 0; j < q; ++j){
|
||||
int xq;
|
||||
cin >> xq;
|
||||
xq--;
|
||||
|
||||
int x_pos = ballPosition[xq], y_pos, yq;
|
||||
|
||||
if(x_pos != n - 1){
|
||||
y_pos = x_pos + 1;
|
||||
yq = numberBall[y_pos];
|
||||
|
||||
swap(numberBall[x_pos], numberBall[y_pos]);
|
||||
swap(ballPosition[xq], ballPosition[yq]);
|
||||
} else{
|
||||
y_pos = x_pos - 1;
|
||||
yq = numberBall[y_pos];
|
||||
|
||||
swap(numberBall[x_pos], numberBall[y_pos]);
|
||||
swap(ballPosition[xq], ballPosition[yq]);
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < n; ++i){
|
||||
cout << numberBall[i] + 1 << " ";
|
||||
} cout << endl;
|
||||
|
||||
cout << flush;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user