题解 | 大整数哈希

大整数哈希

https://www.nowcoder.com/practice/29f0cff8a69b4ab6a2f63fb7386defa3

import sys

n= int(input())
res = 0
f = {}
for i in range(n):
    x,y =map(int,input().split())
    ans = f.get(x,0)   #x不在字典f中,则为0
    res += (i+1)* ans
    f[x] = y
 #位运算,1左移64位后-1,则低位64全是1,&与运算后可以保留低位64个,高位清零;等价与mod(2**64)取模运算
print(res &((1<<64)-1)) 

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务