跳到正文

题解

P17849 solution

4C45约 4 分钟
原文
文章信息与版本

文章信息

发布
2026年11月14日
收录
2026年11月14日
更新
2026年11月14日
篇幅
约 4 分钟
获赞
3
题目
P17849

版本

  1. v1当前
∏iai<V\prod_i a_i\lt V

判断上式是否成立。

发现左边那个项是指数级增长的所以给它限制一下,两边同取以二为底的对数。由函数单调性,

log⁡2∏iai<log⁡2V⇒∑ilog⁡2ai<log⁡2V\log_2 \prod_i a_i\lt \log_2 V\\\Rightarrow\sum_i \log_2 a_i\lt\log_2 V

考虑 aia_i 始终为正,直接开个 double 维护一下对数和就完了,误差可以通过在结果上做一个四舍五入来避免。

P17849
C++
#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:换了一板卡了卡常的代码。什么叫在性能差的机子上缩短了时限。

原文
存档评论3 条抓取于