QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#225754#7523. Partially Free Mealammardab3anWA 939ms299376kbC++172.8kb2023-10-25 05:11:562023-10-25 05:11:56

Judging History

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

  • [2023-10-25 05:11:56]
  • 评测
  • 测评结果:WA
  • 用时:939ms
  • 内存:299376kb
  • [2023-10-25 05:11:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll ans[200010];

#define int long long

struct node {
    ll sum;
    int cnt;
    node *left, *right;
    node(ll sum){
        this->sum = sum;
        this->cnt = 1;
        left = right = nullptr;
    }
    node(ll sum, int cnt){
        this->sum = sum;
        this->cnt = cnt;
        left = right = nullptr;
    }
    node(node *left, node *right){
        sum = (left ? left->sum : 0) + (right ? right->sum : 0);
        cnt = (left ? left->cnt : 0) + (right ? right->cnt : 0);
        this->left = left;
        this->right = right;
    }
};

vector<node*> per;

node* that_node = nullptr;

node* create_node(ll val){
    node* nd = new node(val);
    nd->left = nd->right = that_node;
    return nd;
}

node* create_node(ll val, int cnt){
    node* nd = new node(val, cnt);
    nd->left = nd->right = that_node;
    return nd;
}

node* create_node(node* left, node* right){
    node* nd = new node(left, right);
    return nd;
}

node* add(node*root, int l, int r, ll idx){
    if(l == r){
        return create_node(root->sum+idx, root->cnt+1);
    }
    int mid = (l + r)/2;
    if(idx <= mid) return create_node(add(root->left, l, mid, idx), root->right);
    else return create_node(root->left, add(root->right, mid+1, r, idx));
}

ll get(node* root, int l, int r, int ks){
    if(l == r) return root->sum;
    if(root->cnt < ks){
        return 1e18;
    }
    int mid = (l+r)/2;
    if(root->left->cnt >= ks) return get(root->left, l, mid, ks);
    return root->left->sum + get(root->right, mid+1, r, ks - (root->left->cnt));
}

void solve(const vector<pair<int, int>> &v, int l, int r, int tl, int tr){

    if(tl > tr) return;

    int mid = (tl+tr)/2;
    pair<ll, int> best(1e18, -1);

    for(int i = l; i <= r; i++){
        ll cur = v[i].first + v[i].second;
        ll cur1 = get(per[i], 0, 1e9, mid-1);
        cur += cur1;
        best = min(best, {cur, i});
    }

    assert(best.second >= mid-1);

    ans[mid] = best.first;
    solve(v, l, best.second, tl, mid-1);
    solve(v, best.second, r, mid+1, tr);

}

main()
{

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    that_node = new node(0LL, 0LL);
    that_node->left = that_node;
    that_node->right = that_node;

    per.push_back(that_node);

    int n;
    cin >> n;

    vector<pair<int, int>> v(n);
    for(auto &[f, s] : v) cin >> s >> f;

    sort(v.begin(), v.end());

    for(auto &[f, s] : v) swap(f, s), per.push_back(add(per.back(), 0, 1e9, f));

    for(int i = 0; i <= n; i++){
        if(per[i]->cnt != i) assert(0);
    }

    solve(v, 0, n-1, 1, n);

    for(int i = 1; i <= n; i++){
        cout << ans[i] << "\n";
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 939ms
memory: 299376kb

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:

1318594
3208018
5570526
7340845
9223347
11149865
12332210
13476823
14788280
16172895
17768627
19336633
20693779
22005236
23389851
25073157
26760338
28509336
30294967
32093959
33976461
35893858
37754030
39588384
41470886
43388283
45309771
47309654
48837539
50417767
52079411
53762717
55190044
56577630...

result:

wrong answer 25827th lines differ - expected: '894878200462', found: '894947484423'