fork download
  1. using namespace std;
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5.  
  6. #define MAXN 100005
  7. constexpr long long MOD = 1e9 + 7;
  8.  
  9. int N,M;
  10.  
  11. pair<long long,long long> st[262144];
  12.  
  13.  
  14. pair<long long,long long> combine(pair<long long,long long> a,pair<long long,long long> b) {
  15. // c(ax + b) + d = acx + (bc + d)
  16. return make_pair((a.first * b.first) % MOD,((a.second * b.first) % MOD + b.second));
  17. }
  18.  
  19. void update(int x,pair<long long,long long> v,int l,int r,int p) {
  20.  
  21. if(l > x || r < x) return;
  22.  
  23. if(l == r) {
  24. st[p] = v;
  25. return;
  26. }
  27. int m = (l + r) / 2;
  28. update(x,v,l,m,2 * p + 1);
  29. update(x,v,m + 1,r,2 * p + 2);
  30. st[p] = combine(st[2 * p + 1],st[2 * p + 2]);
  31. }
  32.  
  33. void update(int x,pair<char,long long> v) {
  34. if(v.first == '+') {
  35. update(x,make_pair(1,v.second),0,MAXN,0);
  36. }else if(v.first == '-') {
  37. update(x,make_pair(1,MOD - v.second),0,MAXN,0);
  38. }else if(v.first == '*') {
  39. update(x,make_pair(v.second,0),0,MAXN,0);
  40. }
  41. }
  42.  
  43. pair<long long,long long> getSum(int a,int b,int l,int r,int p) {
  44. if(l > b || r < a) return make_pair(1,0);
  45. if(l >= a && r <= b) return st[p];
  46. int m = (l + r) / 2;
  47. return combine(getSum(a,b,l,m,2 * p + 1),getSum(a,b,m + 1,r,2 * p + 2));
  48. }
  49.  
  50. long long getSum(long long v,int x) {
  51. pair<long long,long long> res = getSum(0,x,0,MAXN,0);
  52. return ((v * res.first) % MOD + res.second) % MOD;
  53. }
  54.  
  55. void init() {
  56. for(int i = 0;i < MAXN;++i) {
  57. update(i,make_pair('+',0));
  58. }
  59. }
  60.  
  61. string pp(pair<long long,long long> p) {
  62. cout << p.first << " " << p.second << endl;
  63. }
  64.  
  65. int main() {
  66. init();
  67.  
  68. cin >> N >> M;
  69. for(int i = 0;i < N;++i) {
  70. char a;
  71. int b;
  72. cin >> a >> b;
  73. update(i,make_pair(a,b));
  74. }
  75. for(int i = 0;i < M;++i) {
  76. char a;
  77. cin >> a;
  78. if(a == 'c') {
  79. long long b,c;
  80. char d;
  81. cin >> b >> c >> d;
  82. update(b - 1,make_pair(d,c));
  83. }else{
  84. int b,c;
  85. cin >> b >> c;
  86. cout << getSum(b,c - 1) << endl;
  87. }
  88. }
  89.  
  90. return 0;
  91. }
Success #stdin #stdout 0.02s 7796KB
stdin
Standard input is empty
stdout
Standard output is empty