結果

問題 No.2462 七人カノン
ユーザー InTheBloomInTheBloom
提出日時 2023-09-08 22:49:02
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 6,093 ms
コンパイル使用メモリ 209,452 KB
実行使用メモリ 15,704 KB
最終ジャッジ日時 2023-09-08 22:49:27
合計ジャッジ時間 13,663 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,088 KB
testcase_01 AC 4 ms
6,380 KB
testcase_02 AC 4 ms
6,484 KB
testcase_03 AC 6 ms
5,692 KB
testcase_04 AC 5 ms
6,160 KB
testcase_05 AC 5 ms
6,656 KB
testcase_06 AC 5 ms
6,092 KB
testcase_07 AC 5 ms
6,108 KB
testcase_08 AC 10 ms
5,620 KB
testcase_09 AC 9 ms
5,584 KB
testcase_10 AC 5 ms
7,412 KB
testcase_11 AC 6 ms
6,620 KB
testcase_12 AC 5 ms
5,564 KB
testcase_13 AC 175 ms
7,948 KB
testcase_14 AC 171 ms
15,532 KB
testcase_15 AC 152 ms
14,948 KB
testcase_16 AC 177 ms
15,704 KB
testcase_17 AC 188 ms
8,216 KB
testcase_18 AC 142 ms
7,460 KB
testcase_19 AC 142 ms
7,236 KB
testcase_20 AC 143 ms
15,680 KB
testcase_21 AC 141 ms
13,944 KB
testcase_22 AC 140 ms
8,252 KB
testcase_23 AC 140 ms
8,200 KB
testcase_24 AC 144 ms
7,700 KB
testcase_25 AC 147 ms
13,212 KB
権限があれば一括ダウンロードができます

ソースコード

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