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

计算机视觉与深度学习实战:以Python为工具,基于帧间差法进行视频目标检测 计算机视觉是一门研究如何使机器从数字图像或视频中提取、分析和理解有用信息的学科。它涉及图像处理、计算机图形学、人工智能等多个领域的知识。通过计算机视觉技术,我们可以实现图像的识别、分类、目标检测等功能。本文介绍了计算机视觉与深度学习的基本概念和原理,并以Python为工具,基于帧间差分法实现了视频目标检测。帧间差分法具有算法实现简单、程序设计复杂度低、对光线等场景变化不太敏感等优点,因此在实际应用中得到了广泛的应用。然而,帧间差分法也存在一些局限性,如对于缓慢移动或静止的物体检测效果不佳。 阅读详情

E. A Simple Task
题目连接:

http://www.codeforces.com/contest/558/problem/E
Description

This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing order if k = 0.

Output the final string after applying the queries.
Input

The first line will contain two integers n, q (1 ≤ n ≤ 105, 0 ≤ q ≤ 50 000), the length of the string and the number of queries respectively.

Next line contains a string S itself. It contains only lowercase English letters.

Next q lines will contain three integers each i, j, k (1 ≤ i ≤ j ≤ n, ).
Output

Output one line, the string S after applying the queries.
Sample Input

10 5
abacdabcda
7 10 0
5 8 1
1 4 0
3 6 0
7 10 1
Sample Output

cbcaaaabdd
Hint
题意

给你n个字符,一共俩操作,l到r区间升序排序,l到r降序排序

字符集26.

让你输出最后的字符样子。
题解:

考虑计数排序,我们用线段树维护计数排序就好了,这样复杂度是26*q*logn

感觉自己智商还是涨了一波……
558E - A Simple Task

In this problem we will be using counting sort. So for each query we will count the number of occurrences for each character, and then update the range like this

for(int j=x;j<=y;j++)
cnt[s[j] - ‘a’]++;
ind = 0;
for(int j=x;j<=y;j++)
{
while(cnt[ind] == 0)
ind++;
s[j] = ind + ‘a’;
cnt[ind]–;
}

But this is too slow. We want a data structure that can support the above operations in appropriate time.

Let’s make 26 segment trees each one for each character. Now for each query let’s get the count of every character in the range, and then arrange them and update each segment tree with the new values. We will have to use lazy propagation technique for updating ranges.

Time complexity: where sz is the size of the alphabet (i.e. = 26).

暂时看不懂。。。。


using namespace std;

int tree[400005][27], lazy[400005][27];
char s[100005];

void build(int i,int L,int R)
{
  if(L == R)
  {
    tree[i][s[L] - 'a'] = 1;
    for(int j=0;j<26;j++)
      lazy[i][j] = -1;
    return ;
  }
  build(i*2 + 1, L, (L + R) / 2);
  build(i*2 + 2, (L + R) / 2 + 1, R);
  for(int j=0;j<26;j++)
  {
    lazy[i][j] = -1;
    tree[i][j] = tree[i*2 + 1][j] + tree[i*2 + 2][j];
  }
}

void update(int i, int L, int R, int x, int y, int val, int j)
{
  if(lazy[i][j] != -1)
  {
    tree[i][j] = lazy[i][j] * (R - L + 1);
    if(L != R)
    {
      lazy[i*2+1][j] = lazy[i][j];
      lazy[i*2+2][j] = lazy[i][j];
    }
    lazy[i][j] = -1;
  }
  if(L >= x && R <= y)
  {
    lazy[i][j] = val;
    tree[i][j] = lazy[i][j] * (R - L + 1);
    if(L != R)
    {
      lazy[i*2+1][j] = lazy[i][j];
      lazy[i*2+2][j] = lazy[i][j];
    }
    lazy[i][j] = -1;
    return;
  }
  if(L > y || R < x)
    return;
  update(i*2 + 1, L, (L + R) / 2, x, y, val, j);
  update(i*2 + 2, (L + R) / 2 + 1, R, x, y, val, j);
  tree[i][j] = tree[i*2 + 1][j] + tree[i*2 + 2][j];
}

int query(int i, int L, int R, int x, int y, int j)
{
  if(lazy[i][j] != -1)
  {
    tree[i][j] = lazy[i][j] * (R - L + 1);
    if(L != R)
    {
      lazy[i*2+1][j] = lazy[i][j];
      lazy[i*2+2][j] = lazy[i][j];
    }
    lazy[i][j] = -1;
  }
  if(L >= x && R <= y)
    return tree[i][j];
  if(L > y || R < x)
    return 0;
  return query(i*2 + 1, L, (L + R) / 2, x, y, j) + query(i*2 + 2, (L + R) / 2 + 1, R, x, y, j);
}

void get(int i, int L, int R, int j)
{
  if(lazy[i][j] != -1)
  {
    tree[i][j] = lazy[i][j] * (R - L + 1);
    if(L != R)
    {
      lazy[i*2+1][j] = lazy[i][j];
      lazy[i*2+2][j] = lazy[i][j];
    }
    lazy[i][j] = -1;
  }
  if(!tree[i][j])
    return ;
  if(L == R)
  {
    s[L] = j + 'a';
    return;
  }
  get(i*2 + 1, L, (L + R) / 2, j);
  get(i*2 + 2, (L + R) / 2 + 1, R, j);
}

int cnt[26];

int main()
{
  //ios_base::sync_with_stdio(0);
  //freopen("test0.txt", "r", stdin);
  //freopen("lca.out", "w", stdout);
  int n, q, x, y, up;
  scanf("%d %d", &n, &q);
  scanf("%s", s);
  build(0, 0, n - 1);
  for(int i=0;i<q;i++)
  {
    scanf("%d %d %d", &x, &y, &up);
    x--, y--;
    for(int j=0;j<26;j++)
      cnt[j] = query(0, 0, n - 1, x, y, j);
    int curr = x;
    if(!up) curr = y;
    for(int j=0;j<26;j++)
    {
      if(!cnt[j]) continue;
      update(0, 0, n - 1, x, y, 0, j);
      if(up)
      {
        update(0, 0, n - 1, curr, curr + cnt[j] - 1, 1, j);
        curr+=cnt[j];
      }
      else
      {
        update(0, 0, n - 1, curr - cnt[j] + 1, curr, 1, j);
        curr-=cnt[j];
      }
    }
  }
  for(int i=0;i<26;i++)
    get(0, 0, n - 1, i);
  printf("%s", s);
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
#define lc (o<<1)
#define rc ((o<<1)|1)
#define mid ((l+r)>>1)
char s[maxn];
struct Seg
{
    char c;
    int v[maxn<<2];
    int mar[maxn<<2],add[maxn<<2];
    void up(int o){v[o]=v[lc]+v[rc];}
    void build(int o,int l,int r)
    {
        if(l==r)
        {
            v[o]=(s[l]==c);
            return;
        }
        build(lc,l,mid);
        build(rc,mid+1,r);
        up(o);
    }
    void deal_clear(int o)
    {
        mar[o]=1;
        add[o]=v[o]=0;
    }
    void deal_add(int o,int l,int r,int val)
    {
        add[o]+=val;
        v[o]+=(r-l+1)*val;
    }
    void down(int o,int l,int r)
    {
        if(mar[o])
        {
            deal_clear(lc);
            deal_clear(rc);
            mar[o]=0;
        }
        if(add[o]!=0)
        {
            deal_add(lc,l,mid,add[o]);
            deal_add(rc,mid+1,r,add[o]);
            add[o]=0;
        }
    }
    void update_add(int o,int l,int r,int y1,int y2,int val)
    {
        if(y1<=l&&y2>=r)
        {
            deal_add(o,l,r,val);
            return;
        }
        down(o,l,r);
        if(y1<=mid) update_add(lc,l,mid,y1,y2,val);
        if(y2>mid) update_add(rc,mid+1,r,y1,y2,val);
        up(o);
    }
    void update_clear(int o,int l,int r,int y1,int y2)
    {
        if(y1<=l&&y2>=r)
        {
            deal_clear(o);
            return;
        }
        down(o,l,r);
        if(y1<=mid) update_clear(lc,l,mid,y1,y2);
        if(y2>mid) update_clear(rc,mid+1,r,y1,y2);
        up(o);
    }
    int query(int o,int l,int r,int y1,int y2)
    {
        if(y1<=l&&y2>=r) return v[o];
        down(o,l,r);
        int ans=0;
        if(y1<=mid) ans+=query(lc,l,mid,y1,y2);
        if(y2>mid) ans+=query(rc,mid+1,r,y1,y2);
        return ans;
    }
    void dfs(int o,int l,int r)
    {
        if(!v[o]) return;
        if(l==r)
        {
            s[l]=c;
            return;
        }
        down(o,l,r);
        dfs(lc,l,mid); dfs(rc,mid+1,r);
    }
}sg[26];
int n,m,cnt[26];
int main()
{
    scanf("%d%d",&n,&m);
    scanf("%s",s+1);
    for(int i=0;i<26;++i)
    {
        sg[i].c='a'+i;
        sg[i].build(1,1,n);
    }
    while(m--)
    {
        int l,r,typ;
        scanf("%d%d%d",&l,&r,&typ);
        if(l==r) continue;
        for(int i=0;i<26;++i) cnt[i]=sg[i].query(1,1,n,l,r);
        int now=l;
        if(typ)
        {
            for(int i=0;i<26;++i)
                if(cnt[i])
                {
                    sg[i].update_clear(1,1,n,l,r);
                    sg[i].update_add(1,1,n,now,now+cnt[i]-1,1);
                    now+=cnt[i];
                }
        }
        else
        {
            for(int i=25;i>=0;--i)
                if(cnt[i])
                {
                    sg[i].update_clear(1,1,n,l,r);
                    sg[i].update_add(1,1,n,now,now+cnt[i]-1,1);
                    now+=cnt[i];
                }
        }
    }
    for(int i=0;i<26;++i) sg[i].dfs(1,1,n);
    printf("%s",s+1);
    return 0;
}

行人检测模型在海思平台上的部署:从 PyTorch 到 NNIE 深度优化与实践 摘要 本文详细介绍行人检测模型从PyTorch到海思NNIE平台的部署流程。首先分析了行人检测面临的挑战(尺度变化、遮挡、姿态多样性等)及边缘部署的优势(实时性、隐私保护等)。重点阐述了模型转换过程:PyTorch→ONNX→Caffe→NNIE-WK,其中PyTorch转ONNX需注意评估模式设置、虚拟输入匹配、操作集版本选择等关键点。文章旨在帮助开发者在海思3516D芯片上实现高效的行人检测,克服部署过程中的常见问题,最终实现边缘设备的实时目标检测能力。 阅读详情

相关推荐

面板数据分析中的随机前沿软件FRONTIER Version 4.1应用

随机前沿模型是一种用于评估单位效率的统计方法。它考虑了输入和输出的随机性,允许我们在效率评估中引入不确定性。随机前沿模型通常用于评估生产单位、金融机构、医院等各种类型的决策单元的效率。FRONTIER是一个广泛使用的随机前沿分析软件,具有用户友好的界面和强大的功能。它提供了估计效率、前沿分析和模型比较的工具,使用户能够深入研究单位的效率和绩效。面板数据是一种包含多个单位(通常是时间序列数据)的数据类型,可以用于分析单位在不同时间点的变化和效率。

目标检测专栏持续更新中,改进YOLO系列通用,适用v5、v7、v8、所有博客均是团队原创博客,所有文章禁止转载,违者必究。 2981

CodeForces - 558E A Simple Task (计数排序 线段树)

This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order i...

henuzxy 545

Qwen2.5-7B大模型实战:从零部署到高效推理全流程解析

本文详细解析了Qwen2.5-7B大模型从零部署到高效推理的全流程。内容涵盖环境准备、模型下载、使用Transformers进行核心对话推理,并深入介绍了vLLM与TGI生产级服务部署、GPTQ/AWQ量化技术以降低显存消耗,以及llama.cpp、Ollama等本地推理方案。旨在帮助开发者快速掌握部署技巧,实现大模型在消费级硬件上的高效运行。

weixin_29061425的博客 490

codeforces 558 E A Simple Task

题目大意就是给一个字符串,然后多个操作,每次操作可以把每一段区间的字符进行升序或者降序排序,问最终的字符串是怎样的。 做法的话就是用线段树维护区间和   一开始只考虑字符串中字符'a'的情况,假设操作区间[L,R]中有x个'a',那么一次操作后,这x个'a'要么去最左(升序),要么去最右(降序),我们可以建立一颗线段树来维护这样的操作,字符'a'出现的位置值为1,否则为0,那么q次

Last Order 1154

UFAST车道线检测 Ultra-Fast-Lane-Detection 从环境搭建到复现完成(一)

UFAST车道线检测 Ultra-Fast-Lane-Detection 从环境搭建到复现完成(一)

m0_46364958的博客 4345

Coverity本地增量C/C++代码检查(Linux)操作简介

Coverity 是一款精确的综合静态分析与应用安全测试 (SAST) 平台,它可以在编写代码时发现关键的缺陷和安全缺陷,防止它们变成安全漏洞、故障或维护缺陷。

1482

CodeForces - 558E.A Simple Task字符串区间排序(计数排序+26棵线段树的维护)

题目链接http://codeforces.com/problemset/problem/558/E Time limit :5000 ms Memory limit : 524288 kB This task is very simple. Given a string S of length n and q queries each query is on the format i j k w...

孤风的博客 567

零基础学simulink仿真建模--使用Simulink来构建一个混合动力无人机中燃料电池与锂电池协同控制的仿真模型

延长飞行时间:燃料电池的能量密度高于锂电池,适合长时间稳定供电。提高功率密度:锂电池能够快速响应瞬时高功率需求,比如起飞和加速阶段。优化能源管理:通过有效的能量管理系统,可以根据实际需求动态调整燃料电池和锂电池的工作状态,从而提高整体效率。通过上述步骤,我们简要介绍了如何基于Simulink实现混合动力无人机中燃料电池与锂电池协同控制的仿真模型。

amy_mhd的博客 189

codeforces558e,好题

http://codeforces.com/problemset/problem/558/E E. A Simple Task time limit per test 5 seconds memory limit per test 512 megabytes input standard input output standard

郭大帅 1272

【Unity实战篇 】| Unity实现 文本框可以自适应大小,到达最大宽度之后再缩小字体

Unity实现 Text文本框可以自适应大小,到达最大宽度之后再缩小字体 需求:在文本框可以自适应大小拉伸的前提下,增加一个最大限制宽度,使其到达最大宽度后 再启用 Best Fit 实现自适应改变文字大小以适应文本框的大小。 在Unity中经常会用到文本组件的自适应大小功能,一般使用HorizontalLayoutGroup和ContentSizeFitter组件配合即可实现文本自适应的效果。

努力前行,总会成为自己心中的那道光 3万+

宇树G1机器人遥控器音频控制实战

本文介绍了宇树G1人形机器人遥控器控制音频播放的核心实现方案。通过DDS消息订阅获取遥控器输入,采用非阻塞的subprocess调用aplay命令控制外接音响设备。系统支持播放、暂停和重播功能,采用50ms轮询间隔实现实时响应。关键点包括遥控器初始化、音频进程管理(Popen)、退出机制。文章还提供了设备配置指南、遥控器按键说明和常见问题解决方案。该方案从复杂音频播放器中提炼出核心控制逻辑,可作为机器人交互开发的参考模板。

m0_47999117的博客 542

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 outputstandard output This task is very simple. Given a string S of length n and q queries each

习惯与规则决定命运 1478

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

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

题意:给你一个长度为n的字符串,n <= 100000,有q个查询 q <= 100000,每个查询,i,j,k,代表将从i到j的字符重新排序,如果k==1,就升序,如果k==0,就降序分析:裸的复杂度太高,肯定是过不了的,注意到只有26个字母,也就是可以log(n)的查询出来一段区间每个字母有多少个,查询出来之后,如果k==1就从’a’到’z’枚举查询出来的字母个数,依次放在这个区间即可,k==0

NM的专栏 544

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

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

E. A Simple Task time limit per test 5 seconds memory limit per test 512 megabytes input standard input output standard output This task is very simple. Given a string S

叶孤心的专栏 915

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

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 simple. Given a string S of length n and q queries each query is on the format i j k which means so...

weixin_34248849的博客 147

Codeforces Round #312 (Div. 2)-A Simple Task

这道题对字符进行排序要用counting sort, 其中统计每个字符的个数要用到线段树。所以需要为26个字母建26个线段树,统计某个字母在某个区间的数目。线段树的操作为区间更新和区间求和。#include <bits/stdc++.h> #define maxn 100005 #define INF 1e9 using namespace std; typedef long long ll;int

L. 361

Codeforces Round #312 E. A Simple Task (桶排序思想+线段树维护桶)

传送门 给定一个只包含小写字母的字符串,长度为n, m次操作,每次指定 [L,R] K K=0,让[L,R]区间降序排列,否则升序排列。 输出最终字符串。 由于每个数都相当于是[0,25]区间内,我们试试能不能开26个桶,第i个桶记录有多少个i,利用桶排序来求解。 我们开n个桶,每个桶大小都是26,记录第i位的26个数分布情况。 线段树维护桶序列,每个节点表示: 当前区间内,桶合并后的情况,即:【0,25】这些数各有多少个。 于是每次操作就可以这样处理: 先区间查询出当前询问区间[L,R]里面,【0,25

矮纸斜行闲作草 212

Codeforces Round #312 (Div. 2) E. A Simple Task

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

weixin_30384217的博客 96

CF 558E(A Simple Task-计数排序+线段树)

E. A Simple Task time limit per test 5 seconds memory limit per test 512 megabytes input standard input output standard output This task is very simple. Given a string S

nike0good |Oier&ACMer | 熟能生巧 1742

cf #312 E. A Simple Task (线段树+计数排序)

题目:http://codeforces.com/contest/558/problem/E 题意:给你一个字符串s,|s| 分析: 计数排序:先统计区间内每种字符的个数,然后按顺序将字符分配。 例如bccasabdass a有3个 b有2个 c有2个 d有1个 s有3个 按顺序分配之后就是aaabbccdsss,就已经排好序了。 现在用线段树的每个节点保存区间内每种

w20810的专栏 518

codeforces 558E E. A Simple Task( 线段树+统计排序)

题目连接:codeforces 558E题目大意:给出一个字母的序列(只包含小写字母),每次对它的一个区间进行排序,问最后的字母序列。题目分析:首先因为字母的数量很小,我们很容易想到统计统计排序这个O(26*log(n))的排序方法,对于每个要排序的区间,我们只需要从小到大统计每个字母有多少个,然后顺序输出即可,利用26棵线段树维护,可以做到O(logn)的复杂度。最后输出即可,总的复杂度O(26*

llin-黎辰 808

【CF】【312div2】【A Simple Task】

E. A Simple Task time limit per test 5 seconds memory limit per test 512 megabytes input standard input output standard output This task is very simple. Given a string S

ACM之路 466
上一篇: BZOJ 4636: 蒟蒻的数列 分块 (未敲)
下一篇: Codeforces Round #449 (Div. 1) A. Nephren gives a riddle 模拟.
sega_handsome
博客等级 码龄10年 7粉丝 164原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值