SHARE
    TWEET
    Vince14

    /<> 11505 (top down seg tree)

    Sep 9th, 2023 (edited)
    136
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    C++ 1.88 KB | Source Code | 0 0
    1. #include <iostream>
    2. #include <string>
    3. #include <cstring>
    4. #include <algorithm>
    5. #include <cmath>
    6. #include <vector>
    7. #include <set>
    8. #include <map>
    9. #include <stack>
    10. #include <queue>
    11. #include <deque>
    12. #include <unordered_map>
    13. #include <numeric>
    14. #include <iomanip>
    15. using namespace std;
    16. #define pii pair<long long, long long>
    17. #define ll long long
    18. #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
    19. const long long dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
    20. const long long dl[2] = {1, -1};
    21. const long long MOD = 1000000007;
    22. const long long MAX = 1000005;
    23. const long long MAXN = 1000005;
    24. int N, M , K;
    25. long long arr[MAXN];
    26. long long seg[MAXN * 4];
    27. long long build(int x, int s, int e){
    28. if(s == e){
    29. return seg[x] = arr[s];
    30. }
    31. int mid = (s + e)/2;
    32. return seg[x] = (build(x * 2, s, mid) * build(x * 2 + 1, mid + 1, e)) % MOD;
    33. }
    34. void update(int x, int s, int e, int idx, long long val){
    35. if(idx < s || idx > e) return;
    36. if(s == e){
    37. seg[x] = val;
    38. return;
    39. }
    40. int mid = (s + e)/2;
    41. update(x * 2, s, mid, idx, val);
    42. update(x * 2 + 1, mid + 1, e, idx, val);
    43. seg[x] = (seg[x * 2] * seg[x * 2 + 1]) % MOD;
    44. }
    45. long long query(int x, int s, int e, int a, int b){
    46. if(a > e || b < s) return 1;
    47. if(a <= s && e <= b){
    48. return seg[x];
    49. }
    50. int mid = (s + e)/2;
    51. return (query(x * 2, s, mid, a, b) * query(x * 2 + 1, mid + 1, e, a, b)) % MOD;
    52. }
    53. int main() {
    54. FAST;
    55. cin >> N >> M >> K;
    56. for(int i = 1; i <= N; i++){
    57. cin >> arr[i];
    58. }
    59. build(1, 1, N);
    60. for(int i = 0; i < M + K; i++){
    61. int a, b, c;
    62. cin >> a >> b >> c;
    63. if(a == 1){
    64. update(1, 1, N, b, c);
    65. }
    66. else{
    67. cout << query(1, 1, N, b, c) << "\n";
    68. }
    69. }
    70. }
    71. /*
    72. 5 2 2
    73. 1
    74. 2
    75. 3
    76. 4
    77. 5
    78. 1 3 6
    79. 2 2 5
    80. 1 5 2
    81. 2 3 5
    82. */
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /