CodeForces 1004C Sonya and Robots

从数学到机床:RTCP背后的几何变换与工业实现 本文深入解析RTCP(Rotary Tool Center Point)技术在五轴数控加工中的核心作用,通过几何变换与运动学原理实现刀尖点跟随,确保加工精度。从数学基础到工业实现,详细探讨了算法架构、机床结构适配及精度保障方法,为数控系统开发和高效加工提供关键技术支撑。 阅读详情

Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.

Sonya has drawn n numbers in a row, ai is located in the i-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position.

Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one. 
For example, if the numbers [1,5,4,1,3] are written, and Sonya gives the number 
1 to the first robot and the number 4 to the second one, the first robot will stop in the 1-st position while the second one in the 3-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number 4 to the first robot and the number 5 to the second one, they will meet since the first robot will stop in the 3-rd position while the second one is in the 2-nd position. 
Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot.

Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs (p, q), where she will give p to the first robot and q to the second one. Pairs (pi, qi) and (pj, qj) are different if pi≠pj or qi≠qj.

Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet. 
Input 
The first line contains a single integer n (1≤n≤105) — the number of numbers in a row.

The second line contains n integers a1,a2,…,an (1≤ai≤105) — the numbers in a row.

Output 
Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. 
Examples 
input
5 
1 5 4 1 3 
output
9 
input
7 
1 2 1 1 1 3 2 
output
7 
Note 
In the first example, Sonya can give pairs (1, 1), (1, 3), (1, 4), (1, 5), (4, 1), (4, 3), (5, 1), (5, 3), and (5, 4). 
In the second example, Sonya can give pairs (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), and (3, 2).

 

题意:每个数可以和它后面的数组成一个数对,问有多少个这样的不同数对。

暴力:从当前数开始,枚举所有能构成的数对。即计算当前数之后有多少个不同的数。

优化一:以ai开头的数对统计过之后,下次出现ai,就不用统计了,

优化二:用后缀数组记录此时ai之后有多少个不同的数。

代码实现:

可以用set,简化书写。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define eps 1e-8
#define PI acos(-1)
#define INF 0x3f3f3f3f
#define N 200000 + 10
using namespace std;
const int intN = 3e5 + 10 ;
typedef long long int LL;
const int dir[4][2]= { {1,0},{0,1},{-1,0},{0,-1} };

int GCD(int a,int b)
{
    return b ? GCD(b,a%b) : a;
}


int main()
{
    LL n,i,out=0;
    LL ans[N],s[N],ha[N]={0};
    set<LL>p;
    scanf("%lld",&n);
    for(i=0;i<n;i++)
        scanf("%lld",&s[i]);
    for(i=n-1;i>=0;i--)
    {
        p.insert(s[i]);
        ans[i]=p.size();
    }
    for(i=0;i<n-1;i++)
    {
        if(ha[s[i]]==0)
        {
            out+=ans[i+1];
            ha[s[i]]=1;
        }
    }
    printf("%lld\n",out);
    return 0;
}

 

YOLOv11涨点改进| Kimi团队 2026 |独家创新首发、注意力改进篇|爆火AttnRes残差自注意力模块,含多种创新改进,借助残差思想,缓解细节信息在传播过程中被稀释,促进YOLOv11涨点 🔥本文提出AttnRes残差自注意力模块,通过深度维度的注意力加权机制替代传统固定残差累加方式,使YOLOv11网络能自适应选择更有价值的历史层特征进行聚合。该方法缓解了浅层细节信息在深层传播过程中被稀释的问题,有效融合浅层纹理与深层语义特征,提升小目标、密集目标和复杂场景的检测能力。AttnRes还改善了深层网络的梯度分布与训练稳定性,增强模型收敛质量和泛化能力。实验表明,该模块能以较小计算开销显著提升YOLOv11的特征表达能力、检测精度和整体鲁棒性。文中详细介绍了模块结构、实现原理、优势特点 阅读详情

相关推荐

手把手教你用Wireshark国密版分析TLCP和IPSec协议(附下载地址)

本文详细介绍了Wireshark国密版在TLCP和IPSec协议分析中的实战应用,包括环境配置、协议解析、合规性检查及高级分析技巧。该工具针对商用密码算法(如SM2/SM3/SM4)进行了专项优化,支持GB/T 38636-2020 TLCP和GB/T 36968-2018 IPSec VPN等国家标准,帮助开发者与安全工程师高效完成密评分析任务。

weixin_29325955的博客 555

C. Sonya and Robots codeforces 1004 -csdn博客

Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn n numbers in a row, ai is located in the i-th position. She also has p...

i-Curve的博客 763

基于FaceX-Zoo实现的Face Mask Adding人脸戴口罩

人脸系列文章目录 文章目录人脸系列文章目录前言一、加口罩效果二、实现原理二、代码实现 前言 目前人脸加口罩均为在人脸位置贴图式的,非常不真实。前段时间京东开源一个基于PRnet实现的3D口罩拟合人脸,加口罩非常逼真,但是只是单独一个加口罩demo,没有完整的流程。于是本人结合人脸检测,关键点对齐。PRnet加口罩实现一个完整的加口罩流程。只需一个命令简单方便调用,实现人脸加口罩。 https://github.com/JDAI-CV/FaceX-Zoo 一、加口罩效果 下图可以看出效果还是非常逼真的

zengwb的博客 3391

CodeForces - 1004C Sonya and Robots 印象深刻

C. Sonya and Robots time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Since Sonya is interested in robotics too, she decided to cons...

pxlsdz的博客 446

用Java和MQTT搞定大疆无人机自动巡检:一个真实机场项目的踩坑与优化记录

本文详细介绍了如何利用Java和MQTT协议实现大疆无人机在机场自动巡检系统的开发与优化。通过实战案例分享系统架构设计、通信协议选型、断线重连机制及数据通道优化等关键环节,帮助开发者解决GPS信号漂移、MQTT消息风暴等典型问题,提升系统性能和可靠性。

weixin_30275415的博客 495

机器人运动不流畅?手把手教你用ACCSET调整ABB/FANUC点位加速度

本文针对ABB和FANUC工业机器人运动不流畅、拐角抖动、到位震颤等常见问题,提供了详细的解决方案。核心在于使用ACCSET指令(ABB)或ACC选项(FANUC)调整机器人的点位加速度与减速度参数。文章通过实战案例与系统化调试流程,手把手指导工程师优化运动性能,实现平稳、精准的机器人运动控制。

gpu4optimizer的博客 285

CodeForces 1004C

题目链接 https://vjudge.net/problem/CodeForces-1004C 题意 给左右机器人各一个数字p和q,左边机器人往右走,右边机器人往左走,遇到对应的数字就停下,问要使他们不相遇有多少种p,q。 思路 如果左边机器人在p位置停下,那么右边机器人q的取值是p+1到n之间不同数字的个数。 那么可以从右往左先预处理出每个位置后面不同数字的个数。 然后从...

Morphling_____ 308

Coding Plan:程序员真实工作的可执行编码决策框架

Coding Plan 是一种面向工程实践的编码决策方法论,它超越传统学习路径,聚焦于代码在真实业务系统中的上下文对齐、影响控制与可演进性保障。其核心在于将模糊的开发直觉转化为可度量、可验证、可协作的日常动作,涵盖目标对齐、上下文锁定、验证闭环、协作契约和演进预留五大锚点。结合2026年AI辅助编码新范式,它强调将大模型作为‘上下文翻译器’而非代码生成器,并通过分钟级工作块、技术债主动发行、可观测性前置等机制,显著提升交付确定性与系统长期健康度。本文详解该框架的底层逻辑与落地实践。

weixin_33326218的博客 439

Codeforces ~ 1004C ~ Sonya and Robots (思维 + 桶排)

题意给你n个数字,让你从这个序列中选一对数(a,b),使得从左边数第一个a出现的位置 &lt; 从右边数第一个b出现的位置,问符合要求的对数有多少个?题解对于每一个数字,他跟他后面的数字都可以组成这样的对,但是这样会有重复。重复情况①对于当前数字后面有两个相同的数字,其实算一次,比如1,2,2,其实只有一对(1,2),所以我们需要维护每个数字后面有多少个不同的数字,桶排就好了,过程中统计不同的数字...

张松超的博客 432

DL-FWI基础入门培训视频学习1、2

DL-FWI基础知识

shengMio的博客 711

Python办公自动化 2.1开发环境搭建:PyCharm社区版配置Anaconda开发环境

本篇文章主要讲述了如何在windows主机上配置 PyCharm + Anaconda开发环境、以及了如何配置 PyQt界面开发环境,安装过程超级详细,初学者可以照着一步一步来!

超级大洋葱的博客 2585

Sonya and Robots CodeForces - 1004C(思维)

C. Sonya and Robotstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSince Sonya is interested in robotics too, she decided to construct robots that ...

