답안 #727428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
727428 2023-04-20T16:11:43 Z sysia Event Hopping 2 (JOI21_event2) C++17
0 / 100
1 ms 212 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 20;
const int mod = 998244353;
struct seg{
    int l, r, i;

    bool operator < (const seg&y) const {
        return l == y.l ? r < y.r : l < y.l;
    }
};

void solve(){
    int n, k; cin >> n >> k;
    vector<seg>tab(n);
    vector<int>s;
    int ck = 0;
    for (auto &[l, r, i]: tab) {
        cin >> l >> r;
        i = ck++;
        s.emplace_back(l);
        s.emplace_back(r);
    }
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    auto scale = [&](int x)->int {
        return lower_bound(s.begin(), s.end(), x) - s.begin();
    };
    for (auto &[l, r, i]: tab){
        l = scale(l);
        r = scale(r);
    }
    sort(tab.begin(), tab.end());
    vector up(n+1, vector<int>(K));
    up[n][0] = n;
    vector<int>dp(n+1);
    for (auto [l, r, i]: tab){
        debug(l, r, i);
    }
    for (int rep = n-1; rep>=0; rep--){
        int i = tab[rep].i;
        int ptr = lower_bound(tab.begin(), tab.end(), seg{tab[rep].r, 0, 0}) - tab.begin();
        up[i][0] = (ptr >= (int)tab.size() ? n : tab[ptr].i);
        dp[i] = dp[up[i][0]]+1;
    }
    int curr = *max_element(dp.begin(), dp.end());
    if (curr < k){
        cout << "-1\n";
        return;
    }
    for (int j = 1; j<K; j++){
        for (int i = 0; i < n; i++){
            up[i][j] = up[up[i][j-1]][j-1];
        }
    }
    auto sorted = tab;
    sort(tab.begin(), tab.end(), [](auto x, auto y){return x.i < y.i;});
    tab.emplace_back(seg{oo, oo, oo});
    set<int>alive;
    // for (int i = 0; i<(int)s.size(); i++) alive.insert(i);

    auto ask = [&](int l, int r)->int {
        auto ptr = lower_bound(sorted.begin(), sorted.end(), seg{l, 0, 0}) - sorted.begin();
        if (ptr >= (int)sorted.size()) return 0;
        int ans = 0;
        int now = sorted[ptr].i;
        for (int i = K-1; i>=0; i--){
            if (tab[up[now][i]].r <= r){
                now = up[now][i];
                ans += (1<<i);
            }
        }
        return ans;
    };
    vector<int>ret;
    for (auto [l, r, i]: tab){
        auto it = alive.lower_bound(l);
        if (it != alive.end() && *it < r) continue;
        debug(l, r, i);
        auto Lit = alive.upper_bound(l);
        auto Rit = alive.lower_bound(r);
        int L = (Lit == alive.begin() ? 0 : *(--Lit));
        int R = (Rit == alive.end() ? (int)s.size(): *Rit);
        int change = ask(L, l) + ask(r, R) + 1 - ask(L, R);
        debug(L, l, r, R);
        if (curr + change >= k){
            for (int rep = l; rep < r; rep++){
                alive.insert(rep);
            }
            ret.emplace_back(i);
            if ((int)ret.size() == k) break;
        }
    }   
    for (auto x: ret) cout << x+1 << "\n";
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();

    return 0;
}

Compilation message

event2.cpp: In function 'void solve()':
event2.cpp:63:15: warning: structured binding declaration set but not used [-Wunused-but-set-variable]
   63 |     for (auto [l, r, i]: tab){
      |               ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -