A8312 | Opposites Attract
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Everybody knows that opposites attract. That is the key principle of the "Perfect Matching" dating agency. The "Perfect Matching" matchmakers have classified each registered customer by his interests and assigned to the $i$ -th client number $t_{i}$ ( $-10<=t_{i}<=10$ ). Of course, one number can be assigned to any number of customers.
"Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of $t$ . Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence $t_{1},t_{2},...,t_{n}$ . For example, if $t=(1,-1,1,-1)$ , then any two elements $t_{i}$ and $t_{j}$ form a couple if $i$ and $j$ have different parity. Consequently, in this case the sought number equals 4.
Of course, a client can't form a couple with him/herself.
"Perfect Matching" wants to advertise its services and publish the number of opposite couples, that is, the couples who have opposite values of $t$ . Each couple consists of exactly two clients. The customer can be included in a couple an arbitrary number of times. Help the agency and write the program that will find the sought number by the given sequence $t_{1},t_{2},...,t_{n}$ . For example, if $t=(1,-1,1,-1)$ , then any two elements $t_{i}$ and $t_{j}$ form a couple if $i$ and $j$ have different parity. Consequently, in this case the sought number equals 4.
Of course, a client can't form a couple with him/herself.
输入格式
The first line of the input data contains an integer $n$ ( $1<=n<=10^{5}$ ) which represents the number of registered clients of the "Couple Matching". The second line contains a sequence of integers $t_{1},t_{2},...,t_{n}$ ( $-10<=t_{i}<=10$ ), $t_{i}$ — is the parameter of the $i$ -th customer that has been assigned to the customer by the result of the analysis of his interests.
输出格式
Print the number of couples of customs with opposite $t$ . The opposite number for $x$ is number $-x$ ( $0$ is opposite to itself). Couples that only differ in the clients' order are considered the same.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
输入输出样例
输入 #1
5 -3 3 0 0 3
输出 #1
3
输入 #2
3 0 0 0
输出 #2
3
In the first sample the couples of opposite clients are: (1,2), (1,5) и (3,4).
In the second sample any couple of clients is opposite.
In the second sample any couple of clients is opposite.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted