zoukankan      html  css  js  c++  java
  • 【题解】P3391 文艺平衡树

    用pb_ds库中的rope水过去的,忽然发现这玩意能水好多模拟题。

    详见这个博客:背景的小姐姐真的好看

    • 声明
     #include <ext/rope>
    
     using namespace __gnu_cxx;
    
    • 使用
    rope<类型>a
    
    a.size()
    a.length()
    a.substr(pos,x)从pos开始提取x个
    a.push_back(x);
    a.insert(pos,x);在pos插入x,自然支持整个char数组的一次插入
    a.erase(pos,x);从pos开始删除x个
    a.copy(pos,len,x);从pos开始到pos+len为止用x代替
    a.replace(pos,x);从pos开始换成x
    

    访问可直接用数组下标,非常方便


    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
    #include <ext/rope>
    #include <iostream>
    using namespace std;
    using namespace __gnu_cxx;
    int read()
    {
    	int x=0;char ch;short int neg=0;ch=getchar();
    	while(!isdigit(ch)){
    		neg|=(ch=='-');ch=getchar();
    	}
    	while(isdigit(ch)){
    		x=x*10+ch-48;ch=getchar();
    	}
    	return neg?-x:x;
    }
    int n,m;
    int l,r;
    rope<int>a,b,tmp;
    int main()
    {
      int len;
      cin>>n>>m;
      for(int i=0;i<n;i++)
      {
      	a.push_back(i+1);b.push_back(n-i);//a[i]=i;b[i]=n-i+1;
      }
      while(m--)
      {
        l=read();r=read();
        l--,r--;
        int x=r-l+1;
        tmp=a.substr(l,r-l+1);
        a=a.substr(0,l)+b.substr(n-r-1,r-l+1)+a.substr(r+1,n-r-1);
        b=b.substr(0,n-r-1)+tmp+b.substr(n-l,l);
      }
      for(register int i=0;i<n;i++)cout<<a[i]<<' ';
      return 0;
    }
    
  • 相关阅读:
    WebFrom 复杂控件
    WebFrom 简单控件
    WinForm开发控件集合
    ListView 控件操作
    窗体类型
    WEBFORM--第一讲
    display:inline/block/inline-block
    WINFORM--第五讲(窗体类型)
    WINFORM--第四讲(布局)
    WINFORM--第三讲(下拉列表)
  • 原文地址:https://www.cnblogs.com/Rye-Catcher/p/8467071.html
Copyright © 2011-2022 走看看