Raslboyy

3327

Dec 26th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #include <math.h>
  6. #include <climits>
  7.  
  8. //#pragma GCC optimize("O3, unroll-loops");
  9.  
  10. #include <list>
  11. #include <map>
  12. #include <set>
  13. #include <queue>
  14. #include <unordered_map>
  15. #include <unordered_set>
  16.  
  17. //#include <chrono>
  18. //#include <fstream>
  19. //#include <bits/stdc++.h>
  20.  
  21. #define mp make_pair
  22. #define pb push_back
  23. #define eb emplace_back
  24. #define x first
  25. #define y second
  26. #define sz(x) (int)x.size()
  27. #define all(x) begin(x), end(x)
  28. #define rall(x) rbegin(x), rend(x)
  29. #define FOR(i,a,b) for (int i = (a); i < (b); i++)
  30. #define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
  31.  
  32. using namespace std;
  33.  
  34. typedef unsigned long long ull;
  35. typedef long long ll;
  36. typedef long double ld;
  37. typedef pair<int, int> pi;
  38. typedef pair<ll, ll> pl;
  39. typedef vector<int> veci;
  40. typedef vector<bool> vecb;
  41. typedef vector<vector<int>> vvi;
  42. typedef vector<vector<bool>> vvb;
  43.  
  44. const int INF_I = 1e9;
  45. const ll INF_LL = 1e18;
  46.  
  47. veci mod;
  48. veci a;
  49. int n;
  50.  
  51. void build(int c = 1, int tl = 0, int tr = n - 1) {
  52.     if (tl == tr) {
  53.         mod[c] = a[tl];
  54.         return;
  55.     }
  56.     int tm = (tl + tr) >> 1;
  57.     build(c << 1, tl, tm);
  58.     build((c << 1) + 1, tm + 1, tr);
  59. }
  60.  
  61. void update(int l, int r, int add, int c = 1, int tl = 0, int tr = n - 1) {
  62.     if (l > r)
  63.         return;
  64.     if (tl == l && tr == r) {
  65.         mod[c] += add;
  66.         return;
  67.     }
  68.     int tm = (tl + tr) >> 1;
  69.     update(l, min(r, tm), add, c << 1, tl, tm);
  70.     update(max(l, tm + 1), r, add, (c << 1) + 1, tm + 1, tr);
  71. }
  72.  
  73. int get(int pos, int c = 1, int tl = 0, int tr = n - 1) {
  74.     if (tl == tr)
  75.         return mod[c];
  76.     int tm = (tl + tr) >> 1;
  77.     if (pos <= tm)
  78.         return mod[c] + get(pos, c << 1, tl, tm);
  79.     return mod[c] + get(pos, (c << 1) + 1, tm + 1, tr);
  80. }
  81.  
  82. int main() {
  83.     /*ifstream cin("in.txt");
  84.     ofstream cout("out.txt");
  85.     auto start_time = chrono::high_resolution_clock::now();*/
  86.  
  87.     ios::sync_with_stdio(false);
  88.     cin.tie(0);
  89.     cout.tie(0);
  90.  
  91.    
  92.     int m;
  93.     cin >> n;
  94.  
  95.     mod.assign(n << 2, 0);
  96.     a.assign(n, 0);
  97.     FOR(i, 0, n)
  98.         cin >> a[i];
  99.     build();
  100.     cin >> m;
  101.     for (int i = 0; i < m; i++) {
  102.         char ch;
  103.         cin >> ch;
  104.         if (ch == 'g') {
  105.             int in;
  106.             cin >> in;
  107.             cout << get(--in) << "\n";
  108.         }
  109.         else {
  110.             int l, r, add;
  111.             cin >> l >> r >> add;
  112.             update(--l, --r, add);
  113.         }
  114.     }
  115.    
  116.     /*auto end_time = chrono::high_resolution_clock::now();
  117.     chrono::duration<double> duration = end_time - start_time;
  118.     cout << duration.count() << "\n";
  119.     cin.close();
  120.     cout.close();*/
  121.     return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment