F-项链

数组模拟双向循环链表 然后开始。。。模拟 opt1和opt2 opt1 opt2 应该可以合起来写一个操作,,我试了 不知道为啥wa了

双向循环链表。。。
然后用k表示操作三次数 如果k 为偶数 就是next输出 否则 prev输出
并且在opt操作的时候注意k的奇偶性,,,具体看代码 挺详细的应该

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ri register int
#define rll register long long
#define fp(i,a,b) for(int i=a;i<=b;++i)
#define IOS std::ios::sync_with_stdio(false)
#define L(a) a<<1
#define R(a) a<<1|1
#define P pair<int,int>
#define pii pair<ll,ll>
#define re(x) read(x)
#define lowbit(x) ((x)&-(x))
#define all(x) (x).begin(),(x).end()
#define Pi 3.1415926
#define rg register
#define gcd(x,y) __gcd(x,y)
#define unq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define mem(x,k) memset(x,k,sizeof x)

// #define TIME


template<typename T>
inline void read(T& t) {
    t = 0; int f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }while (isdigit(ch)) { t = t * 10 + ch - '0'; ch = getchar(); }t *= f;
}

namespace my{

    void TEST() { cout << "OK!!!" << endl; }
    template<typename T>
    void Check(T a[],int n){
        for(int i=1;i<=n;i++) cout<<a[i]<<" ";
        cout<<endl;
    }
    template<typename T>
    void printans(T a[],int n){
        for(int i=1;i<=n;i++) cout<<a[i]<<" ";
        cout<<endl;
    }

}

const int dx[8]={0,1,0,-1,1,-1,1,-1};
const int dy[8]={1,0,-1,0,-1,1,1,-1};

const int inf = 0x3f3f3f3f;
const ll mod=1e9+7;
//const ll inf=9e18;

const double eps = 1e-5;
const int maxn = 1e5+10;


struct node{
    int next;
    int prev;
}p[maxn];
// stack<int> s;
void opt1(int x,int y){
    // if(p[x].next==y) return;

    p[p[x].next].prev=p[x].prev;
    p[p[x].prev].next=p[x].next;
    p[p[y].next].prev=x;
    p[x].next=p[y].next;
    p[x].prev=y;
    p[y].next=x;
}
void opt2(int x,int y){
    // if(p[y].next==x) return;
    // if(x==head) head=p[x].next;
    // if(y==head) head=x;
    // if(x==tail) tail=p[x].prev;
    p[p[x].next].prev=p[x].prev;
    p[p[x].prev].next=p[x].next;
    p[p[y].prev].next=x;
    p[x].prev=p[y].prev;
    p[y].prev=x;
    p[x].next=y;
}

int main() {
    // freopen("1.in", "r", stdin);
    // freopen("ans.out", "w", stdout);  
#ifdef TIME
    clock_t start = clock();
#endif
//------------------------------------------------------------------------------------------------
    int n,m;
    re(n);re(m);
    fp(i,1,n-1) p[i].next=i+1;
    for(int i=n;i>1;i--) p[i].prev=i-1;
    p[1].prev=n;
    p[n].next=1;//双向循环链表的建立
    int k=0;
    while(m--){
        int opt;
        re(opt);
        if(opt==1){
            int x,y;
            re(x);re(y);
            if(k%2==0) opt1(x,y);
            else opt2(x,y);
        }
        else if(opt==2){
            int x,y;
            re(x);re(y);
            if(k%2==0) opt2(x,y);
            else opt1(x,y);
        }
        else if(opt==3) k++;
        else{

            if(k&1){
                int tmp=1;
                int k=0;
                while(k<n){
                    cout<<tmp<<" ";
                    k++;
                    tmp=p[tmp].prev;
                }

            }
            else{
                int tmp=1;
                int k=0;
                while(k<n){
                    cout<<tmp<<" ";
                    tmp=p[tmp].next;
                    k++;
                }
            }
            cout<<endl;
        }
    }
//-----------------------------------------------------------------------------------------------
#ifdef TIME
    clock_t end = clock();
    cout << "Runing Time: " << (double)(end - start) / CLOCKS_PER_SEC * 1000 << "ms" << endl;
#endif     
    return 0;
}