結果

問題 No.2462 七人カノン
コンテスト
ユーザー 👑 Nachia
提出日時 2021-05-09 02:38:16
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 1,432 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,148 ms
コンパイル使用メモリ 265,680 KB
実行使用メモリ 17,264 KB
最終ジャッジ日時 2026-06-20 06:49:49
合計ジャッジ時間 11,937 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include "testlib.h"

#include <vector>
#include <iostream>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

const int maxN = 100000;
const int maxQ = 100000;
const int maxT = 100000;

struct Query { int i, t; bool isstarting; };
vector<Query> queries;

int N, Q;
vector<int> playing; // for testing instructions duplicates
int playing_cnt = 0;
double X = 0.0;
vector<double> ansbuf;

int main() {
  registerValidation();

	cout << setprecision(10);

  N = inf.readInt(1,maxN);
  inf.readSpace();
  Q = inf.readInt(1,maxQ);
  inf.readEoln();

  playing.assign(N,0);
  ansbuf.assign(N,0.0);

	rep(q, Q) {
    int i = inf.readInt(1,N);
    inf.readSpace();
    int s = inf.readInt(0,maxT);
    inf.readSpace();
    int t = inf.readInt(0,maxT);
    inf.readEoln();
    ensure(s < t);
		i--;
		queries.push_back({ i,s,true });
		queries.push_back({ i,t,false });
	}

  inf.readEof();

	auto cmp_query_time = [](Query l, Query r)->bool { return l.t < r.t; };
	sort(queries.begin(), queries.end(), cmp_query_time);

	int T = 0;
	for (Query& q : queries) {
		if (playing_cnt != 0) X += double(q.t - T) / playing_cnt;
		if (q.isstarting) {
			ensure(playing[q.i] == 0); // instructions duplicate
      playing[q.i] = 1;
			ansbuf[q.i] -= X;
			playing_cnt++;
		}
		else {
      playing[q.i] = 0;
			ansbuf[q.i] += X;
			playing_cnt--;
		}
		T = q.t;
	}

	rep(i, N) cout << ansbuf[i] << "\n";

	return 0;
}
0