Skip to content

Commit

Permalink
QOJ: The 3rd Universal Cup. Stage 14: Harbin
Browse files Browse the repository at this point in the history
  • Loading branch information
Macesuted committed Oct 27, 2024
1 parent c514b5e commit 8465986
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 0 deletions.
59 changes: 59 additions & 0 deletions QOJ/9519.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* @file 9519.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-10-26
*
* @copyright Copyright (c) 2024
*
*/

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

#define endl '\n'

#define maxn 105

typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;

vector<pii> graph[maxn];
vector<tiii> links;
int cnt = 0;

void solve(int dep, int l, int r, int ql, int qr, int fa, bool pre, bool lst) {
if (ql <= l && r <= qr) return links.emplace_back(fa, dep, lst), void();
int mid = (l + r) >> 1;
if (!pre) graph[fa].emplace_back(++cnt, lst), fa = cnt;
if (ql <= mid) solve(dep - 1, l, mid, ql, qr, fa, pre, 0);
if (qr > mid) solve(dep - 1, mid + 1, r, ql, qr, fa, false, 1);
return;
}

void solve(void) {
int L, R;
cin >> L >> R;
solve(20, 0, (1 << 20) - 1, L, R, ++cnt, true, 0);
cnt++;
int maxv = 0;
for (auto i : links) maxv = max(maxv, get<1>(i));
for (int i = 1; i <= maxv; i++) graph[cnt + i].emplace_back(cnt + i - 1, 0), graph[cnt + i].emplace_back(cnt + i - 1, 1);
for (auto [x, d, w] : links) graph[x].emplace_back(cnt + d, w);
cnt += maxv;
cout << cnt << endl;
for (int i = 1; i <= cnt; i++) {
cout << graph[i].size();
for (auto [x, d] : graph[i]) cout << ' ' << x << ' ' << d;
cout << endl;
}
return;
}

int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

int _ = 1;
while (_--) solve();

return 0;
}
49 changes: 49 additions & 0 deletions QOJ/9521.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @file 9521.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-10-26
*
* @copyright Copyright (c) 2024
*
*/

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

#define endl '\n'

char c[15];
int w[15], d[15];

void solve(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c[i] >> d[i];
if (c[i] == 'N')
w[i] = 0;
else if (c[i] == 'E')
w[i] = 1;
else if (c[i] == 'S')
w[i] = 2;
else
w[i] = 3;
}
cout << 2 * n - 1 << ' ' << c[1] << endl;
cout << "Z " << d[1] << endl;
for (int i = 2; i <= n; i++) {
cout << "LR"[w[i] == (w[i - 1] + 1) % 4] << endl;
cout << "Z " << d[i] << endl;
}
return;
}

int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

int _ = 1;
cin >> _;
while (_--) solve();

return 0;
}
74 changes: 74 additions & 0 deletions QOJ/9523.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @file 9523.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-10-26
*
* @copyright Copyright (c) 2024
*
*/

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

#define endl '\n'

#define maxn 505
#define mod 1000000007

typedef tuple<int, int, int> tiii;

int64_t qpow(int64_t a, int64_t x) {
int64_t ans = 1;
while (x) {
if (x & 1) ans = ans * a % mod;
a = a * a % mod, x >>= 1;
}
return ans;
}
int64_t inv(int64_t a) { return qpow(a, mod - 2); }

int x[maxn], v[maxn], coef[maxn];
int64_t f[maxn];
vector<tiii> a;

void insert(int64_t a, int64_t b) {
for (int i = maxn - 2; ~i; i--) f[i + 1] = (f[i + 1] + f[i] * a) % mod, f[i] = f[i] * b % mod;
return;
}
void erase(int64_t a, int64_t b) {
int64_t invb = inv(b);
for (int i = 0; i < maxn - 1; i++) f[i] = f[i] * invb % mod, f[i + 1] = (f[i + 1] + mod - f[i] * a % mod) % mod;
return;
}

void solve(void) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> x[i], x[i] = -x[i];
for (int i = 1; i <= m; i++) cin >> v[i];

for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) a.emplace_back(x[i], v[j], j);
sort(a.begin(), a.end(),
[&](const tiii& a, const tiii& b) { return (int64_t)get<0>(a) * get<1>(b) < (int64_t)get<1>(a) * get<0>(b); });

f[0] = qpow(n, m);
int64_t ans = 0;
for (auto [x, y, p] : a) {
erase(coef[p], n - coef[p]);
ans = (ans + f[m / 2] * x % mod * inv(y)) % mod;
coef[p]++;
insert(coef[p], n - coef[p]);
}
cout << ans * inv(qpow(n, m)) % mod << endl;
return;
}

int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

int _ = 1;
while (_--) solve();

return 0;
}
69 changes: 69 additions & 0 deletions QOJ/9529.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* @file 9529.cpp
* @author Macesuted (i@macesuted.moe)
* @date 2024-10-26
*
* @copyright Copyright (c) 2024
*
*/

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

#define endl '\n'

#define maxn 1000005

int64_t cnt[maxn], val[maxn], tot = 0, totVal = 0;

void add(int p, int64_t v) {
tot += v, totVal += v * p;
for (int i = p; i < maxn; i += i & -i) cnt[i] += v, val[i] += v * p;
return;
}
int64_t sum(int p) {
int64_t ans = tot;
for (int i = p - 1; i; i -= i & -i) ans -= cnt[i];
return ans;
}
int64_t getAns(int p) {
int64_t ans = totVal;
for (int i = p - 1; i; i -= i & -i) ans -= val[i];
return ans;
}
int64_t solve(int64_t m) {
int l = 1, r = 1e6 + 1;
while (l + 1 < r) {
int mid = (l + r) >> 1;
(sum(mid) >= m ? l : r) = mid;
}
return getAns(l) - (sum(l) - m) * l;
}

int w[maxn], l[maxn], r[maxn];

void solve(void) {
int n;
int64_t m, ans = 0, cur = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> w[i] >> l[i] >> r[i], m -= l[i], cur += (int64_t)l[i] * w[i], add(w[i], r[i] - l[i]);
ans = cur + solve(m);
for (int i = 1; i <= n; i++) {
m += l[i], cur -= (int64_t)l[i] * w[i], add(w[i], l[i] - r[i]);
add(w[i], m);
ans = max(ans, cur + solve(m));
add(w[i], -m);
m -= l[i], cur += (int64_t)l[i] * w[i], add(w[i], r[i] - l[i]);
}
cout << ans << endl;
return;
}

int main() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

int _ = 1;
while (_--) solve();

return 0;
}

0 comments on commit 8465986

Please sign in to comment.