QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#575426 | #5710. Solar Flight | zlt | 0 | 0ms | 0kb | C++14 | 4.8kb | 2024-09-19 14:11:13 | 2024-09-19 14:11:14 |
answer
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;
bool Mst;
namespace IO {
char ibuf[1 << 20], *iS, *iT, obuf[1 << 20], *oS = obuf;
#define writesp(x) write(x), pc(' ')
#define writeln(x) write(x), pc('\n')
#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, 1 << 20, stdin), (iS == iT ? EOF : *iS++) : *iS++)
template<typename T = int>
inline T read () {
char ch = gh();
T x = 0;
bool t = 0;
while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
return t ? ~(x - 1) : x;
}
inline void flush () {
fwrite(obuf, 1, oS - obuf, stdout), oS = obuf;
}
inline void pc (char ch) {
if (oS == obuf + (1 << 20)) flush();
*oS++ = ch;
}
template<typename T>
inline void write (T x) {
static char stk[64], *tp = stk;
if (x < 0) {
x = ~(x - 1);
pc('-');
}
do {
*tp++ = x % 10;
x /= 10;
} while (x);
while (tp != stk) {
pc((*--tp) | 48);
}
}
}
using IO::read;
using IO::write;
using IO::pc;
using IO::flush;
const int maxn = 2020;
ll n, m, K, id[maxn], a[maxn], b[maxn], c[maxn], d[maxn], p[maxn], q[maxn], h[maxn];
struct frac {
ll x, y;
frac(ll a = 0, ll b = 1) {
if (b < 0) {
a = -a;
b = -b;
}
x = a;
y = b;
}
};
struct node {
frac x;
ll y, z;
} g[maxn];
frac f[maxn][maxn];
bool e[maxn][maxn];
int len[maxn];
inline bool operator < (const frac &a, const frac &b) {
return (lll)a.x * b.y < (lll)a.y * b.x;
}
inline bool operator <= (const frac &a, const frac &b) {
return (lll)a.x * b.y <= (lll)a.y * b.x;
}
inline bool operator == (const frac &a, const frac &b) {
return (lll)a.x * b.y == (lll)a.y * b.x;
}
struct SGT {
ll a[8200];
inline void pushup(int x) {
a[x] = max(a[x << 1], a[x << 1 | 1]);
}
void build(int rt, int l, int r) {
if (l == r) {
a[rt] = h[l];
return;
}
int mid = (l + r) >> 1;
build(rt << 1, l, mid);
build(rt << 1 | 1, mid + 1, r);
pushup(rt);
}
void query(int rt, int l, int r, int ql, int qr, ll &x) {
if (ql > qr) {
return;
}
if (ql <= l && r <= qr) {
x = max(x, a[rt]);
return;
}
int mid = (l + r) >> 1;
if (ql <= mid) {
query(rt << 1, l, mid, ql, qr, x);
}
if (qr > mid) {
query(rt << 1 | 1, mid + 1, r, ql, qr, x);
}
}
} T[maxn];
inline int find(frac a[maxn], bool b[maxn], int l, int r, ll x) {
int pos = -1;
while (l <= r) {
int mid = (l + r) >> 1;
if (((b[mid] && a[mid].x < x * a[mid].y) || (!b[mid] && a[mid].x <= x * a[mid].y))) {
pos = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
assert(pos != -1);
return pos;
}
void solve() {
m = read();
ll X = read();
n = read();
K = read();
map<pii, ll> mp;
map< pii, vector<int> > pm;
for (int i = 1; i <= n; ++i) {
a[i] = read();
b[i] = read();
c[i] = read();
mp[mkp(a[i], b[i])] += c[i];
pm[mkp(a[i], b[i])].pb(i);
}
n = 0;
for (auto p : mp) {
a[++n] = p.fst.fst;
b[n] = p.fst.scd;
c[n] = p.scd;
for (int i : pm[mkp(a[n], b[n])]) {
id[i] = n;
}
}
for (int i = 1; i <= n; ++i) {
p[i] = i;
}
sort(p + 1, p + n + 1, [&](const ll &x, const ll &y) {
return b[x] - a[x] < b[y] - a[y] || (b[x] - a[x] == b[y] - a[y] && a[x] > a[y]);
});
ll s = 0;
for (int i = 1; i <= n; ++i) {
d[p[i]] = s;
s += c[p[i]];
q[p[i]] = i;
}
for (int i = 1; i <= n; ++i) {
int tot = 0;
for (int j = 1; j <= n; ++j) {
if (i == j) {
continue;
}
frac k1(b[i] - a[i], m), k2(b[j] - a[j], m);
if (k1 == k2) {
continue;
}
frac x((a[j] - a[i]) * m, k1.x - k2.x);
g[++tot].x = x;
g[tot].y = (q[i] < q[j] ? c[j] : -c[j]);
g[tot].z = (q[i] < q[j]);
}
sort(g + 1, g + tot + 1, [&](const node &a, const node &b) {
return (lll)a.x.x * b.x.y < (lll)b.x.x * a.x.y;
});
g[0].x = frac(-4e18, 1);
ll s = d[i];
h[0] = s;
for (int j = 1; j <= tot; ++j) {
assert(!(g[j - 1].x == g[j].x));
s += g[j].y;
h[j] = s;
}
T[i].build(1, 0, tot);
len[i] = tot;
for (int j = 0; j <= tot; ++j) {
f[i][j] = g[j].x;
e[i][j] = g[j].z;
}
}
while (K--) {
ll x = read();
ll l = read();
ll r = l + X;
x = id[x];
int L = find(f[x], e[x], 0, len[x], l), R = find(f[x], e[x], 0, len[x], r);
ll ans = -1e18;
T[x].query(1, 0, len[x], L, R, ans);
writeln(ans);
}
}
bool Med;
int main() {
fprintf(stderr, "%.2lf MB\n", (&Mst - &Med) / 1048576.);
int T = 1;
// scanf("%d", &T);
while (T--) {
solve();
}
flush();
return 0;
}
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1000 200 200 1000 657 836 23 962 796 47 497 305 25 837 161 23 220 575 33 697 109 37 401 221 43 883 211 46 727 461 26 681 209 28 413 14 49 664 986 27 431 222 47 307 121 38 638 560 45 801 149 24 878 61 36 761 356 43 839 413 32 931 573 35 218 195 46 201 697 25 951 778 21 705 905 42 861 391 23 582 718 2...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%