【HDU】3074 Multiply game

 1 #include<cstdio>

 2 typedef __int64 LL;

 3 #define MAXN 50010

 4 #define MOD 1000000007

 5 LL tree[MAXN<<2];

 6 inline void PushUp(int rt)

 7 {

 8     tree[rt]=tree[rt<<1]*tree[rt<<1|1];

 9     tree[rt]%=MOD;

10 }

11 void Build(int L,int R,int rt)

12 {

13     if(L==R)

14         scanf("%I64d",&tree[rt]);

15     else

16     {

17         int mid=(L+R)>>1;

18         Build(L,mid,rt<<1);

19         Build(mid+1,R,rt<<1|1);

20         PushUp(rt);

21     }

22 }

23 void Update(int x,int val,int L,int R,int rt)

24 {

25     if(L==R)

26         tree[rt]=val;

27     else

28     {

29         int mid=(L+R)>>1;

30         if(mid>=x)

31             Update(x,val,L,mid,rt<<1);

32         else

33             Update(x,val,mid+1,R,rt<<1|1);

34         PushUp(rt);

35     }

36 }

37 LL Query(int x,int y,int L,int R,int rt)

38 {

39     if(x<=L&&R<=y)

40         return tree[rt];

41     int mid=(L+R)>>1;

42     LL ans=1;

43     if(mid>=x)

44     {

45         ans*=Query(x,y,L,mid,rt<<1);

46         ans%=MOD;

47     }

48     if(y>mid)

49     {

50         ans*=Query(x,y,mid+1,R,rt<<1|1);

51         ans%=MOD;

52     }

53     return ans;

54 }

55 int main()

56 {

57     int c,n,q,cmd,x,y;

58     scanf("%d",&c);

59     while(c--)

60     {

61         scanf("%d",&n);

62         Build(1,n,1);

63         scanf("%d",&q);

64         while(q--)

65         {

66             scanf("%d%d%d",&cmd,&x,&y);

67             if(cmd)

68                 Update(x,y,1,n,1);

69             else

70                 printf("%I64d\n",Query(x,y,1,n,1));

71         }

72     }

73     return 0;

74 }

你可能感兴趣的:(game)