結果

問題 No.3614 Breaking door keys(LITTLE BREAK ver.)
コンテスト
ユーザー ococonomy1
提出日時 2026-08-06 14:42:21
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 441 ms / 2,000 ms
+ 265µs
コード長 6,156 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,257 ms
コンパイル使用メモリ 220,844 KB
実行使用メモリ 32,512 KB
最終ジャッジ日時 2026-08-06 14:42:40
合計ジャッジ時間 11,676 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
サンプル 0 % AC * 3
小課題1 10 % AC * 7
小課題2 20 % AC * 7
小課題3 30 % AC * 7
小課題4 30 % AC * 14
小課題5 10 % AC * 38
合計 2.5 * 100% = 250 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
#define MOD 998244353
//#define MOD 1000000007
#define el '\n'
#define El '\n'
#define YESNO(x) ((x) ? "Yes" : "No")
#define YES YESNO(true)
#define NO YESNO(false)
#define EXIT_ANS(x) {cout << (x) << '\n'; return;}
template <typename T> void inline SORT(T &v){sort(v.begin(),v.end()); return;}
template <typename T> void inline REV(T &v){reverse(v.begin(),v.end()); return;}
template <typename T> void inline VEC_UNIQ(T &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return;}
template <typename T> auto inline MAX(T &v){return *max_element(v.begin(),v.end());}
template <typename T> auto inline MIN(T &v){return *min_element(v.begin(),v.end());}
template <typename T> auto inline SUM(vector<T> &v){T ans = 0; for(int i = 0; i < (int)v.size(); i++)ans += v[i]; return ans;}
template <typename T> void inline DEC(T &v){for(int i = 0; i < (int)v.size(); i++)v[i]--; return;}
template <typename T> void inline INC(T &v){for(int i = 0; i < (int)v.size(); i++)v[i]++; return;}
void inline TEST(void){cerr << "TEST" << endl; return;}
template <typename T,typename S> bool inline chmin(T &x,S y){
    if(x > (T)y){
        x = (T)y;
        return true;
    }
    return false;
}
template <typename T,typename S> bool inline chmax(T &x,S y){
    if(x < (T)y){
        x = (T)y;
        return true;
    }
    return false;
}
template <typename T = long long> vector<T> inline get_vec(int n){
    vector<T> ans(n);
    for(int i = 0; i < n; i++)cin >> ans[i];
    return ans;
}
template <typename T> void inline print_vec(vector<T> &vec,bool kaigyou = false){
    int n = (int)vec.size();
    for(int i = 0; i < n; i++){
        cout << vec[i];
        if(kaigyou || i == n - 1)cout << '\n';
        else cout << ' ';
    }
    if(!n)cout << '\n';
    return;
}
template <typename T> void inline debug_vec(vector<T> &vec,bool kaigyou = false){
    int n = (int)vec.size();
    for(int i = 0; i < n; i++){
        cerr << vec[i];
        if(kaigyou || i == n - 1)cerr << '\n';
        else cerr << ' ';
    }
    if(!n)cerr << '\n';
    return;
}
vector<vector<int>> inline get_graph(int n,int m = -1,bool direct = false,bool decrement = true){
    if(m == -1)m = n - 1;
    vector<vector<int>> g(n);
    while(m--){
        int u,v;
        cin >> u >> v;
        if(decrement)u--,v--;
        g[u].push_back(v);
        if(!direct)g[v].push_back(u);
    }
    return g;
}
template <typename T> vector<vector<pair<T,int>>> inline get_weighted_graph(int n,int m = -1,bool direct = false,bool decrement = true){
    if(m == -1)m = n - 1;
    vector<vector<pair<T,int>>> g(n);
    while(m--){
        int u,v;
        cin >> u >> v;
        if(decrement)u--,v--;
        ll w; cin >> w;
        g[u].push_back(pair(w,v));
        if(!direct)g[v].push_back(pair(w,u));
    }
    return g;
}

// 抽象再帰セグ木?(抽象セグ木の定義分からんな)(遅延ではない)
template <typename T> class ococo_segtree {
    T e = {LLONG_MAX,LLONG_MAX,LLONG_MAX,LLONG_MAX,LLONG_MAX,LLONG_MAX,LLONG_MAX,LLONG_MAX,LLONG_MAX,LLONG_MAX};
    T func(T a, T b) {
        array<ll,20> temp;
        for(int i = 0; i < 10; i++){
            temp[i] = a[i];
            temp[i + 10] = b[i];
        }
        SORT(temp);
        T ans;
        for(int i = 0; i < 10; i++)ans[i] = temp[i];
        return ans;
    }

    T get_minimum2(int a, int b, int k, int l, int r) {
        if(a <= l && r <= b) return rmq[k];
        else if(r <= a || b <= l) return tmax;
        else return func(get_minimum2(a, b, k * 2 + 1, l, (l + r) / 2), get_minimum2(a, b, k * 2 + 2, (l + r) / 2, r));
    }

  public:
    int n;
    T tmax;
    // range minimum query
    vector<T> rmq;

    //(データの大きさ,単位元)
    ococo_segtree(int N) {
        syokica(N);
    }

    // 配列の初期化 O(N)
    void syokica(int a) {
        n = 1;
        tmax = e;
        while(n < a) n *= 2;
        rmq.resize(2 * n - 1);
        for(int i = 0; i < 2 * n - 1; i++) {
            rmq[i] = tmax;
        }
    }

    // a[i]をxにする O(logN)
    void update_num(int i, T x) {
        i += (n - 1);
        rmq[i] = x;
        while(i) {
            i = (i - 1) / 2;
            rmq[i] = func(rmq[i * 2 + 1], rmq[i * 2 + 2]);
        }
    }

    // a[i]にxを加える O(logN)
    void add_num(int i, T x) {
        i += (n - 1);
        rmq[i] += x;
        while(i) {
            i = (i - 1) / 2;
            rmq[i] = func(rmq[i * 2 + 1], rmq[i * 2 + 2]);
        }
    }

    
    //[l,r]の区間演算の取得 O(logN)
    T get_val(int l, int r) {
        return get_minimum2(l, r + 1, 0, 0, n);
    }
};



#define MULTI_TEST_CASE false
void solve(void){
    //問題を見たらまず「この問題設定から言えること」をいっぱい言う
    //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く
    //複数の解法のアイデアを思いついた時は全部メモしておく
    //g++ -D_GLIBCXX_DEBUG -Wall -O2 f.cpp -o o
    int n,q;
    cin >> n >> q;
    vector<ll> s = get_vec(n);
    vector<array<ll,10>> tempvec(n);
    for(int i = 0; i < n; i++){
        tempvec[i][0] = s[i];
        for(int j = 1; j < 10; j++)tempvec[i][j] = LLONG_MAX;
    }
    ococo_segtree<array<ll,10>> sgt(n);
    for(int i = 0; i < n; i++)sgt.update_num(i,tempvec[i]);

    while(q--){
        int l,r;
        cin >> l >> r;
        int k; cin >> k;
        l--; r--;
        auto temp = sgt.get_val(l,r);
        //for(int j = 0; j < 10; j++)cerr << temp[j] << ' '; cerr << el;
        ll ans = 0;
        for(int i = 0; i < k; i++)ans += temp[i];
        cout << ans << el;
    }
    return;
}

void calc(void){
    return;
}

signed main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    calc();
    int t = 1;
    if(MULTI_TEST_CASE)cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0