【1】做题心得 - 2026 NOICA #24 - T1

?很神圣的题。

直接取 $\log $ 很慢且精度误差会累计。考虑到 \(>1\) 的数一旦超过 \(30\) 个就会爆炸,那么我们考虑到数值全部 \(>0\),使用栈存储待存元素,若能一次合并完就合并,反之不合并。

直接做就可以了。非常卡常。复杂度线性。

#define FileIO
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define gc getchar
#define fi first
#define se second
#define il inline
bool stMem; double stT=clock();
const int N=5e6+10;
const ll P=998244353;
il ll qp(ll a,ll b=P-2){
	ll res=1;
	for(;b;b>>=1,a=(a*a)%P) if(b&1) res=(res*a)%P;
	return res;
}
// ---------------------------------------------------- //
int n,m,V, a[N],x,y; ll mul, ans;bool is[N];
int stk[N], top;
#define gc getchar_unlocked
il void read(int &x){
    char ch=gc(); int f=+1,now_x=0;
    while(!isdigit(ch)) f=(ch=='-'?-1:f), ch=gc();
    while(isdigit(ch)) now_x=now_x*10+ch-'0', ch=gc();
    x=now_x*f;
}
// ---------------------------------------------------- //
il void solve(){
	read(n), read(m), read(V); mul=1;
	for(int i=1;i<=n;++i){
		read(a[i]);
		if(mul*a[i]<V) mul*=a[i];
		else stk[++top]=i, is[i]=1; 
	}
	if(!top) ans^=mul;
	while(m--){
		read(x), read(y);
		if(!is[x]){ mul/=a[x]; }
		if(mul*y<V){ mul*=y; is[x]=0; }
		else stk[++top]=x, is[x]=1;
		a[x]=y;
		while(top){
			int p=stk[top]; --top; 
			if(!is[p]) continue;
			is[p]=0;
			if(mul*a[p]>=V){ stk[++top]=p; is[p]=1; break; }
			else mul*=a[p];
		}
		if(!top) ans^=mul;
	}
	cout<<ans;
	return;
}
// ---------------------------------------------------- //
bool edMem;
int main(){
	#ifdef FileIO
		freopen("query.in","r",stdin);
		freopen("query.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T=1; //cin>>T;
	while(T--) solve();
	cerr<<"\n";
	cerr<<"[Info] End Of Running. \n";
	cerr<<"       Time Used   : "<<(clock()-stT)/CLOCKS_PER_SEC*1000.00<<" ms\n";
	cerr<<"       Memory Used : "<<(&edMem-&stMem)/1048576.00<<" Mib\n";
	return 0;
}


https://www.luogu.com.cn/article/hsnoftvd

posted @ 2026-11-14 20:33  Ivan422  阅读(9)  评论(0)    收藏  举报