Multiply game

本文介绍了一种涉及数列的游戏,玩家需在数列中进行数值更改及计算指定区间内所有数值的乘积。文章详细解释了游戏规则,并提供了一个使用线段树数据结构实现高效查询和更新的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Tired of playing computer games, alpc23 is planning to play a game on numbers. Because plus and subtraction is too easy for this gay, he wants to do some multiplication in a number sequence. After playing it a few times, he has found it is also too boring. So he plan to do a more challenge job: he wants to change several numbers in this sequence and also work out the multiplication of all the number in a subsequence of the whole sequence.
  To be a friend of this gay, you have been invented by him to play this interesting game with him. Of course, you need to work out the answers faster than him to get a free lunch, He he…


Input
The first line is the number of case T (T<=10).
  For each test case, the first line is the length of sequence n (n<=50000), the second line has n numbers, they are the initial n numbers of the sequence a1,a2, …,an,
Then the third line is the number of operation q (q<=50000), from the fourth line to the q+3 line are the description of the q operations. They are the one of the two forms:
0 k1 k2; you need to work out the multiplication of the subsequence from k1 to k2, inclusive. (1<=k1<=k2<=n)
1 k p; the kth number of the sequence has been change to p. (1<=k<=n)
You can assume that all the numbers before and after the replacement are no larger than 1 million.
Output
For each of the first operation, you need to output the answer of multiplication in each line, because the answer can be very large, so can only output the answer after mod 1000000007.
Sample Input
1
6
1 2 4 5 6 3
3
0 2 5
1 3 7
0 2 5
Sample Output
240
420
#include<stdio.h>
#include<string.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
const int N = 500005;
struct node{
	int l,r;
	ll sum;
}tree[N*4];
ll arr[N];
void build(int root,int l,int r){
	tree[root].l=l;
	tree[root].r=r;
	if(l==r){
		tree[root].sum=arr[l];
		return;
	}
	int mid=(l+r)/2;
	build(root*2,l,mid);
	build(root*2+1,mid+1,r);
	tree[root].sum=(tree[root*2].sum*tree[root*2+1].sum)%mod;
}
void update(int root,int pos,ll data){
	if(tree[root].l==pos&&tree[root].r==pos){
		tree[root].sum=data;
		return;
	}
	int mid=(tree[root].l+tree[root].r)/2;
	if(pos<=mid) update(root*2,pos,data);
	else update(root*2+1,pos,data);
	tree[root].sum=(tree[root*2].sum*tree[root*2+1].sum)%mod;
}
ll query(int root,int l,int r){
	if(tree[root].l==l&&tree[root].r==r)
		return tree[root].sum;
	int mid=(tree[root].l+tree[root].r)/2;
	if(r<=mid) return query(root*2,l,r);
	else if(l>mid) return query(root*2+1,l,r);
	else{
		ll a=query(root*2,l,mid);
		ll b=query(root*2+1,mid+1,r);
		return a*b%mod;
	}
}
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		   scanf("%lld",&arr[i]);
		build(1,1,n);
		int m;
		scanf("%d",&m);
		while(m--){
			int op,a,b;
			scanf("%d%d%d",&op,&a,&b);
			if(op) update(1,a,b);
			else printf("%lld\n",query(1,a,b)%mod);
		}
	}
	return 0;
}


PlayerCameraManagerClass = AMyPlayerCameraManager::StaticClass(); void AMyPlayerCameraManager::UpdateCamera(float DeltaTime) { Super::UpdateCamera(DeltaTime); if (MyCharacter && MyCharacter->ActorHasTag(FName("MyCharacter"))) { CustomCameraBehaivor(DeltaTime); } //Shake.ExecuteIfBound(this); /*if (UMyWeaponSubsystem::GetMyWeaponSubsystem()->ShakeCamera) { StartCameraShake(MyCharacter->CameraShakeClass, UMyWeaponSubsystem::GetMyWeaponSubsystem()->ShakeScale); }*/ } void AMyPlayerCameraManager::CustomCameraBehaivor(float DeltaTime) { PivotValue = MyCharacter->GetActorTransform();//中心锚点位置 //设置过度到中心锚点的中间值,获得过度锚点 PivotTrasitionValue.SetLocation(CalculateTransitionValue_Location(PivotTrasitionValue.GetLocation(), PivotValue.GetLocation(), FVector( GetCurveValue(FName("PivotLagSpeed_X")), GetCurveValue(FName("PivotLagSpeed_Y")), GetCurveValue(FName("PivotLagSpeed_Z")) ))); PivotTrasitionValue.SetRotation(PivotValue.GetRotation()); //在过渡的锚点值上添加偏移值,获得偏移锚点 PivotOffsetValue.SetLocation(PivotTrasitionValue.GetLocation()+ UKismetMathLibrary::Multiply_VectorFloat(UKismetMathLibrary::GetForwardVector(PivotValue.GetRotation().Rotator()), GetCurveValue(FName("PivotOffset_X"))) + UKismetMathLibrary::Multiply_VectorFloat(UKismetMathLibrary::GetRightVector(PivotValue.GetRotation().Rotator()), GetCurveValue(FName("PivotOffset_Y"))) + UKismetMathLibrary::Multiply_VectorFloat(UKismetMathLibrary::GetUpVector(PivotValue.GetRotation().Rotator()), GetCurveValue(FName("PivotOffset_Z")))); PivotOffsetValue.SetRotation(PivotValue.GetRotation()); //在偏移锚点值上添加相机偏移值,获得相机最终位置 CameraTargetValue.SetLocation( FVector(PivotOffsetValue.GetLocation() + UKismetMathLibrary::Multiply_VectorFloat(UKismetMathLibrary::GetForwardVector(PlayerController->GetControlRotation()), GetCurveValue(FName("CameraOffset_X"))) + UKismetMathLibrary::Multiply_VectorFloat(UKismetMathLibrary::GetRightVector(PlayerController->GetControlRotation()), GetCurveValue(FName("CameraOffset_Y"))) + UKismetMathLibrary::Multiply_VectorFloat(UKismetMathLibrary::GetUpVector(PlayerController->GetControlRotation()), GetCurveValue(FName("CameraOffset_Z"))) )); //给相机旋转进行插值变化 CameraTargetValue.SetRotation(UKismetMathLibrary::RInterpTo( CameraTargetValue.GetRotation().Rotator(), PlayerController->GetControlRotation(), DeltaTime, GetCurveValue(FName("RotationLagSpeed")) ).Quaternion()); //射线检测防止相机穿模 FVector start = MyCharacter->GetMesh()->GetSocketLocation(FName("TP_CameraTrace_R")); FVector end = CameraTargetValue.GetLocation(); FHitResult Hit; ETraceTypeQuery TraceType=UEngineTypes::ConvertToTraceType(ECC_Visibility); UKismetSystemLibrary::SphereTraceSingle(GetWorld(), start, end, 10.f, TraceType, false, TArray<AActor*>(), EDrawDebugTrace::ForOneFrame, Hit, true); if (Hit.bBlockingHit && !Hit.bStartPenetrating) { CameraTargetValue.SetLocation(CameraTargetValue.GetLocation() + Hit.Location - Hit.TraceEnd); } //应用最终数值到相机 FMinimalViewInfo&NewPOV= ViewTarget.POV; NewPOV.Location = CameraTargetValue.GetLocation(); NewPOV.Rotation = CameraTargetValue.GetRotation().Rotator(); SetCameraCachePOV(NewPOV);//必须调用才能更改,ViewTarget.POV并不是最终的应用数据,即使用引用更改ViewTarget.POV也无效 //GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Blue, FString::Printf(TEXT("TransitionVlaueGetLocation: %s"), *TransitionVlaue.GetLocation().ToString())); //GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Blue, FString::Printf(TEXT("TransitionVlaueGetRotation: %s"), *TransitionVlaue.GetRotation().ToString())); //调试 UKismetSystemLibrary::DrawDebugSphere(GetWorld(), PivotValue.GetLocation(), 16, 8, FColor::Red);//中心锚点 UKismetSystemLibrary::DrawDebugSphere(GetWorld(), PivotTrasitionValue.GetLocation(), 16, 8, FColor::Blue);//过度锚点 UKismetSystemLibrary::DrawDebugSphere(GetWorld(), PivotOffsetValue.GetLocation(), 16, 8, FColor::Yellow);//偏移锚点 UKismetSystemLibrary::DrawDebugLine(GetWorld(), PivotValue.GetLocation(), PivotTrasitionValue.GetLocation(), FColor::Black); UKismetSystemLibrary::DrawDebugLine(GetWorld(), PivotTrasitionValue.GetLocation(), PivotOffsetValue.GetLocation(), FColor::Black); }
最新发布
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值