Submission #920692

# Submission time Handle Problem Language Result Execution time Memory
920692 2024-02-02T23:59:07 Z hasuhasuiro Autobahn (COI21_autobahn) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, K;
    long long X;
    cin >> N >> K >> X;
    vector l(N, 0LL), r(N, 0LL), t(N, 0LL);
    for(int i = 0; i < N; i++) { cin >> l[i] >> t[i] >> r[i]; r[i]++; }
    if(N <= 1010 && X <= 1010 && *max_element(begin(l), end(l)) <= 1010 && *max_element(begin(r), end(r)) <= 1010 && *max_element(begin(t), end(t)) <= 1010) {
        vector imos1(1010, 0), imos2(1010, 0);
        for(int i = 0; i < N; i++) {
            imos1[l[i]]++, imos1[r[i]]--;
            if(l[i]+t[i] < r[i]) { imos2[l[i]+t[i]]++, imos2[r[i]]--; }
        }
        for(int i = 0; i < 1005; i++) {
            imos1[i+1] += imos1[i];
            imos2[i+1] += imos2[i];
        }
        for(int i = 0; i < 1005; i++) { if(imos1[i] < K) { imos2[i] = 0; } }
        vector sumimos2(1011, 0);
        for(int i = 0; i < 1010; i++) sumimos2[i+1] = sumimos2[i] + imos2[i];
        int ans(0);
        for(int i = 0; i < 1005-X; i++) {
            ans = max(sumimos2[i+X]-sumimos2[i], ans);
        }
        cout << ans << endl;
    }else {
        /* 座標圧縮用の座標 */
        vector P(0, 0LL);
        for(int i = 0; i < N; i++) { P.push_back(l[i]), P.push_back(r[i]); } /* 各区間の始点終点 */
        for(int i = 0; i < N; i++) { if(l[i]+t[i] < r[i]) { P.push_back(l[i]+t[i]); } } /* 追加料金のかかる区間の始点 */
        int sizep(size(P));
        for(int i = 0; i < sizep; i++) { P.push_back(P[i]+X), P.push_back(P[i]-X); } /* ある点から X の距離の点 */
        sort(begin(P), end(P));
        P.erase(unique(begin(P), end(P)), end(P));
    
        /* P の逆引きできるような連想配列 */
        map<long long, int> mp;
        for(int i = 0; i < (int)size(P); i++) { mp[P[i]] = i; }
        vector imos(size(P), 0);
        for(int i = 0; i < N; i++) { imos[mp[l[i]]]++; imos[mp[r[i]]]--; } /* 各区間の区間加算 */
        for(int i = 0; i+1 < (int)size(P); i++) { imos[i+1] += imos[i]; } /* 求解 */
    
        vector imos2(size(P), 0LL);
        for(int i = 0; i < N; i++) { if(l[i]+t[i] < r[i]) { imos2[mp[l[i]+t[i]]]++; imos2[mp[r[i]]]--; } } /* 追加料金の区間加算 */
        for(int i = 0; i+1 < (int)size(P); i++) { imos2[i+1] += imos2[i]; } /* 求解 */
        for(int i = 0; i < (int)size(P); i++) { if(imos[i] < K) { imos2[i] = 0; } } /* 許される場合は除外する */
    
        /* 尺取り法 */
        long long ans(0LL), res(0LL);
        for(int i = 0, j = 0; i+1 < (int)size(P); i++) {
            for(; j < (int)size(P); j++) {
                if(P[i]+X <= P[j]) { break; }
                else if(j+1 < (int)size(P)) { res += imos2[mp[P[j]]] * (long long)(P[j+1]-P[j]); } /* 右端を加算 */
            }
            if(mp2[P[i]]||mp2[P[i]+X]) ans = max(res, ans);
            res -= imos2[mp[P[i]]] * (long long)(P[i+1] - P[i]); /* 左端を加算 */
        }
        cout << ans << endl;
    }
    return 0;
}

Compilation message

autobahn.cpp: In function 'int main()':
autobahn.cpp:57:16: error: 'mp2' was not declared in this scope; did you mean 'mp'?
   57 |             if(mp2[P[i]]||mp2[P[i]+X]) ans = max(res, ans);
      |                ^~~
      |                mp