当前位置:网站首页>Zcmu--5083: number pairs of ly (C language)
Zcmu--5083: number pairs of ly (C language)
2022-07-24 16:32:00 【Little why】
Description
ly Yes n Number , Now she wants to know this n Take a logarithm out of the number (x,y) Satisfy x%3 <= y%3 What's the number of plans for . among , In this sequence ,x It's better than y front .
Input
Enter two lines , The first line contains a positive integer n , Represents the number of numbers .
The second line contains n A positive integer ,ai Represents the second in the sequence i Number .
Title assurance 1 <= n <= 10^5, 1 <= ai <=10^9
Output
Output one line , It's an integer , For the answer .
Sample Input
4
1 3 4 2
Sample Output
5
analysis :1. requirement x%3 <= y%3, So we can notice , We can put the whole sequence all %3, Then I found that only 0,1,2 Three situations !
2. because x The location should be y front , So the question actually lets us ask each a[ i ] How many of the following sequences are greater than a[ i ] The sum of the number of , So we have to traverse from the back , At the same time, the record is updated 0,1,2 Existing quantity a,b,c. If a[ i]=0, that a[ i ] The contribution to the answer is a+b+c, then a++. If a[i]=1, Contribution is b+c, then b++,a[i]=2, Contribution is c,c++;
3. The maximum number of schemes exceeds int 了 , We use long long.
#include <stdio.h>
int k[100005];
int main()
{
int n,i,l,a=0,b=0,c=0; //abc Record the existing 0,1,2 Number
long long s=0; // Record the number of schemes
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%d",&l),k[i]=l%3;// All modules 3 Deposit in
for(i=n-1;i>=0;i--){ // Start from the back
if(k[i]==0) s+=a+b+c,a++;
else if(k[i]==1) s+=b+c,b++;
else if(k[i]==2) s+=c,c++;
}
printf("%lld\n",s);
return 0;
}
边栏推荐
- Jenkins CLI 命令详解
- [leetcode]38. counting - problem solving (execution time beat 91%, memory consumption beat 97%)
- Druid integration shardingsphere appears xxmapper Reasons and solutions of XML error reporting
- ZBar source code analysis - img_ scanner. c | [email protected]
- File browser? QT can also be achieved!
- [technology] chat room demo of uniapp
- 1184. Distance between bus stops
- Rest style
- [Nanjing Agricultural University] information sharing of postgraduate entrance examination and re examination
- Qt信号和槽连接失败原因及解决办法
猜你喜欢

EMQ Yingyun technology was listed on the 2022 "cutting edge 100" list of Chinese entrepreneurs

Jing Wei PS tutorial: basic part a

Win10 download address

Envi SHP to ROI and mask the grid

C TCP client form application asynchronous receiving mode

Template method mode

1184. 公交站间的距离

Caikeng Alibaba cloud Kex_ exchange_ identification: read: Connection reset by peer

Urban safety series popular science - enter the high incidence period of drowning, if you know the common sense of life-saving

多线程(基础)
随机推荐
做完数据治理,质量依旧很差
Envi SHP to ROI and mask the grid
1184. 公交站间的距离
Envi5.3 open GF-1 WFV data
Qualcomm reconciled with apple and received at least $4.5 billion in settlement fees! Next goal: Huawei!
Jing Wei PS tutorial: basic part a
Template method mode
How vscode mouse wheel enlarges the interface
QT keyboard event (I) -- detect key input
Host PSQL connecting virtual machine Oracle
我们为什么要推出Getaverse?
Hping3 installation and use
"Heaven and the world, self-respect" -- single case mode
Mobile phone comparison redmi note8 and realm x2
详解 Apache Hudi Schema Evolution(模式演进)
QT keyboard event (II) -- long press the key to trigger the event event repeatedly, and the problem is solved
EF data migration
Thinkphp3.2.5 cannot jump to external links
ARP 入门
Code shoe set - mt2095 · zigzag jump