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

  一开始只考虑字符串中字符'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. extjs MVC模式的个人看法

    针对一个后台管理页面是mvc模式,后台也是mvc模式下的项目,要怎么去熟悉呢? 首先以我个人的认解,先从后台的管理界面来看,会有control,model,store,view:其中先看view的代码 ...

  2. 通过nginx配置文件抵御攻击

    通过nginx配置文件抵御攻击 囧思九千 · 2013/11/12 12:22 0x00 前言 大家好,我们是OpenCDN团队的Twwy.这次我们来讲讲如何通过简单的配置文件来实现nginx防御攻击 ...

  3. Visual Mingw

    Visual-MinGW 是一个专门为MinGW所设计的IDE.如果,你曾经用过VC++ 6.0这个IDE,你的第一感觉就是,Visual-MinGW和VC++ 6.0非常相似.所以,对于曾经用惯VC ...

  4. 规则html表单对象赋值

    function grid_load_callback(data, status) {            if (data.rows.length > 0)            {     ...

  5. WCF 无法激活服务,因为它不支持 ASP.NET 兼容性。已为此应用程序启用了 ASP.NET 兼容性

    无法激活服务,因为它不支持 ASP.NET 兼容性.已为此应用程序启用了 ASP.NET 兼容性.请在 web.config 中关闭 ASP.NET 兼容性模式,或将 AspNetCompatibil ...

  6. Android Handler简单示例

    package com.firstapp.foo.firstapp; import android.os.Handler; import android.os.Message; import andr ...

  7. [LeetCode]题解(python):047-Permutations II

    题目来源 https://leetcode.com/problems/permutations-ii/ Given a collection of numbers that might contain ...

  8. .Net 文件名补位

    文件以name-1.pdf.name-2.pdf.name-3.pdf......name-80.pdf命名,传到数据库中排序混乱:1之后为10,2之后是20,所以要把文件名中的数字补位变成相同位数, ...

  9. iOS:FFmpeg视频播放和直播框架

    视频直播和播放转码器框架 介绍: FFmpeg是一套可以用来记录.转换数字音频.视频,并能将其转化为流的开源计算机程序.采用LGPL或GPL许可证. 它提供了录制.转换以及流化音视频的完整解决方案.它 ...

  10. xp系统的安装SVN

    xp系统安装SVN,出现错误: 解决办法: 1,首先确定xp体统是否为sp3,SVN安装需要在sp3以上: 2,检查windows Installer是否开启,解决:控制面板-管理工具-服务—wind ...