QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#210159 | #7523. Partially Free Meal | USP_USP_USP# | WA | 657ms | 20380kb | C++23 | 2.9kb | 2023-10-11 04:17:04 | 2023-10-11 04:17:05 |
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<pair<int, int>> a (n);
for (auto &[y, x] : a) cin >> x >> y;
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].first;
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] = a[j];
upd (j, 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 (j, 0, 0);
DyC (m + 1, r, optm, optr);
for (int j = optl; j < optm; j++) upd (j, 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();
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 16152kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 657ms
memory: 20380kb
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:
350098164 542379891 815516336 1634271747 2281723841 2288848823 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: '350098164'