POJ 3928 Ping pong 树状数组

DFRobot MGC3130电容式手势传感器库深度解析 电容式近场感应(Electric Near Field Sensing)是一种非接触、抗干扰的三维空间感知技术,其原理基于人体介电特性对高频电场的扰动响应,具备低功耗、高鲁棒性与零物理接触等核心优势。该技术广泛应用于医疗人机交互、工业HMI、智能家电等对可靠性与环境适应性要求严苛的嵌入式场景。DFRobot_MGC3130库正是面向Microchip MGC3130芯片的工程化实现,封装了I²C驱动、ASU硬件加速调度及多层抽象API,支持手势识别、触控检测与接近唤醒等功能动态切换。结合电容式近场感应与嵌入 阅读详情

Description

N(3<=N<=20000) ping pong players live along a west-east street(consider the street as a line segment). Each player has a unique skill rank. To improve their skill rank, they often compete with each other. If two players want to compete, they must choose a referee among other ping pong players and hold the game in the referee's house. For some reason, the contestants can't choose a referee whose skill rank is higher or lower than both of theirs. The contestants have to walk to the referee's house, and because they are lazy, they want to make their total walking distance no more than the distance between their houses. Of course all players live in different houses and the position of their houses are all different. If the referee or any of the two contestants is different, we call two games different. Now is the problem: how many different games can be held in this ping pong street?

Input

The first line of the input contains an integer T(1<=T<=20), indicating the number of test cases, followed by T lines each of which describes a test case.
Every test case consists of N + 1 integers. The first integer is N, the number of players. Then N distinct integers a1, a2 ... aN follow, indicating the skill rank of each player, in the order of west to east. (1 <= ai <= 100000, i = 1 ... N).

Output

For each test case, output a single line contains an integer, the total number of different games.

Sample Input

1 3 1 2 3

Sample Output

1

Score:
#include<cstdio>
#include<string.h>
using namespace std;
typedef long long ll;
#define MAXN 100000
#define M 20006
int ah[MAXN],al[MAXN],lb[MAXN];
int a[M],r[M],l[M];

int sum(int b[MAXN],int k)
{
    int ans=0;
    while(k>0)
    {
        ans+=b[k];
        k-=lb[k];
    }
    return ans;
}

void insert(int b[MAXN],int k)
{
    while(k<=MAXN)
    {
        b[k]++;
        k+=lb[k];
    }
}
int main()
{
    int T;
    scanf("%d",&T);
    for(int i=0;i<=MAXN;i++)
    {
        lb[i]=i&(-i);
    }
    while(T--)
    {
        int n,i;
        scanf("%d",&n);
        for(i=0;i<n;i++)
        {
            scanf("%d",a+i);
        }
        memset(ah,0,sizeof(ah));
        memset(al,0,sizeof(al));
        for(i=0;i<n;i++)
        {
            l[i]=sum(al,a[i]-1);
            insert(al,a[i]);
        }
        for(i=n-1;i>=0;i--)
        {
            r[i]=sum(ah,a[i]-1);
            insert(ah,a[i]);
        }
        ll ans=0;
        for(i=0;i<n;i++)
        {
            ans+=(ll)l[i] * (ll)( n - i - 1 - r[i] ) + (ll)( i - l[i] ) * (ll)r[i];
        }
        printf("%lld\n",ans);
    }
    return 0;
}
电容放电测试解析 电子设备断电后滤波电容残留电荷存在触电风险,需符合IEC等安全标准对放电时间的要求。放电测试需测量电容电压下降至安全值的时间,设计可采用主动放电电路或被动放电电阻。常见问题包括电阻选择不当或电路设计缺陷,建议预留放电时间裕度并采用组合放电方案。合规的放电设计是确保产品安全性和可靠性的关键环节。 阅读详情

相关推荐

RocketMq面板访问异常 com.alibaba.fastjson.JSONException: not close json text, token : string

rocketmq JSONException: not close json text, token : string 问题解决

qq_21067307的博客 5575

Poj 3928 Ping pong(树状数组)

http://poj.org/problem?id=3928 题意:有n个乒乓球爱好者,每个人都有不同的权能值a[i],每场比赛需要三个人,两名选手,一名裁判。有规定,裁判必须住在两名选手中间,并且技能值也要在两名选手中间。问一共能组织多少场比赛。 思路:只考虑第i(2 求c[i]:从左到右扫描所有的a[i],令x[j]表示到目前所有的a[i]中是否存在一个a[i] == j( x

1455

NVMe-MI --- Message Servicing Model(消息服务模型)

本文主要介绍NVMe-MI消息服务模型,两个主要类别是请求消息和响应消息。并介绍带外机制消息服务状态机。

智小星的博客 2015

poj3928 Ping pong 树状数组

http://poj.org/problem?id=3928 Ping pong Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2087   Accepted: 798 Description N(3<=N<=20000) ping pong pla

945

从CAD到Web:高效转换STEP/IGES模型为GLB格式的实践指南

本文详细介绍了如何将工业设计中的STEP/IGES模型高效转换为Web友好的GLB格式。通过PythonOCC和gltf-pipeline等工具链,实现从CAD到Web的无缝转换,大幅提升模型加载速度和展示效果。文章包含实战案例、优化技巧和常见问题解决方案,帮助开发者快速掌握3D模型转换技术。

weixin_29072299的博客 510

使用TEA5767和stm32制作一台数字FM收音机

本节我们来使用stm32控制一款集成收音机芯片TEA5767,来制作一台FM收音机。 TEA5767是一款低功耗立体声收音IC,接收频率76MHz~108MHz(适应日本/美国/欧洲各FM频段选择)并可以使用软件进行静音和消除噪音。 主要电性能指标:工作电压:2.5V~5.0V,工作电流10mA,立体声分离度30dB,信噪比60dB,输出信号电平75mV。支持I2C总线通信、3-wire总线。 1)硬件设计 TEA5767芯片外围需要搭配较多的电阻、电容、电感、晶振等器件,而且高频电路的PCB设

小白白学电子 1万+

poj 3928 Ping pong(数据结构:树状数组)

白书上树状数组例题,感觉看起来太吃力了 #include #include #define MAXN 100100 #define LL long long int a[MAXN], c[MAXN]; int pos[MAXN]; int lowbit(int x) { return x&(-x); } int sum(int x) { int ans = 0;

小华在努力~ 550

彻底解决Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource

renkai721的专栏 24万+

poj3928 Ping pong(树状数组)

http://poj.org/problem?id=3928 题意:有n个乒乓球选手,住在一条直线上,从左到右依次输入。每个选手有一个技术等级值。他们想打比赛,就要找裁判,为了省时和公正,选裁判的条件为裁判的位置和技术等级都在两位选手之间,求能打多少场比赛。 思路:N久没做树状数组,刚开始根本就是一脸蒙蔽,看了题解。树状数组解决的是根据特性求数量(比如Stars那道根据x坐标大小求

Iguodala的博客 542

数据中台:大数据平台,数据仓库(DM),数据中台之间的联系以及异同分析

大数据平台是一个技术平台。这个技术平台提供了对于大数据的分布式采集,存储,流处理和计算,实时分析等能力。在没有大数据平台前也有数据集成和管理的平台,这种平台可以实现对结构化数据本身的采集,集成和管理。 管理平台,是在原生的大数据生态的基础之上,为了更好的管理集群服务,管理集群的资源,提供灵活SRE能力和资源核算审计能力的一系列工具和合称整体架构数据中台包括数据仓库的全部内容,数据仓库为数据中台提供了数据对外提供服务的基础资源,数据中台将数据仓库建设的投入价值进行最大化,以加快数据赋能业务的速度大家都知道数据

GIS摆渡人 2136

PLC的模糊PID控制

模糊PID控制包括模糊化,确定模糊规则,解模糊等组成部分,小车通过传感器采集赛道信息,PLC通过温度传感器获取炉内温度,确定当前实际温度和设定目标值的偏差e(error), e=setpoint-input以及偏差的变化ec(当前偏差-上次偏差),根据给定的模糊规则进行模糊推理,最后对模糊参数进行解模糊,输出PID控制参数 其次我们需要对这2个参数进行模糊化,e 、 ec 这里我对e进行举例,两个输入的标准化范围都在 [-1,1] 范围内。模糊逻辑控制器还产生范围 [-1,1] 内的归一化输出。 博

RXXW_Dor的博客 1万+

POJ 3928 Ping pong 树状数组模板题

开始用瓜神说的方法撸了一发线段树,早上没事闲的看了一下树状数组的方法,于是又写了一发树状数组 树状数组: #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace

GXwar の Code library 1076

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

POJ 3928 Ping pong (树状数组)

Description N(3<=N<=20000) ping pong players live along a west-east street(consider the street as a line segment). Each player has a unique skill rank. To improve their skill rank, t...

bandiaodai5734的博客 164

老版QQ原生表情gif动态

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

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

POJ3928 Ping pong 树状数组

题目中只n个人,每个人有一个ID和一个技能值,一场比赛需要两个选手和一个裁判,只有当裁判的ID和技能值都在两个选手之间的时候才能进行一场比赛,现在问一共能组织多少场比赛。 这道题目是简单的树状数组统计问题。首先我们要对技能值从小到大排序,然后利用每一个选手的ID对树状数组进行维护.

LJ__ 913

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

POJ 3928 Ping pong(树状数组)

OJ题目 : 猛戳~~ Ping pong Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1743   Accepted: 670 Description N(3<=N<=20000) ping pong players live along a

700

POJ 3928 Ping pong(树状数组)

这道题的题意就是给你一个一维坐标系,坐标系代表着一条街道,每个点上住着一个能力值为ai的人,他们之间总要相互比试,每次比试都需要个裁判,但是每个裁判都要在他们的两个人的坐标中间,问你所有的人两两比试,有多少种比试的方法。 思路就是 考虑把每个人当裁判的情况数求出来,加一起就是答案了。先求出对于每个人的左边比他能力值小的人的个数f[i],再求出他的右边每个能力值比他小的人的个数r[i] 。 [

ACMan 364

poj 3928 Ping pong 树状数组

。。。

禅境花园 702

poj 3928 Ping pong 树状数组

以裁判为基础计算,每个运动员的技术水平都是不变的,他们对应的编号也是不变的, 首先将它们按技术水平排序,但对应的编码不变 如 技术:9 1 2 5 4 编码 1 2 3 4 5 排序后: 1 2 4 5 9 编码 : 2 3 5 4 1 再找他们每个人的左边(比他小的) 有多少人, 右边(即比他大的) 有多少人, 那么这个人就可以做 (左边*右边) 个人的裁判,同理 在反过来求, 如

ABCD1234 595

poj 3928 ping pong 树状数组

1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<algorithm> 5 #include<math.h> 6 #define maxx 100002 7 using namespace std; 8 ...

weixin_30834783的博客 97
上一篇: POJ 2352 线段树
下一篇: POJ 3835 Columbus's bargain 最短路
MakingMaker
博客等级 码龄15年 6粉丝 108原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值