結果

問題 No.2462 七人カノン
ユーザー InTheBloom
提出日時 2023-09-08 22:49:02
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 5,731 ms
コンパイル使用メモリ 212,864 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-06-26 16:04:33
合計ジャッジ時間 14,349 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

struct trio {
    int I;
    int S;
    int T;
}

void main () {
    int N, Q; readln.read(N, Q);
    trio[] instruct = new trio[](Q);
    foreach (i; 0..Q) {
        with (instruct[i]) {
            readln.read(I, S, T);
            I--;
        }
    }

    solve(N, Q, instruct);
}

void solve (int N, int Q, trio[] instruct) {
    // 時間が全部配列に乗るので、imos的に「ある時間に演奏していた人数」を求めて、あとは累積和でおけw

    const int time = 10^^5+1;
    int[] PlayerCount = new int[](time);
    double[] score = new double[](time);
    score[] = 0;

    // imos
    foreach (i; instruct) {
        PlayerCount[i.S]++;
        PlayerCount[i.T]--;
    }
    foreach (i; 1..time) {
        PlayerCount[i] += PlayerCount[i-1];
    }

    // 重みづけ
    foreach (i; 0..time) {
        if (PlayerCount[i] == 0) continue;
        score[i] = 1./PlayerCount[i];
    }

    // 累積和 ( [0, i)の総和 )
    double[] cum = new double[](time+1);
    cum[] = 0;
    foreach (i; 1..time+1) {
        cum[i] = cum[i-1] + score[i-1];
    }

    // 各クエリから計算
    double[] ans = new double[](N);
    ans[] = 0;

    foreach (i; instruct) {
        ans[i.I] += cum[i.T]-cum[i.S];
    }

    // output
    foreach (a; ans) {
        writeln(format("%.10f", a));
    }
}

void read(T...)(string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}
0