Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
1,473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. using namespace std;
  4. int sign(int x)
  5. {
  6.     if (x%2)
  7.     return -1;
  8.     return 1;
  9. }
  10. long long absll(long long x)
  11. {
  12.     if (x>0)
  13.     return x;
  14.     return -x;
  15. }
  16. set<long long> s;
  17. int b[100005];
  18. long long ans(long long x)
  19. {
  20.     set<long long>::iterator it=s.lower_bound(x);
  21.     if (it==s.end())
  22.     it--;
  23.     long long ret=absll((*it)-x);
  24.     if (it!=s.begin())
  25.     it--;
  26.     return min(ret,absll((*it)-x));
  27. }
  28. int main()
  29. {
  30.     int n,m,q;
  31.     scanf("%d%d%d",&n,&m,&q);
  32.     long long sumA=0;
  33.     for (int i=0;i<n;i++)
  34.     {
  35.         int a;
  36.         scanf("%d",&a);
  37.         sumA+=a*sign(i);
  38.     }
  39.     long long cur=0;
  40.     for (int i=0;i<n;i++)
  41.     {
  42.         scanf("%d",&b[i]);
  43.         cur+=sign(i+1)*b[i];
  44.     }
  45.     s.insert(cur);
  46.     for (int i=n;i<m;i++)
  47.     {
  48.         scanf("%d",&b[i]);
  49.         cur+=b[i-n];
  50.         cur=-cur;
  51.         cur+=sign(n)*b[i];
  52.         s.insert(cur);
  53.     }
  54.     printf("%I64d\n",ans(-sumA));
  55.     while (q--)
  56.     {
  57.         int l,r,x;
  58.         scanf("%d%d%d",&l,&r,&x);
  59.         if ((r-l)%2==0)
  60.         {
  61.             if (l%2)
  62.             sumA+=x;
  63.             else
  64.             sumA-=x;
  65.         }
  66.         printf("%I64d\n",ans(-sumA));
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement