結果

問題 No.2873 Kendall's Tau
ユーザー wsrtrtwsrtrt
提出日時 2024-09-06 23:06:35
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 608 ms / 4,500 ms
コード長 13,970 bytes
コンパイル時間 3,955 ms
コンパイル使用メモリ 277,732 KB
実行使用メモリ 26,452 KB
最終ジャッジ日時 2024-09-06 23:07:10
合計ジャッジ時間 13,151 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,568 KB
testcase_01 AC 4 ms
7,700 KB
testcase_02 AC 3 ms
7,712 KB
testcase_03 AC 4 ms
7,492 KB
testcase_04 AC 4 ms
7,492 KB
testcase_05 AC 3 ms
7,496 KB
testcase_06 AC 4 ms
7,540 KB
testcase_07 AC 502 ms
21,052 KB
testcase_08 AC 608 ms
25,512 KB
testcase_09 AC 524 ms
21,032 KB
testcase_10 AC 593 ms
26,452 KB
testcase_11 AC 502 ms
20,936 KB
testcase_12 AC 574 ms
25,500 KB
testcase_13 AC 137 ms
12,220 KB
testcase_14 AC 483 ms
23,404 KB
testcase_15 AC 75 ms
11,112 KB
testcase_16 AC 73 ms
10,576 KB
testcase_17 AC 344 ms
18,064 KB
testcase_18 AC 268 ms
17,408 KB
testcase_19 AC 345 ms
18,292 KB
testcase_20 AC 75 ms
10,740 KB
testcase_21 AC 276 ms
16,528 KB
testcase_22 AC 108 ms
12,140 KB
testcase_23 AC 305 ms
16,788 KB
testcase_24 AC 33 ms
8,956 KB
testcase_25 AC 72 ms
10,548 KB
testcase_26 AC 364 ms
17,704 KB
testcase_27 AC 235 ms
15,380 KB
testcase_28 AC 491 ms
21,280 KB
testcase_29 AC 492 ms
23,020 KB
testcase_30 AC 54 ms
9,992 KB
testcase_31 AC 103 ms
11,144 KB
testcase_32 AC 289 ms
16,636 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:397:13: warning: 'q' may be used uninitialized [-Wmaybe-uninitialized]
  397 |     cout<<(p-q)/sqrt(r*s)<<el;
      |           ~~^~~
main.cpp:351:14: note: 'q' was declared here
  351 |     double p,q,r,s;
      |              ^
main.cpp:397:13: warning: 'p' may be used uninitialized [-Wmaybe-uninitialized]
  397 |     cout<<(p-q)/sqrt(r*s)<<el;
      |           ~~^~~
main.cpp:351:12: note: 'p' was declared here
  351 |     double p,q,r,s;
      |            ^
main.cpp:397:21: warning: 's' may be used uninitialized [-Wmaybe-uninitialized]
  397 |     cout<<(p-q)/sqrt(r*s)<<el;
      |                 ~~~~^~~~~
main.cpp:351:18: note: 's' was declared here
  351 |     double p,q,r,s;
      |                  ^
main.cpp:397:21: warning: 'r' may be used uninitialized [-Wmaybe-uninitialized]
  397 |     cout<<(p-q)/sqrt(r*s)<<el;
      |                 ~~~~^~~~~
main.cpp:351:16: note: 'r' was declared here
  351 |     double p,q,r,s;
      |                ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define INT(...)                                                                                                                                               \
    int __VA_ARGS__;                                                                                                                                           \
    IN(__VA_ARGS__)
#define LL(...)                                                                                                                                                \
    ll __VA_ARGS__;                                                                                                                                            \
    IN(__VA_ARGS__)
#define STR(...)                                                                                                                                               \
    string __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define CHR(...)                                                                                                                                               \
    char __VA_ARGS__;                                                                                                                                          \
    IN(__VA_ARGS__)
#define DBL(...)                                                                                                                                               \
    double __VA_ARGS__;                                                                                                                                        \
    IN(__VA_ARGS__)
#define ll long long
#define cout std::cout
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define pii pair<int, int>
#define pll pair<long long,long long>
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<long long>
#define vc vector<char>
#define vvi vector<vector<int>> 
#define vec(type, name, ...) vector<type> name(__VA_ARGS__)
#define VEC(type, name, size)                                                                                                                                  \
    vector<type> name(size);                                                                                                                                   \
    IN(name)
