Boring Counting(主席树+二分)

用Python+PyTorch实现DQN无人机避障:从环境搭建到实战训练(附完整代码) 本文详细介绍了如何使用Python和PyTorch框架,基于深度强化学习中的DQN算法,实现一个无人机自主避障系统。内容涵盖从自定义环境搭建、DQN智能体核心算法实现,到完整的训练流程与超参数调优,并提供了可视化演示与进阶优化方向,为开发者提供了从理论到实践的完整指南。 阅读详情
题目描述

In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence. Now you task is to answer a list of queries, for each query, please tell us among [L, R], how many Pi is not less than A and not greater than B( L<= i <= R). In other words, your task is to count the number of Pi (L <= i <= R, A <= Pi <= B).

输入

In the first line there is an integer T (1 < T <= 50), indicates the number of test cases.
For each case, the first line contains two numbers N and M (1 <= N, M <= 50000), the size of sequence P, the number of queries. The second line contains N numbers Pi(1 <= Pi <= 10^9), the number sequence P. Then there are M lines, each line contains four number L, R, A, B(1 <= L, R <= n, 1 <= A, B <= 10^9)

输出

For each case, at first output a line ‘Case #c:’, c is the case number start from 1. Then for each query output a line contains the answer.

样例输入
1
13 5
6 9 5 2 3 6 8 7 3 2 5 1 4
1 13 1 10
1 13 3 6
3 6 3 6
2 8 2 8
1 9 1 9
样例输出
Case #1:
13
7
3
6
思路

我们知道主席树可以求区间第k小的值,我可以二分k的值,然后判断利用第k小来判断出A,B分别是第几小。然后答案就是两者的差值。

代码
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define best 131 
#define INF 0x3f3f3f3f
#define P pair<int,int>
#define ls p<<1
#define rs p<<1|1
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps=1e-5;
const double pai=acos(-1.0);
const int N=5e4+10;
const int maxn=1e6+10;
//const int mod=1000000007;
int root[N],a[N],b[N],cnt;
int sum[N<<5],lc[N<<5],rc[N<<5];
void build(int p,int l,int r)
{
    p=++cnt,sum[p]=0;
    if(l==r) return ;
    int mid=(l+r)>>1;
    build(lc[p],l,mid);
    build(rc[p],mid+1,r);
}
int update(int p,int l,int r,int pos)
{
    int rt=++cnt;
    lc[rt]=lc[p],rc[rt]=rc[p],sum[rt]=sum[p]+1;
    if(l<r)
    {
        int mid=(l+r)>>1;
        if(pos<=mid) lc[rt]=update(lc[p],l,mid,pos);
        else rc[rt]=update(rc[p],mid+1,r,pos);
    }
    return rt;
}
int query(int u,int v,int l,int r,int k)
{
    if(l==r) return l;
    int mid=(l+r)>>1,x=sum[lc[v]]-sum[lc[u]];
    if(k<=x) return query(lc[u],lc[v],l,mid,k);
    else return query(rc[u],rc[v],mid+1,r,k-x);
}
int main( )
{
    int t,tot=0;
    scanf("%d",&t);
    while(t--)
    {
        cnt=0;//一定要记得清零,要不一直RE/(ㄒoㄒ)/~~
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i];
        sort(b+1,b+n+1);
        int len=unique(b+1,b+n+1)-b-1;
        build(root[0],1,len);
        for(int i=1;i<=n;i++)
        {
            int pos=lower_bound(b+1,b+len+1,a[i])-b;
            root[i]=update(root[i-1],1,len,pos);
        }
        printf("Case #%d:\n",++tot);
        while(m--)
        {
            int x,y,A,B,ans1,ans2;
            scanf("%d%d%d%d",&x,&y,&A,&B);
            int l=1,r=y-x+1,mid;
            while(l<=r)
            {
                mid=(l+r)>>1;
                int pos=query(root[x-1],root[y],1,len,mid);
                if(b[pos]>=A) 
                {
                    r=mid-1;
                }
                else l=mid+1;
            }
            ans1=l;
            l=1,r=y-x+1;
            while(l<=r)
            { 
                mid=(l+r)>>1;
                int pos=query(root[x-1],root[y],1,len,mid);
                if(b[pos]<=B)
                {
                    l=mid+1;
                }
                else r=mid-1;
            }       
            ans2=l;
            printf("%d\n",ans2-ans1);
        }
    }
    return 0;
}
嵌入式工程师成长之路(5)——板子调试 USB2514集线器调试总结说说USB连接线USB数据线上的“疙瘩”:原来有这么大用处! 阅读详情

相关推荐

STM32H750_QSPI_Flash_Configuration_With_CubeMX

本文详细介绍了如何使用STM32CubeMX配置STM32H750的QSPI Flash接口,包括硬件连接、CubeMX参数设置、代码生成与初始化流程优化。通过实战示例展示了Flash ID读取、页编程与数据读取等常用操作,并提供了调试技巧与性能优化建议,帮助开发者高效实现高速外部存储扩展。

weixin_29176179的博客 273

HDU 4358 Boring counting(线段树)

用C++交会栈溢出,而G++不会。 更新和查询我用的是线段树,1500+ms,用树状数组应该会快一些。 将树形结构转换成线性结构后,等价于求指定区间内恰好出现k次的数有多少个。 #include #include #include #include #include #include using namespace std; const int maxn = 100010

~飞呀,飞~ 2107

dummy机械臂代码学习(六)

CLI-Tool文件夹下又包含四个子文件夹,以及一个gitignore文件、一个run_shell.py的python文件、一个run.bat文件和一个zadig exe文件。库解析命令行参数,并根据不同的命令执行相应的操作。Zadig是一个用于Windows操作系统的开源工具,它的主要功能是安装和配置USB驱动程序。的目的呢就是确保在版本控制过程中,不必要的或自动生成的文件被忽略掉,来保持代码仓库的干净和整洁。,DummyStudio的软件作者已放在GitHub,我们主要看CLI-Tool文件夹就行。

jumaohhh的博客 1432

后缀自动机——Boring counting

题解: 统计每个子串的最右位置和最左位置,在这个区间(左闭右开)里我们一定能够保证我们每个子串出现了2次。 #include <bits/stdc++.h> using namespace std; const int maxn=2e5+10; const int maxc=27; typedef long long ll; struct Suffix_Automaton { int next[maxn<<1][maxc]; //状态转移(尾部加一个字符的下一个状态)

行走天涯的豆沙包的博客 264

pwscf与wannier90 Hands-On实战训练(一)——费米面计算为例

系列文章目录 Quantum Espresso Hands-On实战训练(三)——DOS计算 文章目录系列文章目录计算过程pwscf直接得到等能面pwscf和wannier90得到等能面pwscf直接得到等能面1. scf2. nscf3. 后处理pwscf和wannier90得到等能面1. Kpoints2. scf3. nscf4. pw2wan及wannier90.x5. XCrySDen可视化 计算过程 pwscf直接得到等能面 pwscf和wannier90得到等能面 pwscf直接得到等能面

weixin_45973682的博客 5070

从Transformer到蛋白质结构预测:手把手解读ESM系列模型的核心原理与实战价值

本文深入解析了ESM系列模型如何将Transformer架构创新应用于蛋白质结构预测,揭示了其从氨基酸序列到三维结构的高效预测机制。通过掩码语言模型预训练和注意力机制,ESM模型不仅捕捉蛋白质序列的远程相互作用,还在蛋白质工程改造、药物发现等领域展现出巨大实战价值,显著提升了结构预测速度和精度。

weixin_28744423的博客 318

Boring counting HDU - 4358(树上出现k次的数字个数)

In this problem we consider a rooted tree with N vertices. The vertices are numbered from 1 to N, and vertex 1 represents the root. There are integer weights on each vectice. Your task is to answer a ...

starlet_kiss的博客 404

【算法设计与分析】期末复习题(超详细)

刚刚整理了一下电脑的文件,发现了这份上学期的算法设计与分析期末复习题,有需要的文后自取。

a1234567822的博客 6611

HDU 3518 Boring counting(后缀数组)

题意: 求出不重叠切出现次数超过两次的子串个数 题解: 后缀数组分组后,判断每组出现的sa最大值和最小值之差是否是大于k就好了,k通过枚举即可 AC代码: #include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 2000+50; char s[MAXN]; in...

qq_43544481的博客 231

Apollo 9.0 参考线生成器 -- ReferenceLineProvider

在基于参考线的规划算法中,参考线是Planning一切工作的基础和前提,所以搞清楚参考线怎么来的就变得很重要。为此,首先需要了解Planning 与 Routing的交互,通过交互得到路径片段,这些路径片段就告诉我们该怎么走,再在此基础上生成参考线,最后使用不同的平滑算法对参考线进行平滑,得到一条光滑的参考线。

WaiNgai 1664

39、FIPA ACL:多代理系统中的标准化通信

本文详细介绍了FIPA ACL(Agent Communication Language)的基本概念、言语行为理论基础以及其在多代理系统(MAS)中的应用。文章涵盖了FIPA ACL的消息格式、信息交流流程、实现与优化方法,并通过智能调度系统的实例展示了其实际应用效果。此外,还探讨了FIPA ACL面临的挑战及未来发展方向,如通信延迟优化、本体简化、安全性增强等。

k8s6orchestrator的博客 381

HDU 3518 Boring counting (后缀自动机)

统计至少出现两次的不重叠子串的个数 后缀数组可做,所以我用后缀自动机 考虑到任意子串都包含在sam的某个状态中,所以对于某个状态st,只要| endpos(st) | >= 2 则状态中长度 <= ( max( endpos( st ) ) - min( endpos ( st ) )的子串都是满足条件的 所以只需要求出两个数组L[ i ],R[ i ],分别表示endpos...

aomen8092的博客 259

SOC估算方法之(OCV-SOC+安时积分法)

此方法主要参考。

m0_61973119的博客 933

Hrbust 2054 Boring Counting (主席树+二分)

Boring Counting Time Limit: 3000 MS Memory Limit: 32768 K Total Submit: 67(21 users) Total Accepted: 5(5 users) Rating: Special Judge: No Description In this problem you are given a number sequence P

妍恐龙的博客....^~^眼熟我 502

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

UPC组队赛第四场—— H: Boring Counting (主席树+二分)

问题 H: Boring Counting 时间限制: 3 Sec 内存限制: 128 MB 题目描述 In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence. Now you task is to answer a list of queries, for each query, please tell us among [L,

我们都有光明的未来 233

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

第四届 山东省ACM Boring Counting(划分树+二分 主席树待整理)

Boring Counting Time Limit: 3000MS Memory Limit: 65536KB Submit Statistic Problem Description     In this problem you are given a number sequence P consisting of N integer and Pi is the it

AI蜗牛之家 1347

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

【SDUT OJ 2610】 Boring Counting(主席树)

【SDUT OJ 2610】 Boring Counting(主席树) Boring Counting Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述     In this problem you are given a number sequence P consisting of N integ

ACMer' 4719

Boring Counting——【SDUT2610】主席树

Boring Counting Time Limit: 3000ms Memory limit: 65536K 题目描述 In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the sequence. Now you task is to

绝尘 923

2013山东省赛Boring Counting (主席树超详解)

主席树是为了处理l,r之间第k大的值。 题目分析:把在l,r之间小于等于y的数,减去l,r之间小于x的数。 求l,r之间小于等于y的数,假设这个数第k大,用主席树求,然后二分求k。1 主席树的建立:http://www.cnblogs.com/tedzhao/archive/2008/11/12/1332112.html 持久化二叉树,就是主席树,国外论文含金量有点高。有点

但求心安的博客 392

第四届山东省赛 J Boring Counting [主席树]【数据结构】

题目链接 http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2054 —————————————————————————————————————————— Boring Counting Time Limit: 3000 MS Memory Limit: 32768 K Total Submit:

Tabris的博客 578

upc 2224 Boring Counting (线段树+离线or主席树)+离散化

题意: 1~n个数,询问l~r区间,值范围在A~B的个数。 思路: 线段树+离线(肉鸽跟我说的思路,以前真没碰到,线段树的花样太多了),用树状数组替代线段树也可以。 首先先全部接收全部的询问, 然后再把每个询问区间,分为两个区间。例如2-8 -> 1-1和1-8。 然后根据区间右端点从小到大排序,然后边更新线段树边查询,把查询的结果保存起来即可。 code(线段树):

459

SDUT 2610 Boring Counting(离散化+主席树区间内的区间求和)

Boring Counting Time Limit:3000MSMemory Limit:65536KB SubmitStatisticDiscuss Problem Description In this problem you are given a number sequence P consisting of N integer and Piis the it...

weixin_30292745的博客 132

SDUT 2610 第四届山东省ACM省赛 Boring Counting (主席树或划分树 + 二分)

传送门:SDUT 2610题目大意:给你一个数组 P 和 m 组询问,让你求在区间 [ l , r ] 中满足 A&lt;= Pi &lt;=B 的数有多少个。前置技能:1.主席树原理及应用。2.划分树原理及应用。思路:主席树和划分树都可以解决区间第 K 大值的求解问题,但本题是求解区间内在某个范围内的数的个数。该怎么办呢?我们可以换个思路,求出区间内第一个出现的 A 排第几大,最后一个出现的 B...

zuzhiang的博客 272

UPC 2224 / “浪潮杯”山东省第四届ACM大学生程序设计竞赛 1008 Boring Counting 主席树...

Problem H:Boring Counting Time Limit : 6000/3000ms (Java/Other)Memory Limit : 65535/32768K (Java/Other) Problem Description In this problem you are given a number sequence P consisting o...

aegt43853的博客 183

山东省第四届ACM大学生程序设计竞赛 Boring Counting 划分树

Boring Counting Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述     In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the seque

MY Blog 657

Boring counting

题目描述 035 now faced a tough problem,his english teacher gives him a string,which consists with n lower case letter,he must figure out how many substrings appear at least twice,moreover,such apearanc

Tomcat的Tom 1万+
上一篇: Rescue The Princess(数学)
下一篇: A^X mod P(数论+打表)
Cosmic_Tree
博客等级 码龄7年 134粉丝 337原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值