답안 #814376

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
814376 2023-08-08T07:08:04 Z 이동현(#10122) Arranging Tickets (JOI17_arranging_tickets) C++17
0 / 100
1456 ms 576 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

struct Seg{
    int n;
    vector<int> tr, lazy;

    Seg(int m){
        n = m + 4;
        tr.resize(n * 4 + 4);
        lazy.resize(n * 4 + 4);
    }

    void push(int x, int s, int e, int ps, int pe, int val){
        if(pe < s || ps > e || ps > pe) return;
        if(ps <= s && pe >= e){
            tr[x] += val;
            lazy[x] += val;
            return;
        }
        if(lazy[x]){
            tr[x * 2] += lazy[x], lazy[x * 2] += lazy[x];
            tr[x * 2 + 1] += lazy[x], lazy[x * 2 + 1] += lazy[x];
            lazy[x] = 0;
        }

        int m = s + e >> 1;
        push(x * 2, s, m, ps, pe, val);
        push(x * 2 + 1, m + 1, e, ps, pe, val);

        tr[x] = max(tr[x * 2], tr[x * 2 + 1]);
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int L, n;
    cin >> L >> n;
    L = n = 3000;
    Seg tr(L + 4);
    vector<array<int, 4>> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        --a[i][0], --a[i][1];

        a[i][2] = 1;
        a[i][0] = rand() % 3000;
        a[i][1] = rand() % 3000;

        assert(a[i][2] == 1);

        if(a[i][0] > a[i][1]) swap(a[i][0], a[i][1]);

        tr.push(1, 0, L - 1, a[i][0], a[i][1] - 1, 1);
    }

    auto flip = [&](int id)->void{
        if(a[id][3] == 1){
            tr.push(1, 0, L - 1, a[id][1], L - 1, -1);
            tr.push(1, 0, L - 1, 0, a[id][0] - 1, -1);
            tr.push(1, 0, L - 1, a[id][0], a[id][1] - 1, 1);
        }
        else{
            tr.push(1, 0, L - 1, a[id][1], L - 1, 1);
            tr.push(1, 0, L - 1, 0, a[id][0] - 1, 1);
            tr.push(1, 0, L - 1, a[id][0], a[id][1] - 1, -1);
        }
        a[id][3] ^= 1;
    };

    int ans = (int)1e9;

    // assert(n <= 300);

    auto doit = [&]{
        for(int i = 0; i < 1; ++i){
            for(int j = i - 1; j < n; j += (n < 300 ? 1 : n / 300)){
                // cout << j << ' ' << ans << endl;
                if(j >= 0) flip(j);
                
                int nans = tr.tr[1];
                while(true){
                    int now = nans;

                    for(int i = 0; i < n; ++i){
                        flip(i);

                        int prv = now;
                        now = min(now, tr.tr[1]);

                        if(now == prv) flip(i);
                    }

                    if(now == nans) break;

                    nans = now;
                }

                ans = min(ans, nans);
            }
        }
    };
    
    // sort(a.begin(), a.end(), [&](array<int, 4>&x, array<int, 4>&y){return make_pair(x[1], x[0]) < make_pair(y[1], y[0]);});
    // doit();
    // sort(a.begin(), a.end(), [&](array<int, 4>&x, array<int, 4>&y){return make_pair(x[1], x[0] + x[1]) < make_pair(y[1], y[0] + y[1]);});
    // doit();
    // sort(a.begin(), a.end(), [&](array<int, 4>&x, array<int, 4>&y){return make_pair(x[1], x[0] - x[1]) < make_pair(y[1], y[0] - y[1]);});
    // doit();
    // sort(a.begin(), a.end(), [&](array<int, 4>&x, array<int, 4>&y){return make_pair(x[0], x[1]) < make_pair(y[0], y[1]);});
    // doit();
    // sort(a.begin(), a.end(), [&](array<int, 4>&x, array<int, 4>&y){return make_pair(x[0], x[0] + x[1]) < make_pair(y[0], y[0] + y[1]);});
    // doit();
    // sort(a.begin(), a.end(), [&](array<int, 4>&x, array<int, 4>&y){return make_pair(x[0], x[0] - x[1]) < make_pair(y[0], y[0] - y[1]);});
    // doit();
    sort(a.begin(), a.end(), [&](array<int, 4>&x, array<int, 4>&y){return x[0] + x[1] < y[0] + y[1];});
    doit();
    // sort(a.begin(), a.end(), [&](array<int, 4>&x, array<int, 4>&y){return x[0] < y[0];});
    // doit();
    // sort(a.begin(), a.end(), [&](array<int, 4>&x, array<int, 4>&y){return x[0] - x[1] < y[0] - y[1];});
    // doit();
    // sort(a.begin(), a.end(), [&](array<int, 4>&x, array<int, 4>&y){return x[1] < y[1];});
    // doit();

    cout << ans << '\n';
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1456 ms 576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1456 ms 576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1456 ms 576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1456 ms 576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1456 ms 576 KB Output isn't correct
2 Halted 0 ms 0 KB -