Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define endl '\n'
- using namespace std;
- const int N = 1007;
- const int MOD = 998244353;
- int tests,current_case;
- int pw[N];
- int n,ans;
- pair < int, int > a[N];
- long long s(pair < int, int > a, pair < int, int > b, pair < int, int > c) {
- 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);
- }
- struct cmp {
- pair < int, int > pt;
- cmp(){}
- cmp(pair < int, int > a): pt(a) {}
- bool operator () (const pair < int, int > &a, const pair < int, int > &b) const {
- return s(pt,a,b)>0;
- }
- };
- int get_mod(long long a) {
- if(a>=0) return a%MOD;
- return MOD-abs(a)%MOD;
- }
- void solve(pair < int, int > pt, vector < pair < int, int > > left, vector < pair < int, int > > right) {
- sort(left.begin(),left.end(),cmp(pt));
- sort(right.begin(),right.end(),cmp(pt));
- int i,j,cnt;
- long long curr;
- //Solve for the right side
- j=0;
- for(i=0;i<(int)(right.size());i++) {
- while(j<(int)(left.size()) && s(pt,right[i],left[j])>0) ++j;
- cnt=j+(int)(right.size())-i-1;
- curr=get_mod((pt.first-right[i].first)*1ll*(pt.second+right[i].second));
- curr=curr*(pw[cnt]-1)%MOD;
- ans+=curr;
- ans%=MOD;
- }
- //Solve for the left side
- j=0;
- for(i=0;i<(int)(left.size());i++) {
- while(j<(int)(right.size()) && s(pt,left[i],right[j])>0) ++j;
- cnt=j+(int)(left.size())-i-1;
- curr=get_mod((pt.first-left[i].first)*1ll*(pt.second+left[i].second));
- curr=curr*(pw[cnt]-1)%MOD;
- ans+=curr;
- ans%=MOD;
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int i,j;
- pw[0]=1;
- for(i=1;i<N;i++) {
- pw[i]=pw[i-1]*2%MOD;
- }
- scanf("%d", &tests);
- for(current_case=1;current_case<=tests;current_case++) {
- scanf("%d", &n);
- for(i=1;i<=n;i++) {
- scanf("%d %d", &a[i].first, &a[i].second);
- }
- sort(a+1,a+1+n);
- ans=0;
- for(i=1;i<=n;i++) {
- vector < pair < int, int > > left,right;
- for(j=1;j<i;j++) left.push_back(a[j]);
- for(j=i+1;j<=n;j++) right.push_back(a[j]);
- solve(a[i],left,right);
- }
- printf("%d\n", ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement