Advertisement
Guest User

Untitled

a guest
Jun 26th, 2024
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <vector>
  3. #include <map>
  4. #include <math.h>
  5. #define pb push_back
  6. #define F first
  7. #define S second
  8. #define ll long long
  9. #define pii pair<int, int>
  10. #define pll pair<ll, ll>
  11.  
  12. using namespace std;
  13.  
  14. const ll MAX = 1e9;
  15. const ll MOD = 1e9 + 7;
  16.  
  17. ll binpow(ll a, ll b)
  18. {
  19.   ll res = 1;
  20.   while (b)
  21.   {
  22.     if (b & 1)
  23.       res = res * a % MOD;
  24.     a = a * a % MOD;
  25.     b >>= 1;
  26.   }
  27.   return res;
  28. }
  29.  
  30. bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
  31. {
  32.   return (a.second < b.second);
  33. }
  34.  
  35. int get_size(int x)
  36. {
  37.   int bit_size = 0;
  38.   while (x != 0)
  39.   {
  40.     x >>= 1;
  41.     bit_size++;
  42.   }
  43.   return bit_size;
  44. }
  45.  
  46. ll lcm(ll a, ll b)
  47. {
  48.   return (ll)((a / __gcd(a, b)) * b);
  49. }
  50.  
  51. void NonSense()
  52. {
  53.  
  54.   int64_t n, q;
  55.   cin >> n >> q;
  56.   vector<int64_t> A(n+1000);
  57.   for (int i = 1; i <= n; i++)
  58.     cin >> A[i];
  59.  
  60.   int64_t l, r, x, p;
  61.  
  62.   while (q--)
  63.   {
  64.     int64_t type;
  65.     cin >> type;
  66.     switch (type)
  67.     {
  68.     case 1:
  69.     {
  70.       cin >> l >> r >> x;
  71.       for (int64_t i = l; i < r; i++)
  72.         A[i] = x;
  73.       break;
  74.     }
  75.  
  76.     case 2:
  77.     {
  78.       cin >> l >> r >> x;
  79.  
  80.       for (int64_t i =l; i <= r; i++)
  81.         A[i] = (i-l+1)* x;
  82.       break;
  83.     }
  84.     case 3:
  85.     {
  86.       cin >> p >> x;
  87.       A.insert(A.begin() + p + 1 , x);
  88.       break;
  89.     }
  90.     case 4:
  91.     {
  92.       cin >> l >> r;
  93.       int64_t sum = 0;
  94.       for (int64_t i = l; i <= r; i++)
  95.         sum += A[i];
  96.       cout << "\t\t" << sum << endl;
  97.       break;
  98.     }
  99.     }
  100.   }
  101. }
  102.  
  103. int main()
  104. {
  105.   ios::sync_with_stdio(0);
  106.   int T;
  107.   cin >> T;
  108.   for (; T--;)
  109.   {
  110.     NonSense();
  111.   }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement