fork(1) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cstdio>
  6. #include <cctype>
  7. #include <vector>
  8. #include <queue>
  9. #include <deque>
  10. #include <cmath>
  11. #include <set>
  12. #include <map>
  13. #include <string>
  14. #define ll long long
  15. #define ld long double
  16. #define sqr(a) (a)*(a)
  17. #define mp make_pair
  18. #define pb push_back
  19. #define pi pair<int,int>
  20. #define x first
  21. #define y second
  22. #define inf (int)1e9
  23. using namespace std;
  24. const int N=1000001;
  25. int n,m,x,t,l,r;
  26. int tree[N],a[N];
  27. void update(int i,int delta)
  28. {
  29. for(;i<n;i=(i|(i+1)))
  30. tree[i]+=delta;
  31. }
  32. int get(int r)
  33. {
  34. int res=0;
  35. for(;r>=0;r=(r&(r+1))-1)
  36. res+=tree[r];
  37. return res;
  38. }
  39.  
  40. int main()
  41. {
  42. freopen("segmentupdate.in","r",stdin);
  43. freopen("segmentupdate.out","w",stdout);
  44. ios_base::sync_with_stdio(false);
  45. cin.tie(NULL);
  46. cin>>n>>m;
  47. for(int i=0;i<n;i++)
  48. cin>>a[i];
  49. while(m--)
  50. {
  51. cin>>t;
  52. if(t==1)
  53. {
  54. cin>>l>>r>>x;
  55. l--,r--;
  56. update(l,x);
  57. update(r+1,-x);
  58. }else {
  59. cin>>x;
  60. x--;
  61. cout<<a[x]+get(x)<<"\n";
  62. //printf("%d\n",a[x]+get(x));
  63. }
  64. }
  65. return 0;
  66. }
  67.  
Runtime error #stdin #stdout #stderr 0s 11288KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::ios_base::failure'
  what():  basic_filebuf::underflow error reading the file