QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#533908#7523. Partially Free Mealrikka_lylyWA 270ms12364kbC++203.8kb2024-08-26 16:38:252024-08-26 16:38:25

Judging History

你现在查看的是最新测评结果

  • [2024-08-26 16:38:25]
  • 评测
  • 测评结果:WA
  • 用时:270ms
  • 内存:12364kb
  • [2024-08-26 16:38:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f

int totopt = 0;

struct KBIG
{
    int k = 0;
    ll sum = 0;
    priority_queue<int, vector<int>, greater<int>> pq1;
    priority_queue<int> pq2;
    KBIG()
    {
        k = 0;
        sum = 0;
    }
    void insert(int x)
    {
        totopt++;
        if(pq1.size() < k)
        {
            pq1.push(x);
            sum += x;
            return;
        }
        pq1.push(x);
        sum += x;
        pq2.push(pq1.top());
        sum -= pq1.top();
        pq1.pop();
    }
    void resetk(int kk)//这个k必须比之前的k大
    {
        k = kk;
        while (!pq2.empty() && pq1.size() < k)
        {
            totopt++;
            pq1.push(pq2.top());
            sum += pq2.top();
            pq2.pop();
        }
    }
    ll getsum()const
    {
        return pq1.size() == k ? sum : -1;
    }
};


void solve()
{
    int n;
    cin >> n;
    vector<int> a0(n + 2), b0(n + 2);
    for (int i = 1; i <= n; i++)
    {
        cin >> a0[i] >> b0[i];
    }
    auto cmp = [&](int x, int y) -> bool
    {
        return b0[x] < b0[y];
    };
    vector<int> temp(n + 2);
    for (int i = 1; i <= n; i++)
    {
        temp[i] = i;
    }
    sort(temp.begin() + 1, temp.end() - 1, cmp);
    vector<int> a(n + 2), b(n + 2);
    for (int i = 1; i <= n; i++)
    {
        a[i] = a0[temp[i]], b[i] = b0[temp[i]];
    }
    vector<int> f(n + 2, -1);
    vector<ll> ans(n + 2, INF);
    f[0] = 1, f[n] = n;
    if(1)//先把ans[n]求出来免得夜长梦多
    {
        ll sum = 0;
        for (int i = 1; i <= n; i++)
        {
            sum += a[i];
        }
        ans[n] = sum + b[n];
    }
    int totceng = 0;
    while (1)
    {
        totceng++;
        //找一下这一层需要处理那些f,以及其前后已经算出来f的数
        vector<pair<int, pair<int, int>>> vt;
        for (int i = 1, last = 0; i <= n; i++)
        {
            if(f[i] == -1)
                continue;
            if(last + 1 == i)
            {
                last = i;
                continue;
            }
            vt.push_back({(last + i) >> 1, {last, i}});
            last = i;
        }
        if(vt.empty())
            break;
        int p = 1;
        KBIG kb;
        for (auto &[cur, rng] : vt)
        {
            // cerr << "siz1=" << kb.pq1.size() << " siz2=" << kb.pq2.size() << endl;
            // cerr << "cur=" << cur << endl;
            kb.resetk(cur - 1);
            int l = f[rng.first], r = f[rng.second];
            // cerr << "l=" << l << " r=" << r << endl;
            // cerr << "siz1=" << kb.pq1.size() << " siz2=" << kb.pq2.size() << endl;
            {
                ll tans = kb.getsum();
                if(tans != -1 && tans + a[p] + b[p] < ans[cur])
                {
                    ans[cur] = tans + a[p] + b[p];
                    f[cur] = p;
                }
            }
            while (p < r)
            {
                kb.insert(a[p++]);
                ll tans = kb.getsum();
                if(tans != -1 && tans + a[p] + b[p] < ans[cur])
                {
                    ans[cur] = tans + a[p] + b[p];
                    f[cur] = p;
                }
            }
            assert(f[cur] != -1);
            // cerr << "f[" << cur << "]=" << f[cur] << endl;
        }
        // cerr << endl;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << ans[i] << '\n';
    }
    // cerr << totceng << " " << totopt << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    while (t--)
    {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3560kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 270ms
memory: 12364kb

input:

200000
466436993 804989151
660995237 756645598
432103296 703610564
6889895 53276988
873617076 822481192
532911431 126844295
623111499 456772252
937464699 762157133
708503076 786039753
78556972 5436013
582960979 398984169
786333369 325119902
930705057 615928139
924915828 506145001
164984329 208212435...

output:

192284522
542379891
815516336
1634271747
2095679225
2287960123
2295081837
2436938324
3378947668
3729968912
3888786337
4450922472
4529407199
4668579114
5217871609
5748677760
6741335309
7240106251
7727932570
8316657022
8904518029
9850303712
10096632581
10289352744
10829176078
10986147364
11431637691
1...

result:

wrong answer 1st lines differ - expected: '1318594', found: '192284522'