Advertisement
Guest User

Problem B - Round 53

a guest
Jan 26th, 2011
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1.  
  2. /*
  3.     RosyIsh's code!
  4.    
  5. */
  6.  
  7.  
  8. #include<iostream>
  9. #include <algorithm>
  10. #include <bitset>
  11. #include <cassert>
  12. #include <cctype>
  13. #include <cmath>
  14. #include <cstdio>
  15. #include <cstdlib>
  16. #include <cstring>
  17. #include <ctime>
  18. #include <deque>
  19. #include <functional>
  20. #include <iomanip>
  21. #include <iostream>
  22. #include <list>
  23. #include <map>
  24. #include <numeric>
  25. #include <queue>
  26. #include <set>
  27. #include <sstream>
  28. #include <stack>
  29. #include <string>
  30. #include <utility>
  31. #include <vector>
  32. #define VI vector<int>
  33. #define PI pair<int,int>
  34. #define PB(x) push_back(x)
  35. #define MP(x,y) make_pair(x,y)
  36. #define fill(a,b) memset((a),(b),sizeof((a)))
  37. #define MX 100003
  38. typedef long long LL;
  39. using namespace std;
  40.  
  41. int times[MX];
  42. LL bit[MX];
  43. LL sum[MX];
  44. VI K;
  45. int n,m,k;
  46.  
  47.  
  48. int main(){
  49.  
  50.     //freopen("out.txt","w",stdout);
  51.     //freopen("in.txt","r",stdin);
  52.  
  53.     scanf("%d %d %d",&n,&m,&k);
  54.    
  55.     for(int i=1;i<=m;i++){
  56.        
  57.         int a,b,c;
  58.         scanf("%d %d %d",&a,&b,&c);
  59.        
  60.         int j = a;
  61.         while(j<n+1){
  62.             times[j]++;
  63.             sum[j]+=c;
  64.             bit[j]+=a;
  65.             j += (j & -j);
  66.         }          
  67.  
  68.         j = b+1;
  69.         while(j<n+1){
  70.             times[j]--;
  71.             sum[j]-=c;
  72.             bit[j]-=a;
  73.             j += (j & -j);
  74.         }
  75.        
  76.        
  77.     }
  78.  
  79.     LL fin = 0;
  80.     for(int i = 0;i<k;i++){
  81.         int x;
  82.         scanf("%d",&x);
  83.         LL ans = 0 , t = 0 , b = 0;
  84.        
  85.         int j = x;
  86.         while(j>0){
  87.             ans+=sum[j];
  88.             t+=times[j];
  89.             b+=bit[j];
  90.             j -= (j & -j);
  91.         }
  92.         ans+=(x*t) - b;
  93.         fin+=ans;
  94.     }
  95.    
  96.         cout<<fin<<endl;
  97.  
  98.  
  99.     return 0;
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement