题目链接


题目大意:

就是每次把牌堆中若干个连续的牌放到堆顶,问你最后牌的序列。


解题思路:

Splay 区间翻转的模板题:
对于一个区间[1,2,3,4,5,6,7,8][1,2,3,4,5,6,7,8][1,2,3,4,5,6,7,8]
你要把[3,4,5][3,4,5][3,4,5]拿到前面去

  1. 我们可以这么搞先把[1−5][1-5][1−5]翻转·一下
    [5,4,3,2,1,6,7,8][5,4,3,2,1,6,7,8][5,4,3,2,1,6,7,8]
  2. 然后我们发现只要把[5,4,3][5,4,3][5,4,3]和[2,1][2,1][2,1]再翻转一遍就好了
    [3,4,5,1,2,6,7,8][3,4,5,1,2,6,7,8][3,4,5,1,2,6,7,8]

AC code

#include <bits/stdc++.h>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define log2(a) log(a)/log(2)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x7fffffff
#define LLF 0x3f3f3f3f3f3f3f3f
#define f first
#define s second
#define endl '\n'
using namespace std;
const int N = 2e6 + 10, mod = 1e9 + 9;
const int maxn = 500010;
const long double eps = 1e-5;
const int EPS = 500 * 500;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
template<typename T> void read(T &x) {x = 0;char ch = getchar();ll f = 1;while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {read(first);read(args...);
}
int n, m, arr[maxn];
struct node {#define ls(x) T[x].ch[0]#define rs(x) T[x].ch[1]#define fa(x) T[x].fa#define root T[0].ch[1]/*** 树形结构*/int fa;//父亲int ch[2];// 存储左右儿子的位置int sum;// 子树大小int val;  /*** * lazy 标记两个* */int rac;/*** 权值 最大值*/
}T[N];
void downdate(int x) {if(T[x].rac) {int &lc = T[x].ch[0], &rc = T[x].ch[1];swap(lc,rc);T[lc].rac ^= 1, T[rc].rac ^= 1;T[x].rac = 0;}
}void update(int x) {T[x].sum = T[ls(x)].sum + T[rs(x)].sum + 1;
}int ident(int x) {return T[fa(x)].ch[0] == x ? 0 : 1;}
void connect(int x, int fa, int how) {// 把x变成fa的how儿子T[fa].ch[how] = x;T[x].fa = fa;
}void rotate(int x) { // 把x转到fa位置int Y = fa(x), R = fa(Y);int YSON = ident(x), RSON = ident(Y);downdate(Y);downdate(x);connect(T[x].ch[YSON^1],Y,YSON), connect(Y,x,YSON^1), connect(x,R,RSON);update(Y);update(x);
}void splay(int x, int to) { // 把x转到to的位置to = fa(to);while(fa(x) != to) {int y = fa(x);if(T[y].fa == to) rotate(x);else if(ident(x) == ident(y)) rotate(y), rotate(x);else rotate(x), rotate(x);}
}
//.....................................................................
int find(int x) {int now = root;while (now) {downdate(now);if (x <= T[T[now].ch[0]].sum) now = T[now].ch[0];else {x -= T[T[now].ch[0]].sum + 1;if (!x) return now;now = T[now].ch[1];}}return 0;
}inline int BuildTree(int l,int r) {if(l > r) return 0;connect(BuildTree(l,mid-1),mid,0);connect(BuildTree(mid+1,r),mid,1);T[mid].val = mid;update(mid);return mid;
}void print(int now) {if(!now) return;downdate(now);if(T[now].ch[0]) print(T[now].ch[0]);if(now != 1 && now != n + 2) cout << now - 1 << " ";// cout << now << " ";if(T[now].ch[1]) print(T[now].ch[1]);
}inline void work(int l, int r) {int fl = find(l);int fr = find(r+2);splay(fl,root);splay(fr,T[root].ch[1]);T[T[fr].ch[0]].rac ^= 1;
}int main() {read(n,m);root = BuildTree(1,n+2);while(m --) {int l, r;cin >> l >> r;work(1,l+r-1);work(1,r);work(r+1,r+l-1);}print(root);return 0;
}

rope

Rope其主要是结合了链表和数组各自的优点,链表中的节点指向每个数据

块,即数组,并且记录数据的个数,然后分块查找和插入。在g++头文件中,< ext / rope >中有成型的块状链表,在using namespace

__gnu_cxx;空间中,其操作十分方便。

基本操作:
rope test;

test.push_back(x);//在末尾添加x

test.insert(pos,x);//在pos插入x

test.erase(pos,x);//从pos开始删除x个

test.copy(pos,len,x);//从pos开始到pos+len为止用x代替

test.replace(pos,x);//从pos开始换成x

test.substr(pos,x);//提取pos开始x个 x的默认值是1

test.at(x)/[x];//访问第x个元素

#include <bits/stdc++.h>
#include <ext/rope>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define log2(a) log(a)/log(2)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define LLF 0x3f3f3f3f3f3f3f3f
#define f first
#define s second
#define endl '\n'
using namespace std;
using namespace __gnu_cxx;
const int N = 2e6 + 10, mod = 1e9 + 9;
const int maxn = 500010;
const long double eps = 1e-5;
const int EPS = 500 * 500;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
template<typename T> void read(T &x) {x = 0;char ch = getchar();ll f = 1;while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {read(first);read(args...);
}int main() {IOS;int n, m;rope<int> q;cin >> n >> m;for(int i = 1; i <= n; ++ i) {q.push_back(i);}for(int i = 1; i <= m; ++ i) {int u, v;cin >> u >> v;q = q.substr(u-1,v) + q.substr(0,u-1) + q.substr(u+v-1,n-(u+v-1));}for(int i = 0; i < n; ++ i)cout << q[i] << " ";
}

Splay ---- 2018牛客多校第三场 区间翻转搞区间位移 或者 rope可持久化块状链表相关推荐

  1. 24dian(牛客多校第三场)

    24dian(牛客多校第三场) 题意: 给你n张牌,每张牌的大小为1 ~ 13,问这些牌与加减乘除任意组合(可以使用括号),且但所有的有效解在计算过程中都涉及到分数,即非整数,能否组成答案m,如果可以 ...

  2. 牛客多校第三场 B【Classical String Problem】

    牛客多校第三场 B[Classical String Problem] 链接:https://ac.nowcoder.com/acm/contest/5668/B 来源:牛客网 题目描述 Given ...

  3. 牛客多校第三场A【Clam and fish】贪心

    A[Clam and fish]贪心 链接:https://ac.nowcoder.com/acm/contest/5668/A 来源:牛客网 题目: There is a fishing game ...

  4. 2020牛客多校第三场[C Operation Love+基础计算几何 判断多边形顺逆时针]

    题目链接 题目大意:就是给你两个左右手的模型,下面给出这两只手通过平移变换之后坐标问你这只手是左手还是右手?[题目保证坐标是按照顺时针或者逆时针给出的] 解题思路:首先我们先观察一下这只右手:假如数据 ...

  5. exgcd ---- 2020牛客多校第三场:[Fraction Construction Problem:exgcd+思维题]

    题目链接 题目大意:就是给你两个数a,ba,ba,b叫你求满足下面三个条件的c,d,e,fc,d,e,fc,d,e,f 1.cd−ef=ab1.{c\over d}-{e\over f}={a\ove ...

  6. Math(牛客多校第三场)

    Math 题意: 问你有多少对(x,y),1<=x<=y<=n,满足(x2 + y2)%(xy+1) == 0 题解: 这种题...直接打表芜湖~ 通过打表发现:满足情况的为(i,i ...

  7. 2019牛客多校第三场 F.Planting Trees

    题目链接 题目链接 题解 题面上面很明显的提示了需要严格\(O(n^3)\)的算法. 先考虑一个过不了的做法,枚举右下角的\((x,y)\),然后二分矩形面积,枚举其中一边,则复杂度是\(O(n^3 ...

  8. 2019 牛客多校第三场 B Crazy Binary String

    题目链接:https://ac.nowcoder.com/acm/contest/883/B 题目大意 给定一个长度为 N 的 01 字符串,输出最长子串和子序列的长度,满足其中 0 和 1 的个数相 ...

  9. 2022年牛客多校第三场补题记录

    A Ancestor 题意:给出两棵 nnn 个节点的树 A,BA,BA,B,A,BA,BA,B 树上每个节点均有一个权值,给出 kkk 个关键点的编号 x1,x2,⋯,xkx_1, x_2, \cd ...

最新文章

  1. gc日志一般关注什么_GC日志说明
  2. 深入理解Python生成器(Generator)
  3. [原创] 域模式下的ASP.NET 发邮件代码
  4. 怎样将图片转换成word文字
  5. hang计算机术语大全,行业英语学习
  6. 推荐10个国外的开源免费的.NET CMS系统
  7. 2022年最佳WordPress企业主题
  8. AI仿生:人类进化新可能
  9. KVM虚拟机如何新增一块磁盘?
  10. 2022-2028全球人造黄油结晶器行业调研及趋势分析报告
  11. 2021-08-05SpringCloud升级之路2020.0.x版-5.所有项目的parent与spring-framework-common说明
  12. kotlin的必修之路
  13. 关于打破思维的墙读后感
  14. 怎么写实验论文的结果和分析
  15. Unity ShaderGraph 负片效果
  16. opencv人脸识别之让电脑分清吴彦祖和彭于晏 (LBPH)
  17. 删除u盘插拔记录linux,Linux清除U盘(USB)使用记录
  18. 基于UDP的P2P聊天工具——0.2
  19. 分享链接 - 学习/实践
  20. NLP自然语言处理实战(三):词频背后的语义--4.隐性狄利克雷分布(LDiA)

热门文章

  1. Linux:命令执行控制与||
  2. 难以置信的目标检测小妙招:多训练几个epochs,平均一下就能获得更好的模型...
  3. HDU 4826 Labyrinth(DP解法)
  4. 【云计算】云上建站快速入门:博客、论坛、CMS、电子商务网站统统
  5. mysql存储、function、触发器等实例
  6. python基础(四)集合
  7. 【Redis学习笔记】2018-05-30 Redis源码学习之Ziplist、Server
  8. 用简单的C语言实现多任务轮流切换(模拟操作系统线程机制)【转】
  9. Maven项目下HttpServletRequest 或 HttpServletResponse需引用的依赖包
  10. [Python]urllib库的简单应用-实现北航宿舍自动上网