QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#499830 | #8235. Top Cluster | cz_yxx | WA | 354ms | 225796kb | C++20 | 2.4kb | 2024-07-31 19:32:31 | 2024-07-31 19:32:31 |
Judging History
answer
// sis puella oier
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
ll read(){
ll xx = 0, f = 1; char ch = getchar();
for (;!isdigit(ch); ch = getchar())
f = (ch == '-' ? -1 : 1);
for (; isdigit(ch); ch = getchar())
xx = (xx << 3) + (xx << 1) + ch - '0';
return xx * f;
}
const int N = 500100;
int n, q;
struct edge{
int v; ll w;
};
vector <edge> e[N];
int a[N];
ll dis[N];
int st[20][N << 1], lg[N << 1], fir[N], dfn;
void dfs(int x, int fath){
st[0][++dfn] = x, fir[x] = dfn;
for (edge v : e[x])
if (v.v != fath)dis[v.v] = dis[x] + v.w, dfs(v.v, x),
st[0][++dfn] = x;
}
int query(int l, int r){
int len = lg[r - l + 1];
return min(st[len][l], st[len][r - (1 << len) + 1]);
}
int lca(int x, int y){
x = fir[x], y = fir[y]; if (x > y)swap(x, y);
return query(x, y);
}
ll Dis(int x, int y){
return dis[x] + dis[y] - 2ll * dis[lca(x, y)];
}
int dd[2][N];
int vis[N];
signed main(){
n = read(), q = read();
for (int i = 1; i <= n; ++i){
a[i] = read(); if (a[i] < N)vis[a[i]] = i;
}
int mx = 0; while(vis[mx])++mx;
for (int i = 1, u, v, w; i < n; ++i)u = read(), v = read(), w = read(),
e[u].push_back(edge{v, w}), e[v].push_back(edge{u, w});
dis[1] = 0, dfs(1, 0);
lg[0] = -1; for (int i = 1; i <= dfn; ++i)lg[i] = lg[i >> 1] + 1;
for (int i = 1; i < 20; ++i)
for (int j = 1; j + (1 << i) - 1 <= dfn; ++j)
st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
dd[0][0] = vis[0], dd[1][0] = vis[0];
for (int i = 1; i < mx; ++i){
int xx = Dis(vis[i], dd[0][i - 1]), yy = Dis(vis[i], dd[1][i - 1]),
zz = Dis(dd[0][i - 1], dd[1][i - 1]);
if (xx >= yy && xx >= zz)dd[0][i] = vis[i], dd[1][i] = dd[0][i - 1];
if (yy >= xx && yy >= zz)dd[0][i] = vis[i], dd[1][i] = dd[1][i - 1];
if (zz >= xx && zz >= yy)dd[0][i] = dd[0][i - 1], dd[1][i] = dd[1][i - 1];
}
// for (int i = 0; i < mx; ++i)cout<<dd[0][i]<<" "<<dd[1][i]<<endl; cout<<endl;
while(q--){
int x = read(); ll w = read();
int l = 0, r = mx, mid;
while(l < r){
mid = (l + r) >> 1;
if (max(Dis(dd[0][mid], x), Dis(dd[1][mid], x)) > w)r = mid;
else l = mid + 1;
}
printf("%lld\n", l);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 22244kb
input:
5 4 3 9 0 1 2 1 2 10 3 1 4 3 4 3 3 5 2 3 0 1 0 4 6 4 7
output:
1 0 3 4
result:
ok 4 number(s): "1 0 3 4"
Test #2:
score: -100
Wrong Answer
time: 354ms
memory: 225796kb
input:
500000 500000 350828 420188 171646 209344 4 999941289 289054 79183 999948352 427544 160827 138994 192204 108365 99596 999987124 292578 2949 384841 269390 999920664 315611 163146 51795 265839 34188 999939494 145387 366234 86466 220368 357231 347706 332064 279036 173185 5901 217061 112848 37915 377359...
output:
0 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 249999 2499...
result:
wrong answer 6721st numbers differ - expected: '0', found: '249999'