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. ...
随机推荐
- 一次性搞清楚equals和hashCode
前言 在程序设计中,有很多的“公约”,遵守约定去实现你的代码,会让你避开很多坑,这些公约是前人总结出来的设计规范. Object类是Java中的万类之祖,其中,equals和hashCode是2个非常 ...
- hbase与mapreduce集成
一:运行给定的案例 1.获取jar包里的方法 2.运行hbase自带的mapreduce程序 lib/hbase-server-0.98.6-hadoop2.jar 3.具体运行 4.运行一个小方法 ...
- JavaScript函数小结
JS基础知识 /********************** 1:基础知识 1 创建脚本块 1: <script language=”JavaScript”> 2: JavaScript ...
- EF扩展库(批量操作)
EF删除和修改数据只能先从数据库取出,然后再进行删除 delete from Table1 where Id>5; update Table1 set Age=10; 我们需要这样操作 //删除 ...
- VLC说明
一.简介 vlc的全名是Video Lan Client,是一个开源的.跨平台的视频播放器.VLC支持大量的音视频传输.封装和编码格式,完整的功能特性列表可以在这里获得http://www.video ...
- [LeetCode]题解(python):086 - Partition List
题目来源 https://leetcode.com/problems/partition-list/ Given a linked list and a value x, partition it s ...
- hexo 搭建博客
使用hexo搭建网站.记录一下. hexo搭建方法: https://wsgzao.github.io/post/hexo-guide/ http://jacob110.github.io/2015/ ...
- Xcode编译WebApps找不到js的错误解决办法<转>
使用Xcode做WebApps时,使用UIWebview来调用一个页面,有时会遇到问题,其一就是编译的时候出现黄色感叹号的Warning,js文件都报错:warning: no rule to pro ...
- 打印出1,11,21,31,41。。。。。。的shell脚本
打印出1,11,21,31,41......的shell脚本 方法一:#!/bin/bash ;i<;i=i+));do echo $i #cat -n /etc/services | sed ...
- 计算机管理打不开的解决方法,直接cmd修改reg
复制命令即可: reg add HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\she ...