結果

問題 No.2462 七人カノン
ユーザー milanis48663220milanis48663220
提出日時 2023-09-08 21:44:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 966 ms / 2,000 ms
コード長 3,637 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 131,788 KB
実行使用メモリ 21,388 KB
最終ジャッジ日時 2023-09-08 21:45:12
合計ジャッジ時間 19,986 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,708 KB
testcase_01 AC 7 ms
7,772 KB
testcase_02 AC 6 ms
7,776 KB
testcase_03 AC 98 ms
8,192 KB
testcase_04 AC 88 ms
8,192 KB
testcase_05 AC 95 ms
7,800 KB
testcase_06 AC 93 ms
8,080 KB
testcase_07 AC 89 ms
7,680 KB
testcase_08 AC 59 ms
8,124 KB
testcase_09 AC 56 ms
8,176 KB
testcase_10 AC 46 ms
7,940 KB
testcase_11 AC 95 ms
8,304 KB
testcase_12 AC 90 ms
8,076 KB
testcase_13 AC 892 ms
20,656 KB
testcase_14 AC 922 ms
21,104 KB
testcase_15 AC 859 ms
20,940 KB
testcase_16 AC 966 ms
21,344 KB
testcase_17 AC 947 ms
21,388 KB
testcase_18 AC 379 ms
17,384 KB
testcase_19 AC 376 ms
17,308 KB
testcase_20 AC 895 ms
18,584 KB
testcase_21 AC 906 ms
18,720 KB
testcase_22 AC 883 ms
18,724 KB
testcase_23 AC 903 ms
18,316 KB
testcase_24 AC 697 ms
20,512 KB
testcase_25 AC 961 ms
20,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/lazysegtree>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}


template<typename T, int N, int M>
class Matrix {
    public:
    array<array<T, M>, N> dat;
    Matrix(T val) {
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                dat[i][j] = val;
            }
        }
    }

    Matrix(array<array<T, M>, N> dat): dat(dat){  }
    array<T, M>& operator[](int x) {
        return dat[x];
	}
};

template<typename T, int N, int M, int K>
Matrix<T, N, K> operator*(Matrix<T, N, M> a, Matrix<T, M, K> b){
    Matrix<T, N, K> c(T(0));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < K; j++){
            for(int k = 0; k < M; k++){
                c.dat[i][j] += a.dat[i][k]*b.dat[k][j];
            }
        }
    }
    return c;
}

template<typename T, int N, int M>
Matrix<T, N, M> operator+(Matrix<T, N, M> a, Matrix<T, N, M> b){
    Matrix<T, N, M> c(T(0));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            c.dat[i][j] += a.dat[i][j]+b.dat[i][j];
        }
    }
    return c;
}


using Mat = Matrix<double, 2, 2>;
using Vec = Matrix<double, 2, 1>;

const int T = 100005;

Vec op(Vec x, Vec y){
    return x+y;
}

Vec e(){
    return Vec(0);
}

Vec mapping(Mat f, Vec x){
    return f*x;
}

Mat composition(Mat f, Mat g){
    return f*g;
}

Mat make_id(){
    Mat ans(0);
    ans[0][0] = 1;
    ans[1][1] = 1;
    return ans;
}

Mat _id = make_id();

Mat id(){
    return _id;
}

using Seg = atcoder::lazy_segtree<Vec, op, e, Mat, mapping, composition, id>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, q; cin >> n >> q;
    vector<vector<int>> starts(T);
    vector<vector<int>> ends(T);
    for(int i = 0; i < q; i++){
        int j, s, t; cin >> j >> s >> t; j--;
        starts[s].push_back(j);
        ends[t].push_back(j);
    }
    int sum = 0;
    Seg seg(n);
    for(int t = 0; t < T; t++){
        for(int i: starts[t]){
            auto v = seg.get(i);
            v[1][0] = 1;
            seg.set(i, v);
            sum++;
        }
        for(int i: ends[t]){
            auto v = seg.get(i);
            v[1][0] = 0;
            seg.set(i, v);
            sum--;
        }
        if(sum != 0){
            double x = 1.0/(double)sum;
            Mat m = id();
            m[0][1] = x;
            seg.apply(0, n, m);
        }
        
    }
    for(int i = 0; i < n; i++){
        cout << seg.get(i)[0][0] << endl;
    }
}
0