結果

問題 No.2873 Kendall's Tau
ユーザー yuusaanyuusaan
提出日時 2024-07-10 22:35:27
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 6,780 bytes
コンパイル時間 6,480 ms
コンパイル使用メモリ 333,668 KB
実行使用メモリ 24,608 KB
最終ジャッジ日時 2024-07-10 22:35:41
合計ジャッジ時間 13,691 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <tuple>
#include <map>
#include<set>
#include<queue>
#include<stack>
#include <unordered_set>
#include<thread>
#include<bits/stdc++.h>

#include <atcoder/all>
#include <cstdio>

// #pragma GCC target("avx")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

//if(a < 0 || h <= a || b < 0 || w <= b)return;
//  string abc = "abcdefghijklmnopqrstuvwxyz";
//  string labc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using mint = modint998244353;
//using mint = modint1000000007;
template<typename T> using pq = priority_queue<T>;//降順?(最大取り出し)
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;//昇順?(最小取り出し)
template<typename T> using vector2 = vector<vector<T>>;
template<typename T> using vector3 = vector<vector<vector<T>>>;
template<typename T> using vector4 = vector<vector<vector<vector<T>>>>;
template<typename T> using vector5 = vector<vector<vector<vector<vector<T>>>>>;
template<typename T> using vector6 = vector<vector<vector<vector<vector<vector<T>>>>>>;
template<typename T> using pairs = pair<T,T>;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define rep1(i,n) for(int i = 1;i <= int(n);i++)
#define repi(i,a,b) for(int i = int(a);i < int(b);i++)
#define repm(i, m, n) for (int i = (m); (i) < int(n);(i)++)
#define repmr(i, m, n) for (int i = (m) - 1; (i) >= int(n);(i)--)
#define rep0(i,n) for(int i = n - 1;i >= 0;i--)
#define rep01(i,n) for(int i = n;i >= 1;i--)




// ユークリッドの互除法による最大公約数算出
ll GCD(ll a,ll b){
    if(b == 0)return a;
    return GCD(b, a % b);
}
//拡張ユークリッドの互除法による(ax + by = GCD(a,b))を満たすx,yの算出
pair<long long, long long> extgcd(long long a, long long b) {
  if (b == 0) return make_pair(1, 0);
  long long x, y;
  tie(y, x) = extgcd(b, a % b);
  y -= a / b * x;
  return make_pair(x, y);
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
    
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
    
    int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
    }
    
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
ll n;

struct UnionFind2 {
    vector2<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
    
    UnionFind2(int N) : par(N,vector<int>(N)) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++)for(int j = 0;j < N;j++) par[i][j] = i * N + j;
    }
    
    int root(int y,int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
        if (par[y][x] == y * n + x) return y * n +x;
        return par[y][x] = root(par[y][x] / n,par[y][x] % n);
    }
    
    void unite(int y0, int x0,int y1,int x1) { // xとyの木を併合
        int rx = root(y0,x0); //xの根をrx
        int ry = root(y1,x1); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx / n][rx % n] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
    }
    
    bool same(int y0, int x0,int y1,int x1) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(y0,x0);
        int ry = root(y1,x1);
        return rx == ry;
    }
};
//座標圧縮
vector<ll> Ccomp(vector<ll> a){
    vector<ll> b = a;
    sort(b.begin(),b.end());
    b.erase(unique(b.begin(),b.end()),b.end());//ダブり消去
    vector<ll> rtn;
    rep(j,a.size()){
        ll pb = lower_bound(b.begin(),b.end(),a[j]) - b.begin();
        rtn.push_back(pb);
    }
    return rtn;
}
/// ここから////////////////////////////////////////////




using F = ll;
using S = ll;
string s;

mint modPow(ll a, ll n, ll mod) { if(mod==1) return 0;ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
void cincout(){
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(15);
}
//seg,遅延segの設定-----ここから
S op(S a,S b){return max(a,b);}//何を求めるか(最大値とか)

S e(){return 0;}//モノイド(初期値)

bool f(int a){return a > 0 ;}//めんどいやつ

//S mapping (F a,S b){return a + b;}//遅延処理

F composition (F a,F b){return a + b;}//遅延中の枝にさらに処理

F id(){return 0;}//遅延のモノイド

vector<int> Op(vector<int> a,vector<int> b){a.insert(a.end(),b.begin(),b.end()); return a;}

vector<int> E(){return vector<int> (0);}

//segここまで
ll mod = 998244353;
mint modPow(mint a,ll n) { if(mod==1) return 0;mint ret = 1; mint p = a; while (n) { if (n & 1) ret = ret * p; p = p * p; n >>= 1; } return ret; }

//nとs以外の変数は都度用意しやがれください。AtCoderではデータ量的にintは全部llでいいかと
int main() {
    cincout();
    cin >> n;
    vector<pairs<ll>> a(n);
    ll R = n * (n-1) / 2,S = n*(n-1) / 2;
    map<int,int> xed,yed;
    multiset<ll> y;
    
    rep(j,n){
        cin >> a[j].first >> a[j].second;
        R -= xed[a[j].first];
        S -= yed[a[j].second];
        xed[a[j].first]++;
        yed[a[j].second]++;
    }

    sort(a.begin(),a.end());
    vector<int> res(0);
    double Q = 0,P = 0;
    rep(j,n){
        if(j != 0){
            if(a[j].first != a[j -1].first){
                for(int j : res){
                    y.insert(j);
                }
                res = {};
            }
        }
        
        auto it = y.lower_bound(a[j].second);
        
        P += distance(y.begin(),it);
        auto it2 = y.upper_bound(a[j].second);
        //cout << *it << " " << *it2 << endl;
        Q += distance(it2,y.end());

        res.push_back(a[j].second);
        //y.insert(a[j].second);
    }
    //cout << P << " " << Q << " " << R << " " << S << endl;

    cout << (P-Q)<< endl;


    return 0;
}
0