結果

問題 No.1919 Many Monster Battles
ユーザー 👑 NachiaNachia
提出日時 2022-04-29 22:57:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 1,458 bytes
コンパイル時間 1,202 ms
コンパイル使用メモリ 95,052 KB
実行使用メモリ 12,524 KB
最終ジャッジ日時 2023-09-11 14:23:33
合計ジャッジ時間 7,366 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 225 ms
12,376 KB
testcase_14 AC 230 ms
11,940 KB
testcase_15 AC 229 ms
12,260 KB
testcase_16 AC 229 ms
11,996 KB
testcase_17 AC 230 ms
11,944 KB
testcase_18 AC 219 ms
12,016 KB
testcase_19 AC 214 ms
12,088 KB
testcase_20 AC 212 ms
11,876 KB
testcase_21 AC 220 ms
12,524 KB
testcase_22 AC 207 ms
12,256 KB
testcase_23 AC 150 ms
12,192 KB
testcase_24 AC 150 ms
11,944 KB
testcase_25 AC 149 ms
11,940 KB
testcase_26 AC 149 ms
12,296 KB
testcase_27 AC 150 ms
12,012 KB
testcase_28 AC 154 ms
12,412 KB
testcase_29 AC 152 ms
12,388 KB
testcase_30 AC 149 ms
12,016 KB
testcase_31 AC 156 ms
12,008 KB
testcase_32 AC 154 ms
12,460 KB
testcase_33 AC 164 ms
11,996 KB
testcase_34 AC 160 ms
12,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#include <atcoder/fenwicktree>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using m32 = atcoder::static_modint<1000000007>;

int N;
vector<pair<int,int>> A;


m32 solve(){
    vector<pair<i64,i64>> Diag;
    for(auto [a,b] : A) Diag.push_back(make_pair(a-b, -(a+b)));
    sort(Diag.begin(), Diag.end());
    for(auto& [y,x] : Diag) x *= -1;
    m32 ans = 0;

    vector<i64> Xsort;
    for(auto& [y,x] : Diag) Xsort.push_back(x);
    sort(Xsort.begin(), Xsort.end());

    atcoder::fenwick_tree<m32> X1(N);
    atcoder::fenwick_tree<m32> X0(N);
    for(auto [y,x] : Diag){
        int xc = lower_bound(Xsort.begin(), Xsort.end(), x) - Xsort.begin();
        ans += X1.sum(0,xc) * m32(x+y);
        ans -= X0.sum(0,xc);
        X1.add(xc, m32(1));
        X0.add(xc, m32(x+y));
    }

    return ans;
}

int main(){
    cin >> N;
    A.resize(N);
    rep(i,N) cin >> A[i].first;
    rep(i,N) cin >> A[i].second;

    m32 ans[2];

    rep(t,2){
        ans[t] = solve().val();
        for(auto& [u,v] : A) swap(u,v);
    }

    cout << ans[0].val() << ' ' << ans[1].val() << '\n';
    return 0;
}

struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0