Advertisement
erfanul007

Untitled

Jan 15th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. typedef unsigned long long int ull;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int> pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define pb push_back
  14. #define pob pop_back
  15. #define mp make_pair
  16. #define ff first
  17. #define ss second
  18. #define loop1(i,n) for(int i=1; i<=int(n); i++)
  19. #define loop(i,y) for(int i=0; i<int(y); i++)
  20. #define rloop(i,y) for(int i=int(y); i>0; i--)
  21. #define rloop1(i,y) for(int i=int(y)-1; i>=0; i--)
  22. #define read() freopen("input.txt", "r", stdin)
  23. #define write() freopen("output.txt", "w", stdout)
  24. #define cspf(i) printf("Case %d: ", i)
  25. #define all(v) v.begin(),v.end()
  26. /// Constants
  27. #define eps 1e-9
  28. #define PI acos(-1.0) // 3.1415926535897932
  29.  
  30. int main()
  31. {
  32. int t;
  33. cin>>t;
  34. loop1(i,t){
  35. ll l,r,d,sm;
  36. cin>>l>>r;
  37. if(l%2==0 && r%2==0){
  38. d=r-l;
  39. d/=2;
  40. sm=l+d;
  41. cout<<sm<<endl;
  42. continue;
  43. }
  44. if(l%2==1 && r%2==1){
  45. d=r-l;
  46. d/=2;
  47. sm=l+d;
  48. sm=-sm;
  49. cout<<sm<<endl;
  50. continue;
  51. }
  52. if(l%2==0 && r%2==1){
  53. d=r-l;
  54. d=(d+1)/2;
  55. sm=-d;
  56. cout<<sm<<endl;
  57. continue;
  58. }
  59. if(l%2==1 && r%2==0){
  60. d=r-l;
  61. d=(d+1)/2;
  62. sm=d;
  63. cout<<sm<<endl;
  64. continue;
  65. }
  66. }
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement