結果
| 問題 | 
                            No.1919 Many Monster Battles
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Nachia
                         | 
                    
| 提出日時 | 2022-04-29 22:57:55 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 275 ms / 2,000 ms | 
| コード長 | 1,458 bytes | 
| コンパイル時間 | 1,160 ms | 
| コンパイル使用メモリ | 92,728 KB | 
| 最終ジャッジ日時 | 2025-01-28 23:44:44 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 32 | 
ソースコード
#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;
            
            
            
        
            
Nachia