https://www.nowcoder.com/acm/contest/141#question
之所以补这题,是因为第一次使用rope,这是一个可持久化平衡树。
不过本题没有用到可持久化就是了,平衡树的split和merge。
#include <ext/rope>
using namespace __gnu_cxx;
下标从0开始,不可以cin,可以cout
由于rope的底层实现,insert,erase,get都是logn的
reverse是O(n)的,所以构造两个rope来做
push_back(x) 在末尾添加x
insert(pos,x) 在pos插入x
erase(pos,x) 从pos开始删除x个
replace(pos,x) 从pos开始换成x
substr(pos,x) 提取pos开始x个
at(x)/[x] 访问第x个元素
rope<int>*his[maxn], his[i]=new rope<char>(*his[i-1]) 可持久化数组
#define others
#ifdef poj
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#endif // poj
#ifdef others
#include <bits/stdc++.h>
#include <ext/rope>
#endif // others
//#define file
#define all(x) x.begin(), x.end()
using namespace std;
using namespace __gnu_cxx;
#define eps 1e-8
const double pi = acos(-1.0);
typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
void umax(int &a, int b) {
a = max(a, b);
}
void umin(int &a, int b) {
a = min(a, b);
}
int dcmp(double x) {
return fabs(x) <= eps?0:(x > 0?1:-1);
}
void file() {
freopen("data_in.txt", "r", stdin);
freopen("data_out.txt", "w", stdout);
}
const LL mod = 1e9+7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
namespace solver {
/*
#include <ext/rope>
using namespace __gnu_cxx;
下标从0开始,不可以cin,可以cout
*/
void solve() {
rope<int> str;
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
str.push_back(i);
}
for (int i = 1; i <= m; i++) {
int l, r;
cin >> l >> r;
l --;
str = str.substr(l, r) + str.substr(0, l) + str.substr(l + r, n - (l + r) + 1);
}
for (int i = 0; i < str.size(); i++)
printf("%d%c", str[i], i == str.size() - 1?'\n':' ');
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
// file();
solver::solve();
return 0;
}
/*
1,2,4,6,9,13,17,21,26,32,38,45,53,61,69,77,86,96,106,117,129,141,153,166,180,194,209,225,241,257,273,
*/