結果

問題 No.1675 Strange Minimum Query
ユーザー sapphire__15sapphire__15
提出日時 2021-09-10 22:28:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 466 ms / 2,000 ms
コード長 4,105 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 137,900 KB
実行使用メモリ 30,236 KB
最終ジャッジ日時 2023-09-02 18:49:54
合計ジャッジ時間 14,637 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 349 ms
13,932 KB
testcase_04 AC 312 ms
15,464 KB
testcase_05 AC 30 ms
7,920 KB
testcase_06 AC 421 ms
15,640 KB
testcase_07 AC 466 ms
18,168 KB
testcase_08 AC 1 ms
4,372 KB
testcase_09 AC 3 ms
4,372 KB
testcase_10 AC 160 ms
12,412 KB
testcase_11 AC 50 ms
9,160 KB
testcase_12 AC 174 ms
13,276 KB
testcase_13 AC 256 ms
16,208 KB
testcase_14 AC 350 ms
30,236 KB
testcase_15 AC 352 ms
29,272 KB
testcase_16 AC 1 ms
4,368 KB
testcase_17 AC 58 ms
6,580 KB
testcase_18 AC 84 ms
7,308 KB
testcase_19 AC 128 ms
12,444 KB
testcase_20 AC 255 ms
15,112 KB
testcase_21 AC 238 ms
15,716 KB
testcase_22 AC 300 ms
17,444 KB
testcase_23 AC 228 ms
11,368 KB
testcase_24 AC 209 ms
12,524 KB
testcase_25 AC 149 ms
9,100 KB
testcase_26 AC 80 ms
8,448 KB
testcase_27 AC 216 ms
15,344 KB
testcase_28 AC 115 ms
11,432 KB
testcase_29 AC 92 ms
11,216 KB
testcase_30 AC 80 ms
8,400 KB
testcase_31 AC 294 ms
13,608 KB
testcase_32 AC 406 ms
20,024 KB
testcase_33 AC 395 ms
19,832 KB
testcase_34 AC 409 ms
19,936 KB
testcase_35 AC 403 ms
19,768 KB
testcase_36 AC 404 ms
19,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cmath>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <functional>

#define rep(i,n,s) for(int i = (s); i < int(n); i++)
#define MM << " " << 
#define all(x) x.begin(), x.end()

template<class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

template<class T>
bool chmin(T& a, const T b) {
    if(a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template<class T>
bool chmax(T& a, const T b) {
    if(a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template<class T>
void vdeb(std::vector<T> &da) {
    auto n = da.size();
    for(size_t i = 0; i < n; i++) {
        if(i == n-1) std::cout << da[i] << std::endl;
        else std::cout << da[i] << " ";
    }
}
template<>
void vdeb(std::vector<std::string> &da) {
    auto n = da.size();
    for(size_t i = 0; i < n; i++) {
        std::cout << da[i] << std::endl;
    }
}


template<typename T>
struct SegTree{
    std::vector<T> nod;
    T t0;
    std::function<T(T,T)> operation;
    std::function<T(T,T)> merge;
    int size;
    SegTree(int _size, T _t0, std::function<T(T,T)> _operation, std::function<T(T,T)> _merge):t0(_t0), operation(_operation), merge(_merge){
        size=1;
        while(_size>size){
            size*=2;
        }
        nod=std::vector<T>(size*2-1, t0);
    }
    void update(int k, T a){ // operation(da[k], a)
        assert(0<= k && k < size);
        k+=size-1;
        nod[k] = operation(nod[k], a);
        while(k>0){
            k=(k-1)/2;
            nod[k] = merge(nod[k*2+1], nod[k*2+2]); 
        }
    }
    void range_update(int a, int b, T x) {
        assert(0 <= a && a < size);
        assert(0 <= b && b <= size);
        assert(a <= b);
        range_update_query(a, b, 0, 0, size, x);
    }
    T sum(int a, int b) { // merge[a, b)
        assert(0 <= a && a < size);
        assert(0 <= b && b <= size);
        assert(a <= b);
        return sum_query(a, b, 0, 0, size);
    }
    void deb(){
        for(int i=0;i<size*2-1;i++){
            if(i==size*2-2) std::cout << nod[i] <<std:: endl;
            else std::cout << nod[i] << ' ';
        }
        return;
    }
    private:
    void range_update_query(int a,int b,int k,int l,int r,T x){
        if(r<=a||b<=l){
            return;
        }
        if(a<=l && r<=b){
            nod[k] = operation(nod[k], x);
            return;
        }
        else{
            range_update_query(a,b,k*2+1,l,(l+r)/2,x);
            range_update_query(a,b,k*2+2,(l+r)/2,r,x);
            return;
        }
    }
    T sum_query(int a,int b,int k,int l,int r){
        if(r<=a||b<=l){
            return t0;
        }
        if(a<=l && r<=b){
            return nod[k];
        }
        else{
            return merge(sum_query(a,b,k*2+1,l,(l+r)/2),sum_query(a,b,k*2+2,(l+r)/2,r));
        }
    }
};

using namespace std;

int main() {
    int n, q; cin >> n >> q;
    vector<vector<Pii>> da(n+1);
    vector<pair<Pii, int>> query(q);
    rep(i,q,0) {
        int l, r, b; cin >> l >> r >> b;
        da[l-1].push_back({b, 0});
        da[r].push_back({b, 1});
        query[i] = {{l-1, r}, b};
    }
    SegTree<int> st(n, 1000000000, [](int x, int y){return min(x, y);}, [](int x, int y){return min(x, y);});
    map<int, int> mp;
    rep(i,n,0) {
        for(auto &j : da[i]) {
            if(j.second) {
                mp[j.first]--;
                if(mp[j.first] == 0) mp.erase(j.first);
            } else {
                mp[j.first]++;
            }
        }
        if(!mp.empty()) st.update(i, (--mp.end())->first);
    }
    rep(i,q,0) {
        if(st.sum(query[i].first.first, query[i].first.second) != query[i].second) {
            cout << -1 << endl;
            return 0;
        }
    }
    vector<int> ans(n);
    rep(i,n,0) ans[i] = st.sum(i, i+1);
    vdeb(ans);
}
0