P17849 solution
判断上式是否成立。
发现左边那个项是指数级增长的所以给它限制一下,两边同取以二为底的对数。由函数单调性,
考虑 double 维护一下对数和就完了,误差可以通过在结果上做一个四舍五入来避免。
:::info[P17849]
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define rep(i,a,b) for(int i=a;i!=b+1;i++)
#define ir(i,a,b) for(int i=b;i>=a;i--)
#define db double
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define re return
#define len(str) (str.length())
#define inr(L,R,l,r) (l<=L and R<=r)
#define ofr(L,R,l,r) (L>r or l>R)
#define lowbit(x) (x&(-x))
#define tn2 tuple<node*,node*>
#define tn3 tuple<node*,node*,node*>
#define mt make_tuple
#define np nullptr
#define ioo cin.tie(0)->sync_with_stdio(0);cout.tie(0)->sync_with_stdio(0);
#define popc __builtin_popcount
using namespace std;
const int maxn=5e6+114;
char buf[1 << 20], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++)
inline int read() {
int x = 0;
char c = getchar();
for (; c < '0' || c > '9'; c = getchar());
for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar());
return x;
}
int n,m,v;
int a[maxn];
double s=0,t;
int main()
{
ioo;
n=read();m=read();v=read();
t=log2(v)+0.2;
rep(i,1,n)
{
a[i]=read();
s+=log2(a[i]);
}
int res=1,ans=0;
if(s<=t)
{
res=floor(pow(2,s)+0.1);
if(res<v) ans^=res;
}
rep(i,1,m)
{
int x,y;
x=read();y=read();
s-=log2(a[x]);
a[x]=y;
s+=log2(y);
if(s<=t)
{
res=floor(pow(2,s)+0.1);
if(res<v) ans^=res;
}
}
cout<<ans<<'\n';
}
:::
upd:换了一板卡了卡常的代码。什么叫在性能差的机子上缩短了时限。