int scan() { return getchar(); }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(string &a) { cin >> a; }
template <class T, class S> void scan(pair<T, S> &p) { scan(p.first), scan(p.second); }
template <class T> void scan(vector<T> &);
template <class T> void scan(vector<T> &a) {
    for(auto &i : a) scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {
    scan(head);
    IN(tail...);
}
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w)                                                                                                                                   \
    vector<vector<type>> name(h, vector<type>(w));                                                                                                             \
    IN(name)
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)                                                                                                                         \
    vector<vector<vector<vector<type>>>> name(a, vector<vector<vector<type>>>(b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> pair<T, T> operator-(const pair<T, T> &x, const pair<T, T> &y) { return pair<T, T>(x.ff - y.ff, x.ss - y.ss); }
template <class T> pair<T, T> operator+(const pair<T, T> &x, const pair<T, T> &y) { return pair<T, T>(x.ff + y.ff, x.ss + y.ss); }
template <class T> pair<T, T> operator&(const pair<T, T> &l, const pair<T, T> &r) { return pair<T, T>(max(l.ff, r.ff), min(l.ss, r.ss)); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
//座標圧縮
template <typename T> void zip(vector<T> &x) {
    vector<T> y = x;
    UNIQUE(y);
    for(int i = 0; i < x.size(); ++i) { x[i] = lb(y, x[i]); }
}
template <class T> T ceil(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <class T> T floor(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? x / y : (x + y - 1) / y);
}
long long POW(long long x, int n) {
    long long res = 1LL;
    for(; n; n >>= 1, x *= x)
        if(n & 1) res *= x;
    return res;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//return 0<=a&&a<h&&0<=b&&b<w;
inline bool ingrid(int a,int b,int h,int w){return 0<=a&&a<h&&0<=b&&b<w;}
//return return 0<=a&&a<n;
inline bool inl(int a,int n){return 0<=a&&a<n;}
// bit 演算系
ll pow2(int i) { return 1LL << i; }
int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
int lowbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }
int lowbit(ll a) { return a == 0 ? 64 : __builtin_ctzll(a); }
// int allbit(int n) { return (1 << n) - 1; }
ll allbit(ll n) { return (1LL << n) - 1; }
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }
int in() {
    int x;
    cin >> x;
    return x;
}
ll lin() {
    unsigned long long x;
    cin >> x;
    return x;
}
long long sqrtll(long long x) {
    assert(x >= 0);
    long long rev = sqrt(x);
    while(rev * rev > x) --rev;
    while((rev+1) * (rev+1)<=x) ++rev;
    return rev;
}
int logN(long long n){
    int ret=1;
    while((1LL<<ret)<n)ret++;
    return ret;
}
const double PI=3.1415926535897932384626433832795028841971;
const ll MOD = 998244353;
const int INFI = numeric_limits<int>::max() / 2; const long long INFL = numeric_limits<long long>::max() / 2;

template<class T>
void debug(vector<T> a){
    rep(i,0,(int)a.size()){
        cout<<a[i]<<' ';
    }
    cout<<endl;
    return;
}
template<typename T>
bool isPalin(T s){
    rep(i,0,s.size()){
        if(s[i]!=s[s.size()-i-1])return false;
    }
    return true;
}

template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;
public:
    u64 a;
    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &val() noexcept { return a; }
    constexpr const u64 &val() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
        if (exp % 2) {
          *this *= rhs;
        }
        rhs *= rhs;
        exp /= 2;
        }
        return *this;
    }
    friend bool operator==(const modint& a,const modint& b) { return a.val()==b.val(); }
    friend bool operator!=(const modint& a,const modint& b) { return a.val()!=b.val(); }
};
using mint9=modint<998244353>;
using mint1=modint<1000000007>;
constexpr pii dx4[4] = {pii{-1, 0}, pii{0, 1}, pii{1, 0}, pii{0, -1}};
constexpr pii dx8[8] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
constexpr pii dx[8] = { {-1, 0}, {0, -1}};

#define el "\n"
#define endl "\n"
#define inf INFINITY
#define fastio std::cin.sync_with_stdio(false);std::cin.tie(nullptr);cout<<fixed<<setprecision(16);



template< typename T, typename F >
struct SegmentTree {
    int n, sz;
    vector< T > seg;
    const F f;
    const T ti;
    SegmentTree() = default;
    explicit SegmentTree(int n, const F f, const T &ti) : n(n), f(f), ti(ti) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2 * sz, ti);
    }
    explicit SegmentTree(const vector< T > &v, const F f, const T &ti) :
        SegmentTree((int) v.size(), f, ti) {
        build(v);
    }
    void build(const vector< T > &v) {
        assert(n == (int) v.size());
        for(int k = 0; k < n; k++) seg[k + sz] = v[k];
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }
    void set(int k, const T &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }   
    }
    T get(int k) const {
        return seg[k + sz];
    }
    T operator[](const int &k) const {
        return get(k);
    }
    void apply(int k, const T &x) {
        k += sz;
        seg[k] = f(seg[k], x);
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }
    T prod(int l, int r) const {
        T L = ti, R = ti;
        for(l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
            if(l & 1) L = f(L, seg[l++]);
            if(r & 1) R = f(seg[--r], R);
        }
        return f(L, R);
    }
    T all_prod() const {
        return seg[1];
    }
    template< typename C >
    int find_first(int l, const C &check) const {
        if(l >= n) return n;
        l += sz;
        T sum = ti;
        do {
            while((l & 1) == 0) l >>= 1;
            if(check(f(sum, seg[l]))){ 
            while(l < sz) {
                l <<= 1;
                auto nxt = f(sum, seg[l]);
                if(not check(nxt)) {
                    sum = nxt;
                    l++;
                }
            }
            return l + 1 - sz;
        }
        sum = f(sum, seg[l++]);
        } while((l & -l) != l);
        return n;
    }

    template< typename C >
    int find_last(int r, const C &check) const {
        if(r <= 0) return -1;
        r += sz;
        T sum = ti;
        do {
            r--;
            while(r > 1 and (r & 1)) r >>= 1;
            if(check(f(seg[r], sum))) {
                while(r < sz) {
                    r = (r << 1) + 1;
                    auto nxt = f(seg[r], sum);
                    if(not check(nxt)) {
                        sum = nxt;
                        r--;
                    }
                }
                return r - sz;
            }
            sum = f(seg[r], sum);
        } while((r & -r) != r);
        return -1;
    } 
};


template< typename T, typename F >
SegmentTree< T, F > get_segment_tree(int N, const F &f, const T &ti) {
    return SegmentTree<T,F>{N, f, ti};
}

template< typename T, typename F >
SegmentTree< T, F > get_segment_tree(const vector< T > &v, const F &f, const T &ti) {
    return SegmentTree<T,F>{v, f, ti};
}


int main(){
    fastio;
    INT(n);
    vec(int,x,n);
    vec(int,y,n);
    rep(i,0,n)cin>>x[i]>>y[i];
    zip(y);
    double p,q,r,s;
    map<int,int> xmp,ymp;
    map<int,int> za;
    rep(i,0,n){
        xmp[x[i]]++;
        ymp[y[i]]++;
    }
    rep(i,0,n){
        xmp[x[i]]--;
        ymp[y[i]]--;
        r+=(n-1-i)-xmp[x[i]];
        s+=(n-1-i)-ymp[y[i]];
    }
    auto seg=get_segment_tree(300000,[](int a,int b){return a+b;},0);
    vector<pii> xy(n);
    rep(i,0,n)xy[i]=pii(x[i],y[i]);
    sort(all(xy));
    rep(i,0,n){
        queue<int> que;que.push(i);
        //p+=seg.prod(0,xy[i].ss);
        //q+=seg.prod(xy[i].ss+1,300000);
        while(i+1<n&&xy[i].ff==xy[i+1].ff){
            i++;
            //p+=seg.prod(0,xy[i].ss);
            //q+=seg.prod(xy[i].ss+1,300000);
            que.push(i);
        }
        while(!que.empty()){
            int j=que.front();que.pop();
            seg.apply(xy[j].ss,1);
        }
    }
    rep(i,0,n){
        seg.apply(xy[i].ss,-1);
        queue<int> que;que.push(i);
        while(i+1<n&&xy[i].ff==xy[i+1].ff){
            i++;
            seg.apply(xy[i].ss,-1);
            que.push(i);
        }
        while(!que.empty()){
            int j=que.front();que.pop();
            q+=seg.prod(0,xy[j].ss);
            p+=seg.prod(xy[j].ss+1,300000);
        }
    }
    cout<<(p-q)/sqrt(r*s)<<el;
	return 0;
}
/*

*/
0