Codeforces Round #312 (Div. 2) E. A Simple Task
题目大意就是给一个字符串,然后多个操作,每次操作可以把每一段区间的字符进行升序或者降序排序,问最终的字符串是多少。
一开始只考虑字符串中字符'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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #312 (Div. 2)
好吧,再一次被水题虐了. A. Lala Land and Apple Trees 敲码小技巧:故意添加两个苹果树(-1000000000, 0)和(1000000000, 0)(前者是位置,后者是价 ...
- 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/ ...
- 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 ...
- 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 ...
- Codeforces Round #312 (Div. 2) C.Amr and Chemistry
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experime ...
- 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. ...
随机推荐
- phpcms v9模版调用代码大全(全面而实用)
首页调用栏目 {pc:content action="category" siteid="$siteid" num="15" order=& ...
- wampserver
- docker learning
Docker 配置文件位置 Docker 的配置文件可以设置大部分的后台进程参数,在各个操作系统中的存放位置不一致 在 ubuntu 中的位置是:/etc/default/docker 在 cento ...
- nodejs net模块实现socket
var net = require('net'); var client = net.connect({port: 8080}, function() { console.log('连接到服务器!') ...
- hadoop 2.4 伪分布式模式
1.core-site.xml 在<configuration></configuration>中插入 <property> <name>fs.defa ...
- 执行动态sql返回参数
ref: https://support.microsoft.com/en-us/kb/262499 ) ) DECLARE @IntVariable INT ) SET @SQLString = N ...
- ASP.NET MVC 利用ActionFilterAttribute来做权限等
ActionFilterAttribute是Action过滤类,该属于会在执行一个action之前先执行.而ActionFilterAttribute是 MVC的一个专门处理action过滤的类.基于 ...
- 关于使用UDP(TCP)跨局域网,NAT穿透的心得
前言: 最近我用java做了一个C/S的类似QQ之类的IM系统(即时通讯系统),遇到了不能跨局域网通讯的问题,经过在网上,和书上查阅了一些资料,了解了一些情况,现在就总结一下我的解决方案 ...
- block iOS 块
block 是个很陌生的东西啊.以前没有学会,现在再看它,还是觉得很稀奇古怪. 无奈,之后硬着头皮学了.. //有参返回值 格式: 返回值类型 (^变量名)(参数类型及个数) = ^(形参列表){ 代 ...
- activity传值到fragment
1,初始化fragment时候: @Override public void onAttach(Activity activity) { /** 注册广播 */ initBroadcast(); s ...