Advertisement
Guest User

Untitled

a guest
May 7th, 2018
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3.  
  4. using namespace std;
  5.  
  6. const int N = 1007;
  7. const int MOD = 998244353;
  8.  
  9. int tests,current_case;
  10. int pw[N];
  11. int n,ans;
  12. pair < int, int > a[N];
  13.  
  14. long long s(pair < int, int > a, pair < int, int > b, pair < int, int > c) {
  15.   return (a.first-b.first)*1ll*(a.second+b.second) + (b.first-c.first)*1ll*(b.second+c.second) + (c.first-a.first)*1ll*(c.second+a.second);
  16. }
  17.  
  18. struct cmp {
  19.   pair < int, int > pt;
  20.  
  21.   cmp(){}
  22.   cmp(pair < int, int > a): pt(a) {}
  23.  
  24.   bool operator () (const pair < int, int > &a, const pair < int, int > &b) const {
  25.     return s(pt,a,b)>0;
  26.   }
  27. };
  28.  
  29. int get_mod(long long a) {
  30.   if(a>=0) return a%MOD;
  31.   return MOD-abs(a)%MOD;
  32. }
  33.  
  34. void solve(pair < int, int > pt, vector < pair < int, int > > left, vector < pair < int, int > > right) {
  35.   sort(left.begin(),left.end(),cmp(pt));
  36.   sort(right.begin(),right.end(),cmp(pt));
  37.  
  38.   int i,j,cnt;
  39.   long long curr;
  40.  
  41.   //Solve for the right side
  42.   j=0;
  43.   for(i=0;i<(int)(right.size());i++) {
  44.     while(j<(int)(left.size()) && s(pt,right[i],left[j])>0) ++j;
  45.  
  46.     cnt=j+(int)(right.size())-i-1;
  47.    
  48.     curr=get_mod((pt.first-right[i].first)*1ll*(pt.second+right[i].second));
  49.     curr=curr*(pw[cnt]-1)%MOD;
  50.  
  51.     ans+=curr;
  52.     ans%=MOD;
  53.   }
  54.  
  55.   //Solve for the left side
  56.   j=0;
  57.   for(i=0;i<(int)(left.size());i++) {
  58.     while(j<(int)(right.size()) && s(pt,left[i],right[j])>0) ++j;
  59.  
  60.     cnt=j+(int)(left.size())-i-1;
  61.  
  62.     curr=get_mod((pt.first-left[i].first)*1ll*(pt.second+left[i].second));
  63.     curr=curr*(pw[cnt]-1)%MOD;
  64.  
  65.     ans+=curr;
  66.     ans%=MOD;
  67.   }
  68. }
  69.  
  70. int main() {
  71.   ios_base::sync_with_stdio(false);
  72.   cin.tie(NULL);
  73.   int i,j;
  74.  
  75.   pw[0]=1;
  76.   for(i=1;i<N;i++) {
  77.     pw[i]=pw[i-1]*2%MOD;
  78.   }
  79.  
  80.   scanf("%d", &tests);
  81.   for(current_case=1;current_case<=tests;current_case++) {
  82.     scanf("%d", &n);
  83.     for(i=1;i<=n;i++) {
  84.       scanf("%d %d", &a[i].first, &a[i].second);
  85.     }
  86.  
  87.     sort(a+1,a+1+n);
  88.  
  89.     ans=0;
  90.  
  91.     for(i=1;i<=n;i++) {
  92.       vector < pair < int, int > > left,right;
  93.  
  94.       for(j=1;j<i;j++) left.push_back(a[j]);
  95.       for(j=i+1;j<=n;j++) right.push_back(a[j]);
  96.      
  97.       solve(a[i],left,right);
  98.     }
  99.  
  100.     printf("%d\n", ans);
  101.   }
  102.  
  103.   return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement