rope 玄三关求条
查看原帖
rope 玄三关求条
994729
Epitome楼主2025/1/16 09:28
#include <iostream>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_cxx;

int n, m;

rope<int> rp1, rp2;

void update( int l, int r ) {
  --l, --r; int le = r - l + 1;
  rope<int> tmp(rp1.substr(l, le));
  rope<int> now(rp2.substr(n - r - 1, le));
  rp1 = rp1.substr(0, l) + rp2.substr(n - r - 1, le) + rp1.substr(r + 1, n - r);
  rp2 = rp2.substr(0, n - r - 1) + tmp;
}

int main() {
  ios :: sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    rp1.push_back(i);
    rp2.push_back(n - i + 1);
  }
  for (int l, r; m--; ) {
    cin >> l >> r;
    update(l, r);
  }
  for (auto i : rp1) {
    cout << i << " ";
  }
  return 0;
}
2025/1/16 09:28
加载中...