QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#510752 | #8649. Escape Route 2 | Max_s_xaM | 0 | 108ms | 31896kb | C++14 | 5.9kb | 2024-08-09 12:15:39 | 2024-08-09 12:15:40 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
typedef double lf;
// #define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 1e5 + 10, MAXM = 3e5 + 10;
int n, T, q;
struct line
{
int x, y, l;
bool operator < (const line &u) const { return y == u.y ? x > u.x : y < u.y; }
}pl[MAXN], b[MAXN];
int m[MAXN], top;
line *a[MAXN];
struct Qry
{
int l, r; ll res;
}qt[MAXN];
vector <int> vt[MAXN], vtb[MAXN];
int val[MAXN], fa[MAXN], lay[MAXN];
vector <pair <int, int>> e[MAXN];
ll dep[MAXN];
inline void DFS1(int u)
{
dep[u] += val[u];
for (auto [v, w] : e[u])
dep[v] = dep[u] + w, DFS1(v);
}
ll mns, rval[MAXN];
inline void DFS2(int u)
{
rval[lay[u]] = min(rval[lay[u]], dep[u] - mns);
for (auto [v, w] : e[u]) DFS2(v);
}
ll tr[MAXN * 20]; int ls[MAXN * 20], rs[MAXN * 20];
int rt[MAXN], tot;
inline void Pushup(int cur) { tr[cur] = min(tr[ls[cur]], tr[rs[cur]]); }
void Update(int &cur, int l, int r, int x, ll k)
{
if (!cur) cur = ++tot, tr[cur] = 1e18;
if (l == r) tr[cur] = k;
else
{
int mid = l + r >> 1;
if (x <= mid) Update(ls[cur], l, mid, x, k);
else Update(rs[cur], mid + 1, r, x, k);
Pushup(cur);
}
}
int Merge(int u, int v, int l, int r)
{
if (!u || !v) return u | v;
if (l == r) return tr[u] = min(tr[u], tr[v]), u;
int mid = l + r >> 1;
ls[u] = Merge(ls[u], ls[v], l, mid), rs[u] = Merge(rs[u], rs[v], mid + 1, r);
Pushup(u);
return u;
}
ll Query(int cur, int l, int r, int x)
{
if (!cur) return 1e18;
if (l == r) return tr[cur];
int mid = l + r >> 1;
if (x <= mid) return Query(ls[cur], l, mid, x);
return Query(rs[cur], mid + 1, r, x);
}
inline void DFS3(int u)
{
Update(rt[u], 1, n, lay[u], dep[u]);
for (auto [v, w] : e[u])
DFS3(v), Merge(rt[u], rt[v], 1, n);
for (auto x : vt[u])
qt[x].res = min(qt[x].res, Query(rt[u], 1, n, qt[x].l) - dep[u] + val[u]);
}
int main()
{
// freopen("A.in", "r", stdin);
// freopen("A.out", "w", stdout);
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
Read(n), Read(T);
for (int i = 1; i < n; i++)
{
Read(m[i]), a[i] = pl + top;
for (int j = 1; j <= m[i]; j++) Read(b[j].x), Read(b[j].y), b[j].l = i;
sort(b + 1, b + m[i] + 1);
for (int i = 1; i <= m[i]; i++)
if (i == 1 || b[i].x > b[i - 1].x) pl[++top] = b[i];
m[i] = pl + top - a[i];
}
for (int i = 1; i < n - 1; i++)
{
int cur = a[i] - pl + 1;
for (int j = 1, k = 1; j <= m[i]; j++, cur++)
{
while (k <= m[i + 1] && a[i + 1][k].x < a[i][j].y) k++;
if (k > m[i + 1])
{
fa[cur] = a[i + 1] + 1 - pl;
e[fa[cur]].emplace_back(cur, pl[fa[cur]].x - pl[cur].y + T);
}
else
{
fa[cur] = a[i + 1] + k - pl;
e[fa[cur]].emplace_back(cur, pl[fa[cur]].x - pl[cur].y);
}
val[cur] = a[i][j].y - a[i][j].x, lay[cur] = i;
}
}
for (int i = 1, cur = a[n - 1] - pl + 1; i <= m[n - 1]; i++, cur++)
val[cur] = a[n - 1][i].y - a[n - 1][i].x, fa[cur] = 0, lay[cur] = n - 1, e[0].emplace_back(cur, 0);
DFS1(0);
int B = 50;
Read(q);
for (int i = 1; i <= q; i++)
{
Read(qt[i].l), Read(qt[i].r);
if (qt[i].l == qt[i].r) qt[i].res = 0;
else if (m[qt[i].r - 1] <= B)
{
qt[i].res = 2e9;
for (int j = 1; j <= m[qt[i].r - 1]; j++)
vt[a[qt[i].r - 1] + j - pl].push_back(i);
}
else vtb[qt[i].r - 1].push_back(i);
}
for (int i = 1; i <= n; i++)
if (m[i] > B && vtb[i].size())
{
for (int j = 1; j <= i; j++) rval[j] = 1e18;
for (int j = 1; j <= m[i]; j++)
mns = dep[a[i] + j - pl] - val[a[i] + j - pl], DFS2(a[i] + j - pl);
for (auto x : vtb[i])
qt[x].res = rval[qt[x].l];
}
DFS3(0);
for (int i = 1; i <= q; i++) cout << qt[i].res << '\n';
return 0;
}
详细
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
2 1000000000 1 359893566 955414858 300000 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 ...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Wrong Answer
Test #39:
score: 0
Wrong Answer
time: 108ms
memory: 31896kb
input:
301 1000000000 300 863578477 865166395 261293731 262628986 290161866 292035987 31029640 32135494 288138979 289416854 321254857 322352244 163393949 166291828 897880953 899050317 840019366 842900569 100947276 102350870 520716771 522094941 820182602 822928836 766708508 769688128 727827782 728874133 740...
output:
997817610 213529190 997817610 350088722 393643222 660179422 23398481 83378757 386861905 550058707 116805742 66795163 230046137 430046477 50052816 647005237 223372288 443511904 154700724 43523554 10241276 656844377 93473524 443715068 613832268 306924502 607034565 613554290 457214808 276831487 1034634...
result:
wrong answer 1st lines differ - expected: '996840913', found: '997817610'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%