题解:
双向链表模拟即可
代码:
/*
* @Author : Nightmare
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define PII pair<int,int>
#define ls 2 * rt
#define rs 2 * rt + 1
#define gcd(a,b) __gcd(a,b)
#define eps 1e-6
#define lowbit(x) (x&(-x))
#define N 10005
#define M 10005
#define mod 1000000007
#define inf 0x3f3f3f3f
int n, m, l[N], r[N];
void solve(){
scanf("%d %d", &n, &m);
for(int i = 1 ; i <= n ; i ++) l[i] = i - 1, r[i] = i + 1;
l[1] = n; r[n] = 1;
while(m --){
int opt, x, y; scanf("%d", &opt);
if(opt == 1){
scanf("%d %d", &x, &y);
l[r[x]] = l[x];
r[l[x]] = r[x];
l[r[y]] = x;
r[x] = r[y];
l[x] = y;
r[y] = x;
}else if(opt == 2){
scanf("%d %d", &x, &y);
l[r[x]] = l[x];
r[l[x]] = r[x];
r[l[y]] = x;
r[x] = y;
l[x] = l[y];
l[y] = x;
}else if(opt == 3){
for(int i = 1 ; i <= n ; i ++) swap(l[i], r[i]);
}else if(opt == 4){
int cur = 1;
while(r[cur] != 1) printf("%d ", cur), cur = r[cur];
printf("%d\n", cur);
}
}
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("D:\\in.txt", "r", stdin);
#endif
solve();
#ifndef ONLINE_JUDGE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}