結果

問題 No.1649 Manhattan Square
ユーザー chocoruskchocorusk
提出日時 2021-08-13 22:11:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 329 ms / 3,000 ms
コード長 2,366 bytes
コンパイル時間 4,081 ms
コンパイル使用メモリ 195,368 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-14 18:14:16
合計ジャッジ時間 18,047 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 5 ms
6,812 KB
testcase_03 AC 6 ms
6,940 KB
testcase_04 AC 5 ms
6,944 KB
testcase_05 AC 5 ms
6,944 KB
testcase_06 AC 5 ms
6,940 KB
testcase_07 AC 306 ms
9,600 KB
testcase_08 AC 312 ms
9,600 KB
testcase_09 AC 305 ms
9,472 KB
testcase_10 AC 299 ms
9,472 KB
testcase_11 AC 311 ms
9,600 KB
testcase_12 AC 276 ms
7,296 KB
testcase_13 AC 291 ms
8,448 KB
testcase_14 AC 289 ms
7,680 KB
testcase_15 AC 286 ms
7,936 KB
testcase_16 AC 272 ms
7,168 KB
testcase_17 AC 273 ms
7,040 KB
testcase_18 AC 272 ms
6,944 KB
testcase_19 AC 298 ms
7,808 KB
testcase_20 AC 285 ms
7,296 KB
testcase_21 AC 302 ms
8,448 KB
testcase_22 AC 316 ms
9,472 KB
testcase_23 AC 308 ms
9,600 KB
testcase_24 AC 317 ms
9,472 KB
testcase_25 AC 317 ms
9,600 KB
testcase_26 AC 308 ms
9,472 KB
testcase_27 AC 310 ms
9,472 KB
testcase_28 AC 321 ms
9,472 KB
testcase_29 AC 315 ms
9,600 KB
testcase_30 AC 323 ms
9,472 KB
testcase_31 AC 320 ms
9,472 KB
testcase_32 AC 314 ms
9,472 KB
testcase_33 AC 327 ms
9,472 KB
testcase_34 AC 320 ms
9,600 KB
testcase_35 AC 316 ms
9,600 KB
testcase_36 AC 318 ms
9,600 KB
testcase_37 AC 317 ms
9,472 KB
testcase_38 AC 329 ms
9,600 KB
testcase_39 AC 316 ms
9,472 KB
testcase_40 AC 307 ms
9,600 KB
testcase_41 AC 304 ms
9,472 KB
testcase_42 AC 282 ms
9,600 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
template<typename T>
struct BIT{
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){ //[0, i)
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    T sum(int l, int r){ //[l, r)
        return sum(r)-sum(l);
    }
    void add(int i, T x){
        i++;
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
using mint=modint998244353;
int n;
int x[200020], y[200020];
int main()
{
    cin>>n;
    vector<int> ind(n);
    for(int i=0; i<n; i++){
        cin>>x[i]>>y[i];
        ind[i]=i;
    }
    mint sx2=0, sx=0, sy2=0, sy=0;
    for(int i=0; i<n; i++){
        sx+=mint(x[i]);
        sx2+=mint(x[i])*mint(x[i]);
        sy+=mint(y[i]);
        sy2+=mint(y[i])*mint(y[i]);
    }
    mint ans=sx2*n-sx*sx+sy2*n-sy*sy;
    vector<int> vy(n);
    for(int i=0; i<n; i++){
        vy[i]=y[i];
    }
    sort(ind.begin(), ind.end(), [&](int i,int j){ return x[i]<x[j];});
    sort(vy.begin(), vy.end());
    vy.erase(unique(vy.begin(), vy.end()), vy.end());
    int m=vy.size();
    BIT<mint> bit(m), bitx(m), bity(m), bitxy(m);
    mint ans1=0;
    mint c0=0, sx0=0, sy0=0, sxy=0;
    for(auto i:ind){
        int t=lower_bound(vy.begin(), vy.end(), y[i])-vy.begin();
        ans1+=mint(x[i])*mint(y[i])*(2*bit.sum(t)-c0);
        ans1-=mint(y[i])*(2*bitx.sum(t)-sx0);
        ans1-=mint(x[i])*(2*bity.sum(t)-sy0);
        ans1+=(2*bitxy.sum(t)-sxy);
        bit.add(t, 1);
        bitx.add(t, x[i]);
        bity.add(t, y[i]);
        bitxy.add(t, mint(x[i])*mint(y[i]));
        c0++;
        sx0+=x[i];
        sy0+=y[i];
        sxy+=mint(x[i])*mint(y[i]);
    }
    ans+=2*ans1;
    cout<<ans.val()<<endl;
    return 0;
}
0