rt.
Code:
#include<bits/stdc++.h>
using namespace std;
char buf[1<<26],*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 read() {
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;
}
const __int128 MOD=pow(2,64);
unsigned long long n,x,y,ans;
unordered_map<unsigned long long,unsigned long long>a;
int main(){
n=read();
for(unsigned long long i=1;i<=n;i++){
x=read();y=read();
ans=(ans+(a[x]*i))%MOD;
a[x]=y;
}
printf("%llu",ans);
return 0;
}
理论上是 O(n) ,而且已经用了快读优化,但还是TLE.