#P11615. 【模板】哈希表

【模板】哈希表

背景

本题读入量较大,建议使用快速读入。

char buf[1<<23],*p1=buf,*p2=buf;
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline unsigned long long rd() {//读入一个 64 位无符号整数
	unsigned long long x=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch)) x=x*10+(ch^48),ch=gc();
	return x;
}

题目描述

你需要维护一个映射 f:[0,264)→[0,264)f:[0,2^{64})\to[0,2^{64}),初始 ∀x∈[0,264),f(x)=0\forall x\in [0,2^{64}),f(x)=0。

有 nn 次操作,每次操作给出二元组 (x,y)(x,y),表示查询 f(x)f(x) 的值,之后 f(x)←yf(x)\gets y。

输入格式

第一行,一个正整数 nn。

接下来 nn 行,每行两个整数 x,yx,y 描述一次操作。

输出格式

为了减少输出量,设第 ii 次操作的答案为 ansians_i,你只需要输出 ∑i=1ni×ansi\sum_{i=1}^ni\times ans_i 对 2642^{64} 取模的结果。

5
0 4
0 998244353
1000000000000000000 20120712
1000000000000000000 1000000000000000000
1000000000000000000 998244353
5000000000080482856

提示

样例的 ansans 分别为:0,4,0,20120712,10000000000000000000,4,0,20120712,1000000000000000000。

对于 100%100\% 的数据,1≤n≤5×106,0≤x,y<2641\le n \le 5\times 10^6,0\le x,y<2^{64}。

子任务 nn
00 ≤10\le 10
11 ≤105\le 10^5
22 ≤106\le 10^6
33 ≤5×106\le 5\times 10^6
44

子任务 0∼30\sim 3 的数据生成方式较为随机,子任务 44 是针对 unordered_map,gp_hash_table,cc_hash_table 和一些错误的哈希方式等的 hack。

如果你认为你的代码复杂度正确却没有通过,记得使用快速读入。