【Rope】洛谷 P3391 【模板】文艺平衡树
2021-03-29 20:08:00 # ACM

题链

用的是 $STL$ $rope$

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> //用 tree
#include<ext/pb_ds/hash_policy.hpp> //用 hash
#include<ext/pb_ds/trie_policy.hpp> //用 trie 字典树
#include<ext/pb_ds/priority_queue.hpp> //用 priority_queue
using namespace __gnu_pbds;
#include<ext/rope>
using namespace __gnu_cxx;


#define Combine Pair, greater<Pair>, pairing_heap_tag
#define LL long long
#define ll long long
#define Pair pair<double,LL>
#define ULL unsigned long long
#define ls rt<<1
#define rs rt<<1|1
#define one first
#define two second
#define MS 1000009
#define INF 1e9
#define DBINF 1e100
#define Pi acos(-1.0)
#define eps 1e-9
#define mod 99999997
#define mod1 39989
#define mod2 1000000000

int n,m;
rope<int> rp[3];

int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for(int i=1;i<=n;i++){
rp[0].push_back(i);
rp[1].push_front(i);
}
while(m--){
int l,r;
cin >> l >> r;
rp[2] = rp[0];
rp[0].replace(l-1,r-l+1,rp[1].substr(n-r,r-l+1));
rp[1].replace(n-r,r-l+1,rp[2].substr(l-1,r-l+1));
}
for(int i=0;i<rp[0].size();i++){
cout << rp[0][i] << " ";
}
cout << "\n";


return 0;
}
Prev
2021-03-29 20:08:00 # ACM
Next