fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <vector>
  5. #include <cstdio>
  6. #include <cstdlib>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <queue>
  10. #include <map>
  11. #include <set>
  12. #include <iostream>
  13. #include <sstream>
  14. #include <cassert>
  15. #include <fstream>
  16. #include <cstring>
  17. #include <numeric>
  18. #include <ctype.h>
  19. #define MOD 1000000007
  20. #define exit return 0
  21. #define N 1555
  22. #define inf 1000000000000000000LL
  23. typedef long long ll;
  24. #define exit return 0
  25. #define PS system("pause")
  26. #define S 100007
  27. #define mx(a,b) a>b?a:b
  28. #define R0(i,n) for (i = 0; i < n; i++)
  29. #define R1(i,n) for (i = 1; i <= n; i++)
  30. #define MS(a,x) memset(x, a, sizeof(x));
  31. #define left v<<1
  32. #define right left|1
  33. #define SZ(x) ((int)x.size())
  34. const double eps = 1e-10;
  35. using namespace std;
  36.  
  37. struct seg{
  38. int sum, val;
  39. seg *l, *r;
  40. seg(){
  41. l = r = NULL;
  42. sum = 0;
  43. }
  44. };
  45. #define mid ((tl+tr)>>1)
  46. void add(seg &v, int tl, int tr, int pos1, int pos2, int val){
  47. if (tl > pos2 || tr < pos1)return;
  48.  
  49. if (tl <= pos1&&tr >= pos2){
  50. v.val += val;
  51. return;
  52. }
  53. if (!v.r)v.r = new seg;
  54. if (!v.l)v.l = new seg;
  55. add(*v.l, tl, mid, pos1, pos2, val);
  56. add(*v.r, mid + 1, tr, pos1, pos2, val);
  57. v.sum = v.l->sum + v.r->sum + (mid + 1 - tl)*v.l->val + (tr - mid)*v.r->val;
  58. }
  59.  
  60. int get(seg &v, int tl, int tr, int l, int r){
  61. if (tl > r || tr < l){
  62. return 0;
  63. }
  64. if (tl >= l&&tr <= r){
  65. return v.sum;
  66. }
  67. if (!v.l)v.l = new seg;
  68. if (!v.r)v.r = new seg;
  69. int L = get(*v.l, tl, mid, l, r);
  70. int R = get(*v.r, mid + 1, tr, l, r);
  71. return (L + R);
  72. }
  73. int n, m, i, j, k;
  74. seg *root;
  75. int main(){
  76. root = new seg;
  77. //add(*root, 1, 1200000000, 1, 1);
  78. scanf_s("%d %d", &n, &m);
  79. int a, b, c, d;
  80. for (int i = 0; i < m; i++){
  81. cin >> a >> b >> c;
  82. if (a == 0){
  83. cin >> d;
  84. add(*root, 1, n, b, c, d);
  85. }
  86. else cout << get(*root, 1, n, b, c);
  87. }
  88. PS;
  89. exit;
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:78:25: error: 'scanf_s' was not declared in this scope
  scanf_s("%d %d", &n, &m);
                         ^
stdout
Standard output is empty