牛逼的黑科技哈希
Winson_Yue · · 个人记录
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
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++)
unsigned long long rd(){
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;
}
struct Hash{
static unsigned long long mix(unsigned long long x){
x += 0x9e3779b97f4a7c15ULL;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ULL;
x = (x ^ (x >> 27)) * 0x94d049bb133111ebULL;
return x ^ (x >> 31);
}
size_t operator()(unsigned long long x) const{
static const unsigned long long seed = chrono::steady_clock::now().time_since_epoch().count();
return mix(x + seed);
}
};
gp_hash_table<unsigned long long, unsigned long long, Hash> mp;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
unsigned long long n = rd();
unsigned long long sum = 0;
for(unsigned long long i = 1; i <= n; i++){
unsigned long long x = rd();
unsigned long long y = rd();
unsigned long long val = 0;
auto it = mp.find(x);
if(it != mp.end()){
val = it->second;
}
sum += i * val;
mp[x] = y;
}
cout << sum << "\n";
return 0;
}