QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#225746 | #7523. Partially Free Meal | ammardab3an | WA | 0ms | 3620kb | C++17 | 3.2kb | 2023-10-25 04:32:19 | 2023-10-25 04:32:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll ans[200010];
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(int val){
node* nd = new node(val);
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, int idx){
if(l == r){
return create_node(idx);
}
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 tl, int tr, int ks){
if(tl > tr) return 0;
if(root == nullptr){
while(true){
int x = 1;
}
}
if(root->cnt < ks) return 1e18;
if(l == tl && r == tr) return root->sum;
if(l == -1 || r == -1) assert(0);
int mid = (l+r)/2;
if(root->left == nullptr || root->right == nullptr){
while(true){
int x = 1;
}
}
if(root->left->cnt >= ks) return get(root->left, l, mid, tl, min(mid, tr), ks);
return root->left->sum + get(root->right, mid+1, r, max(mid+1, tl), tr, 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);
if(r+1 < mid){
while(true){
int x = 1;
}
}
l = max(l, mid-1);
for(int i = l; i <= r; i++){
ll cur = v[i].first + v[i].second;
cur += get(per[i], 0, 1e9, 0, 1e9, mid-1);
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);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
that_node = new node(0, 0);
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;
if(n==0){
n = 200000;
v.resize(n);
srand(0);
for(auto &[a, b] : v){ a = abs(rand()); b = abs(rand()); }
for(auto &[a, b] : v){ cout << a << " " << b << endl;}
}
sort(v.begin(), v.end());
for(auto &[f, s] : v) swap(f, s), per.push_back(add(per.back(), 0, 1e9, f));
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: 0
Wrong Answer
time: 0ms
memory: 3620kb
input:
3 2 5 4 3 3 7
output:
11 11 16
result:
wrong answer 1st lines differ - expected: '7', found: '11'