题目大意就是给一个字符串,然后多个操作,每次操作可以把每一段区间的字符进行升序或者降序排序,问最终的字符串是多少。

  一开始只考虑字符串中字符'a'的情况,假设操作区间[L,R]中有x个'a',那么一次操作后,这x个'a'要么去最左(升序),要么去最右(降序),我们可以建立一颗线段树来维护这样的操作,字符'a'出现的位置值为1,否则为0,那么q次操作后,最后值为1的地方填的就是'a'了。

  在考虑字符'a'和'b'的情况,操作的情况和上面类似,字符'a'和'b'出现的位置值为1,否则为0,q次操作后,如果一个位置的值为1,并且该位置没有填写'a',那么这个位置就填写'b'。接下来的情况以此类推,一直做到z,复杂度O(26*qlogn)。

  

 #include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<vector>
#include<cmath>
#include<iostream>
#include<string>
#define N 1000010
#define M 1010
#define P 1000000007
using namespace std;
int v[N],s[N],l[N],r[N],tt;
int L[N],R[N],typ[N],n,q,i,j,tmp,ans[N];
string str;
void build(int x,int a,int b)
{
int m;
l[x]=a;r[x]=b;
if (x>tt) tt=x;
if (b-a>)
{
m=(a+b)>>;
build(*x,a,m);
build(*x+,m,b);
}
v[x]=-;
}
void clean(int x)
{
if (v[x]!=-)
{
s[x]=(r[x]-l[x])*v[x];
if (*x<=tt) v[*x]=v[x];
if (*x+<=tt) v[*x+]=v[x];
v[x]=-;
}
}
void change(int x,int a,int b,int c)
{
int m;
clean(x);
if ((a<=l[x])&&(r[x]<=b))
{
v[x]=c;
return;
}
m=(l[x]+r[x])>>;
if (a<m) change(*x,a,b,c);
if (m<b) change(*x+,a,b,c);
clean(*x);clean(*x+);
s[x]=s[*x]+s[*x+];
}
int query(int x,int a,int b)
{
int m,ans=;
clean(x);
if ((a<=l[x])&&(r[x]<=b))
return s[x];
m=(l[x]+r[x])>>;
if (a<m) ans+=query(*x,a,b);
if (m<b) ans+=query(*x+,a,b);
return ans;
}
int main()
{
cin>>n>>q;
cin>>str;
build(,,n);
for (i=;i<=q;i++)
cin>>L[i]>>R[i]>>typ[i]; for (j=;j<=;j++)
{
change(,,n,);
for (i=;i<n;i++)
if (str[i]-<=j)
change(,i,i+,);
for (i=;i<=q;i++)
{
tmp=query(,L[i]-,R[i]);
change(,L[i]-,R[i],);
if (tmp)
{
if (typ[i]==)
change(,R[i]-tmp,R[i],);
else
change(,L[i]-,L[i]-+tmp,);
}
} for (i=;i<=n;i++)
if ((query(,i-,i)==)&&(ans[i]==))
ans[i]=+j;
} for (i=;i<=n;i++)
{
char ch=ans[i];
cout<<ch;
}
}

Codeforces Round #312 (Div. 2) E. A Simple Task的更多相关文章

  1. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树

    E. A Simple Task 题目连接: http://www.codeforces.com/contest/558/problem/E Description This task is very ...

  2. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树+计数排序

    题目链接: http://codeforces.com/problemset/problem/558/E E. A Simple Task time limit per test5 secondsme ...

  3. Codeforces Round #312 (Div. 2) E. A Simple Task 线段树 延时标记

    E. A Simple Task time limit per test5 seconds memory limit per test512 megabytes inputstandard input ...

  4. Codeforces Round #312 (Div. 2)

    好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价 ...

  5. Codeforces Round #312 (Div. 2) C. Amr and Chemistry 暴力

    C. Amr and Chemistry Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/558/ ...

  6. Codeforces Round #312 (Div. 2)B. Amr and The Large Array 暴力

    B. Amr and The Large Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  7. Codeforces Round #312 (Div. 2) A. Lala Land and Apple Trees 暴力

    A. Lala Land and Apple Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/cont ...

  8. Codeforces Round #312 (Div. 2) C.Amr and Chemistry

    Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experime ...

  9. Codeforces Round #312 (Div. 2) B.Amr and The Large Array

    Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. ...

随机推荐

  1. Python 链接Mysql数据库

    参考链接:https://pypi.python.org/pypi/PyMySQL#downloads import pymysql.cursors,xml.dom.minidom # Connect ...

  2. IdTcpClient简单示例

    procedure TForm1.btnHttpGetClick(Sender: TObject); begin idtcpclnt1.Host := '192.168.10.88'; idtcpcl ...

  3. 设计模式:迭代器模式(Iterator)

    定  义:提供一种方法顺序访问一个集合对象中的各个元素,而又不暴露该对象的内部元素. C#中实现,foreach 遍历

  4. UML时序图总结

    前言 在我的工作中,用的最多的就是时序图了.可能由于工作的原因,我也是最喜欢画时序图了,很清楚,很明了,什么时候发送什么消息,到达什么状态,一下子就展示在你的脑海里,对于消息驱动的程序来说,是再好不过 ...

  5. 1011 最大公约数GCD

    1011 最大公约数GCD 基准时间限制:1 秒 空间限制:131072 KB 输入2个正整数A,B,求A与B的最大公约数. Input 2个数A,B,中间用空格隔开.(1<= A,B < ...

  6. 玩儿了一下django User authentication

    五一在家,VPN不能链接了,而项目在本地run的过程中,又需要链接公司的SSO server才能login.下雨,不想去公司,又不得不在家做task,只能想办法避开SSO login,以前知道djan ...

  7. UItableView自定义标题(headerView)重用问题

    在实现类似QQ列表的功能时,这样自定义了一个标题headerView 在实现类似QQ列表的功能时,这样自定义了一个标题headerView - (UIView *)tableView:(UITable ...

  8. ExtractTablesFromSQL

    public static string[] ExtractTablesFromSQL(string cmdString) { return Regex.Matches(cmdString, @&qu ...

  9. cocoapods没有自动补齐

    在install cocoapods成功之后,输入头文件名的时候,没有提示,这样,我还以为是我的cocoapods安装出错了.原来是配置没有配置好. 解决办法: 选择工程的 Target -> ...

  10. Java实现热替换

    package test; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.nio. ...