rope可以持久化操作,平衡树的结构,每一次都复制的是根节点,\(O(1)\)的复制历史版本
rope模板
rope维护历史版本
rope的各种操作
可持久化模板
可持久化数组
MLE的代码
一直在最后一个点MLE,即使改成指针也不行。但是可以看到这个数据结构的好处,代码十分的简短
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
| #include <bits/stdc++.h> #include <ext/rope> using namespace std; using namespace __gnu_cxx; int n, m; const int maxn = 1e6+10; rope<int> *his[maxn]; int main(){ while(~scanf("%d%d", &n, &m)){ his[0]=new rope<int>(); int temp; for(int i=0; i<n; i++){ scanf("%d", &temp); his[0]->append(temp); } int ver, ty, loc, val; for(int i=0; i<m; i++){ scanf("%d%d", &ver, &ty); his[i+1] = new rope<int>(*his[ver]); if(ty == 1){ scanf("%d%d", &loc, &val); his[i+1]->replace(loc-1, val); } else{ scanf("%d", &loc); printf("%d\n", his[i+1]->at(loc-1)); } } } return 0; }
|
未解决的问题