80pts WA On #6 #8求调
查看原帖
80pts WA On #6 #8求调
881015
Resstifnurvˆwˆ.tar.gz楼主2024/6/27 15:57
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <utility>
using namespace std;

// #define IS_ATCODER
#define IS_MULTI_TESTS
// #define USE_CIN

#ifndef ONLINE_JUDGE
#include <atcoder/all>
using mint = atcoder::modint998244353;
#else
#ifdef IS_ATCODER
#include <atcoder/all>
using mint = atcoder::modint998244353;
#endif
#endif

#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
using ll = long long;
using pii = pair <int, int>;

inline int read(){
    int ret = 0;
    char ch = ' ', c = getchar();
    while(!('0' <= c && c <= '9')) ch = c, c = getchar();
    while('0' <= c && c <= '9'){
        ret = ret * 10 + (c ^ 48);
        c = getchar();
    }
    return ch == '-' ? -ret : ret;
}

const int N = 1e3 + 10;
const int M = 1e5 + 10;
const __float128 INF = 0x3f3f3f3f3f3f3f3f;
const __float128 eps = 1e-10;
inline bool _less(__float128 x, __float128 y){ return y - x > eps; }
inline bool _great(__float128 x, __float128 y){ return x - y > eps; }
inline bool _le(__float128 x, __float128 y){ return !_great(x, y); }
inline bool _ge(__float128 x, __float128 y){ return !_less(x, y); }
inline bool _equal(__float128 x, __float128 y){ return _le(x, y) && _ge(x, y); }

int to[M], nt[M], idx, h[N];
__float128 c[M];
inline void add(int x, int y, __float128 z){
    // printf("add(%d, %d, %.4lf)\n", x, y, z);
    to[idx] = y, nt[idx] = h[x], c[idx] = z, h[x] = idx++;
    to[idx] = x, nt[idx] = h[y], c[idx] = 0, h[y] = idx++;
}

int S, T;
int cur[N], lv[N];
queue<int> que, empty_queue;

bool bfs(){
    que = empty_queue;
    memset(lv, -1, sizeof(lv));
    que.push(S);
    lv[S] = 0;
    cur[S] = h[S];
    while(!que.empty()){
        int u = que.front();
        que.pop();
        for(int i = h[u]; i != -1; i = nt[i]){
            int j = to[i];
            if(lv[j] != -1 || _equal(c[i], 0)) continue;
            que.push(j);
            lv[j] = lv[u] + 1;
            cur[j] = h[j];
            if(j == T) return true;
        }
    }
    return false;
}

__float128 find(int u, __float128 limit){
    if(u == T) return limit;
    __float128 flow = 0;
    for(int i = cur[u]; _less(flow, limit) && i != -1; i = nt[i]){
        cur[u] = i;
        int j = to[i];
        if(lv[j] != lv[u] + 1 || _equal(c[i], 0)) continue;
        __float128 k = find(j, min(limit - flow, c[i]));
        if(_equal(k, 0)) lv[j] = -1;
        flow += k;
        c[i] -= k;
        c[i ^ 1] += k;
    }
    return flow;
}

__float128 dinic(){
    __float128 flow = 0, ans = 0;
    while(bfs()){
        while(_great(flow = find(S, INF), 0)) ans += flow;
    }
    return ans;
}

int n, m;
struct cheese{
    int sz;
    __float128 bg, ed;
} A[N];
__float128 B[N];
vector<__float128> ts;

void init(){
    memset(h, -1, sizeof(h));
    idx = 0;
}
bool check(__float128 mid){
    init();
    ts.clear();
    S = 0, T = 1;
    __float128 ful = 0;
    for(int i = 1; i <= n; i++){
        add(S, i + 1, A[i].sz);
        ful += A[i].sz;
        A[i].ed += mid;
        ts.push_back(A[i].bg);
        ts.push_back(A[i].ed);
    }
    sort(ts.begin(), ts.end());
    ts.erase(unique(ts.begin(), ts.end()), ts.end());
    
    auto Rat = [=](int i, int j){
        return i * m + j + n + 2;
    };
    set<int> now;
    __float128 last = 0;
    for(int i = 0; i < sz(ts); i++){
        __float128 len = ts[i] - last;
        if(_great(len, 0)){
            for(int j = 1; j <= m; j++){
                for(int a: now){
                    add(a + 1, Rat(i, j), len * B[j] );
                }
                add(Rat(i, j), T, j * len * B[j]);
            };
        }
        for(int j = 1; j <= n; j++){
            if(_equal(ts[i], A[j].bg)) now.insert(j);
            else if(_equal(ts[i], A[j].ed)) now.erase(j);
        }
        last = ts[i];
    }
    for(int i = 1; i <= n; i++){
        A[i].ed -= mid;
    }

    __float128 ans = dinic();
    return _equal(ans, ful);
}

void solve(){
    n = read(), m = read();
    for(int i = 1; i <= n; i++){
        int sz = read(), bg = read(), ed = read();
        A[i] = (cheese){sz, bg, ed};
    }
    for(int i = 0; i < m; i++) B[i] = read();
    sort(B, B + m, _great);
    B[m] = 0;
    for(int i = m; i >= 1; i--) B[i] = B[i - 1] - B[i];
    __float128 l = 0, r = 1e8, mid;
    while(_less(l, r)){
        mid = (l + r) / 2.0;
        if(check(mid)) r = mid;
        else l = mid;
    }
    printf("%.5Lf\n", (long double)r);
}

int main(){
#ifdef USE_CIN
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
#endif
#ifdef IS_MULTI_TESTS
    int Test;
    #ifdef USE_CIN
        cin >> Test;
    #else
        Test = read();
    #endif
    while(Test--) solve();
#else
    solve();
#endif
    return 0;
}
2024/6/27 15:57
加载中...