当前位置: 代码迷 >> 综合 >> 小A的题(线段树)
  详细解决方案

小A的题(线段树)

热度:56   发布时间:2024-01-19 07:45:28.0

描述

由于小 A 实在是太菜了,因此他现在需要你的帮助: 现在小 A 手上有一个凌乱的 01 串,他想通过若干次对于这个 01 串的局部排序将它变成一个有趣的 01 序列。 现在有两种操作:

输入格式

  1. l r 0 表示把区间 [l,r][l,r] 给升序排序

  2. l rr1 表示把区间 [l,r][l,r] 给降序排序

然后小 A 这个菜鸡想知道在 m 次操作之后序列长啥样。

输出格式

第一行一个 0101 串 S。 第二行一个整数 m。 接下来 m 行每行三个整数 l,r,x,   x=0,1中的一个。

m 次操作之后的 01 串

数据范围

∣S∣≤1000000,m≤500000

输出时每行末尾的多余空格,不影响答案正确性

样例输入

11001
1
2 4 0

样例输出

10011

 

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cstdio>
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=1000100;
int a[maxn];
int sum[maxn*4];
int Add[maxn*4];
char str[maxn];
  相关解决方案