結果

問題 No.1144 Triangles
ユーザー fastmathfastmath
提出日時 2020-07-31 22:44:25
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,479 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 132,232 KB
実行使用メモリ 129,488 KB
最終ジャッジ日時 2023-09-21 01:19:33
合計ジャッジ時間 9,927 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 58 ms
38,860 KB
testcase_20 AC 6 ms
5,148 KB
testcase_21 AC 6 ms
5,140 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 361 ms
129,488 KB
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define double long double
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
const int N = 2007, C = 1e4 + 7, MOD = 1000 * 1000 * 1000 + 7;

int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}   
int fp(int a, int p) {
    int ans = 1, c = a;
    for (int i = 0; (1ll << i) <= p; ++i) {
        if ((p >> i) & 1) ans = mod(ans * c);
        c = mod(c * c);
    }   
    return ans;
}   
int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); }

int n, ans = 0;
struct Point { 
    int x, y; 
    bool operator < (Point p) { return (y < p.y) || (y == p.y && x > p.x); }
} a[N];
int cp(int x1, int y1, int x2, int y2) { return x1 * y2 - y1 * x2; }
struct Line {
    int x, y, i, j;
    bool operator < (Line l) { 
        int t = cp(x, y, l.x, l.y);
        return t > 0 || (t == 0 && i < l.i) || (t == 0 && i == l.i && j < l.j); 
    }
};  

struct Fen {
int f[N];
void clear() {
    for (int i = 0; i < N; ++i) f[i] = 0;
}   
void add(int i, int x) {
    for (; i < N; i |= i + 1) 
        f[i] += x;
}   
int get(int i) {
    int ans = 0;
    for (; i >= 0; i &= i + 1, --i) ans += f[i];
    return ans;
}   
int get(int l, int r) {
    return get(r) - get(l - 1);
}   
} fx, fy;


int pos[N];
Point ord[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i].x >> a[i].y; a[i].x += C; a[i].y += C; }
    sort(a, a + n);

    for (int i = 0; i < n; ++i)
        ord[i] = a[i];

    vector <Line> l;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            l.app({a[j].x - a[i].x, a[j].y - a[i].y, i, j});
        }
    }
    for (int i = 0; i < n; ++i) pos[i] = i;
    sort(all(l));
    int ptr = 0;

    for (int i = 0; i < n; ++i) {
        fx.add(i, a[i].x);
        fy.add(i, a[i].y);
    }   

    while (ptr < l.size()) {
        int t = ptr;
        vector <Line> mem;
        while (ptr < l.size() && cp(l[t].x, l[t].y, l[ptr].x, l[ptr].y) == 0) {
            auto &e = l[ptr];
            mem.app(e);
            swap(pos[e.i], pos[e.j]);

            fx.add(pos[e.i], ord[pos[e.j]].x-ord[pos[e.i]].x);
            fy.add(pos[e.i], ord[pos[e.j]].y-ord[pos[e.i]].y);

            fx.add(pos[e.j], ord[pos[e.i]].x-ord[pos[e.j]].x);
            fy.add(pos[e.j], ord[pos[e.i]].y-ord[pos[e.j]].y);

            swap(ord[pos[e.i]], ord[pos[e.j]]);
            ++ptr;
        }        
        for (auto e : mem) {
            int j = e.i, k = e.j;
            int C = mod(a[j].x * a[k].y - a[j].y * a[k].x);
            int A = mod(a[j].y - a[k].y);
            int B = mod(a[k].x - a[j].x);

            int l = -1, r = n;
            while (l < r - 1) {
                int m = (l + r) >> 1;
                if (C + ord[m].x * A + ord[m].y * B < 0) 
                    l = m;
                else
                    r = m;
            }   

            int lx = fx.get(l);
            int ly = fy.get(l);
            ans -= C * (l + 1);
            ans -= A * lx;
            ans -= B * ly;
            ans = mod(ans);

            ans += C * (n - l - 1);
            ans += A * (fx.get(n) - lx);
            ans += B * (fy.get(n) - ly);
            ans = mod(ans);
        }
    }
    cout << dv(ans, 3) << '\n';
} 
0