JiaYao的博客 437

自定义Usecase/Pipeline

Summary of Custom Usecase and Pipeline Configuration in SA8650 QCX Framework This article elaborates on the complete process of customizing a new Usecase and Pipeline based on the SA8650 QCX framework to meet OEM and Tier1 customization requirements, with

qq_39257814的博客 930

Codeforces 1004C Sonya and Robots

C. Sonya and Robots 题目大意:有n个数,每个数只能与自己后面的数配对,相同的配对只算一个,求配对的数量. 我们反过来考虑每个数可以与自己前面多少个数配对,得到答案是不变的. 如果前面的数都不相同的话,那么这个数对答案的贡献是i-1,如果有相同的,那么只要减去相同的就好了. 所以在读入时记录每个数出现的次数最后出现的位置和这个位置前面相同的数,然后就可以一次循环...

bannaiting9193的博客 202

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

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

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

C. Sonya and Robots codeforces 1004

解题思路:把每个数值都记录下来,并且记录共有多少中不同的数值,然后从左向右走,每到一个数是值这个数记录下,以保证下次不会再记录它,然后加上剩余剩的种类数。注意:结果要用long long存。这种暴力开map的方法屡试不爽 #include<bits/stdc++.h> using namespace std; int n; int a[100010]; int book[...

weixin_30872733的博客 161

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

codeforces 1004 C. Sonya and Robots SET

http://codeforces.com/problemset/problem/1004/C 找给出的序列里有多少组不同的 #include &lt;bits/stdc++.h&gt; using namespace std; const int maxn=100005; int a[maxn]; int sum[maxn]; //下標大於等於i的不同的a[i]的個數 int n;...

西瓜不甜的博客 343

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Sonya and Robots(CodeForces 1004C)

Description Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn nn numbers in a row, aiai is located in the ii-th positio...

Baiyi_destroyer的博客 189

Sonya and Robots CodeForces - 1004C (思维题)

Sonya and Robots time limit per test 1 second memory limit per test 256 megabytes input: standard input output: standard output Since Sonya is interested in robotics too, she de...

weixin_30657999的博客 117

cf 1004 C Sonya and Robots

cf 1004 C Sonya and Robots 题意 给你n个数字\(a_i\) ,在数字的左边和右边各有一个机器人,分别给左边和右边的机器人一个数字\(a_i\), \(a_j\),左边的机器人往右走,右边的机器人往左走,左边的机器人遇到\(a_i\)就停,右边的机器人遇到\(a_j\)就停,问使得两个机器人不相遇的对数有多少对? 题解 就是求一个数(第一次出现的)后面有多少个不...

weixin_30566149的博客 161

codeforces ~ 1004 C Sonya and Robots (dp)

C. Sonya and Robots time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Since Sonya is interested in robotics to...

weixin_30251829的博客 157

Codeforces Round #495 (Div. 2) C. Sonya and Robots(模拟)

原题地址:http://codeforces.com/contest/1004/problem/C 题意:给你n个数字,询问你有多少对 &lt;ai,aj&gt;(i&lt;j)&lt;ai,aj&gt;(i&lt;j)(i

yiqzq的博客 600

cf1004C Sonya and Robots

Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers.Sonya has drawn n numbers in a row, ai is located in the i-th position. She also has put...

包子不卖包子 319

Codeforces Round #495 C. Sonya and Robots

题意 给你n个数字,让你从这个序列中选一对数(a,b),使得从左边数第一个a出现的位置 &lt; 从右边数第一个b出现的位置,问符合要求的对数有多少个? 思路 仔细想一下,如果给你的n个数字中,每一个数字都是不同的,那么我们的答案其实就是,n-1,n-2,n-3….1对吧,如果这几个数字中有重复的那么我们就没有办法这样弄,怎么办呢?对于一种数来说,可以满足条件的是你出现的后面的数,比如说你后...

wjmwsgj的博客 287

Codeforces Round#495

A #include &amp;lt;bits/stdc++.h&amp;gt; using namespace std; #define ll long long #define inf 0x3f3f3f3f #define N 100010 inline char gc(){ static char buf[1&amp;lt;&amp;lt;16],*S,*T; if(S==T){T=(S=buf...

Icefox的博客 342

Codeforces Round 1004

Codeforces Round 1004

青少年趣味编程 1622
上一篇: C++之string类型
下一篇: 中国剩余定理
codertcm
博客等级 码龄8年 80粉丝 98原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值