QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#210163 | #7523. Partially Free Meal | USP_USP_USP# | WA | 1091ms | 21980kb | C++23 | 3.0kb | 2023-10-11 04:36:52 | 2023-10-11 04:36:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define pb push_back
void dbg_out() { cerr << endl; }
template <typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
struct Node {
int sum, ativo;
Node () : sum (0), ativo (0) {}
Node (int sum, int ativo) : sum (sum), ativo (ativo) {}
Node operator + (const Node &o) const {
return Node (sum + o.sum, ativo + o.ativo);
}
};
const int N = 2e5 + 10;
int n;
Node node[4 * N];
void upd (int no, int ini, int fim, int k, int sum, int ativo) {
if (ini == fim) {
node[no] = Node (sum, ativo);
return;
}
int meio = (ini + fim) / 2;
if (k <= meio) upd (2 * no, ini, meio, k, sum, ativo);
else upd (2 * no + 1, meio + 1, fim, k, sum, ativo);
node[no] = node[2 * no] + node[2 * no + 1];
}
int find_first_k (int no, int ini, int fim, int need) {
if (ini == fim) return node[no].sum;
int meio = (ini + fim) / 2;
if (node[2 * no].ativo < need) {
return node[2 * no].sum + find_first_k (2 * no + 1, meio + 1, fim, need - node[2 * no].ativo);
}
else return find_first_k (2 * no, ini, meio, need);
}
int find_first_k (int need) {
return find_first_k (1, 0, n - 1, need + 1);
}
void upd (int k, int sum, int ativo) {
// dbg (k, sum, ativo);
upd (1, 0, n - 1, k, sum, ativo);
}
void solve () {
cin >> n;
vector<array<int, 3>> a (n);
for (auto &[x, y, z] : a) cin >> x >> y;
sort (all (a));
for (int i = 0; i < n; i++) a[i][2] = i, swap (a[i][0], a[i][1]);
sort (all (a));
vector<int> ans (n);
const int INF = 1e16;
function <void(int, int, int, int)> DyC = [&] (int l, int r, int optl, int optr) {
if (r < l) return;
if (optl == optr) {
for (int j = l; j <= r; j++) {
ans[j] = a[optr][0];
ans[j] += find_first_k (j);
}
return;
}
int m = (l + r) / 2;
int optm = -1, cur = INF;
for (int j = optl; j <= optr; j++) {
auto [y, x, z] = a[j];
upd (z, x, 1);
// adicionamos o maluco
int res = find_first_k (m) + y;
// dbg (j, res);
if (res < cur && m <= j) {
cur = res;
optm = j;
}
}
// dbg (l, optl, m, optm, r, optr);
ans[m] = cur;
for (int j = optm; j <= optr; j++) upd (a[j][2], 0, 0);
DyC (m + 1, r, optm, optr);
for (int j = optl; j < optm; j++) upd (a[j][2], 0, 0);
DyC (l, m - 1, optl, optm);
};
DyC (0, n - 1, 0, n - 1);
for (int i = 0; i < n; i++) cout << ans[i] << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 16052kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 1091ms
memory: 21980kb
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 14624329 14788280 16172895 17768627 19336633 20693779 23136209 23389851 26506696 28255694 28509336 31840317 33722819 33976461 35893858 37754030 39588384 41808055 43729543 45309771 47309654 48837539 50417767 52079411 53762717 55190044 56577630...
result:
wrong answer 8th lines differ - expected: '13476823', found: '14624329'