QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#688476 | #8235. Top Cluster | xxk2006 | WA | 674ms | 140664kb | C++23 | 2.8kb | 2024-10-30 09:51:32 | 2024-10-30 09:51:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define Enter putchar('\n')
#define spc putchar(' ')
#define pb push_back
#define fi first
#define se second
inline void read(int &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
inline void lread(long long &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
void print(long long num){if(num<0){putchar('-');num=-num;}if(num>9){print(num/10);}putchar((num%10)^48);}
const int N=5e5+9;
int a[N],id[N],cnt,fi[N],st[N<<1][20],lg[N<<1],dm[N][2],vi[N<<1];
struct node{
int v;
LL w;
};
LL dp[N];
vector<node> g[N];
bool cmp(const int &x,const int &y){
return a[x]<a[y];
}
void dfs(int u,int fr){
fi[u]=++cnt;
st[cnt][0]=cnt;
vi[cnt]=u;
for(int i=0;i<g[u].size();i++){
if(g[u][i].v==fr)continue;
dp[g[u][i].v]=dp[u]+g[u][i].w;
dfs(g[u][i].v,u);
st[++cnt][0]=fi[u];
vi[cnt]=u;
}
}
int ask(int x,int y){
if(!x||!y)return 0;
if(fi[x]>fi[y])swap(x,y);
int z=lg[fi[y]-fi[x]+1];
z=min(st[fi[x]][z],st[fi[y]-(1<<z)+1][z]);
return dp[x]+dp[y]-dp[vi[z]]-dp[vi[z]];
}
int main(){
int n,Q,x,y,z,mx=0;
LL s;
read(n),read(Q);
for(int i=1;i<=n;i++)read(a[i]),id[i]=i;
sort(id+1,id+n+1,cmp);
for(int i=1;i<=n;i++){
if(a[id[i]]==mx)++mx;
else break;
}
for(int i=1;i<n;i++){
read(x),read(y),read(z);
g[x].pb({y,z});
g[y].pb({x,z});
}
dfs(1,0);
for(int i=1,j=1;i<=19;i++,j<<=1){
for(int k=1;k+j+j<=n+n;k++){
st[k][i]=min(st[k][i-1],st[k+j][i-1]);
}
}
for(int i=2;i<=1e6;i++)lg[i]=lg[i>>1]+1;
dm[2][0]=dm[1][0]=id[1];
dm[2][1]=id[2];
for(int i=3;i<=mx;i++){
x=ask(dm[i-1][0],dm[i-1][1]);
y=ask(dm[i-1][0],id[i]);
z=ask(dm[i-1][1],id[i]);
if(x>=y&&x>=z){
dm[i][0]=dm[i-1][0],dm[i][1]=dm[i-1][1];
continue;
}
if(y>z){
dm[i][0]=dm[i-1][0],dm[i][1]=id[i];
}
else{
dm[i][1]=dm[i-1][1],dm[i][0]=id[i];
}
}
while(Q--){
read(x),lread(s);
if(a[1]==416779){
cout<<ask(x,id[1])<<':'<<s<<' ';
}
int l=0,r=mx,mid;
while(l<r){
mid=(l+r+1)>>1;
if(max(ask(x,dm[mid][0]),ask(x,dm[mid][1]))<=s){
l=mid;
}
else r=mid-1;
}
print(l),Enter;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 19248kb
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: 0
Accepted
time: 613ms
memory: 140664kb
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:
ok 500000 numbers
Test #3:
score: -100
Wrong Answer
time: 674ms
memory: 139512kb
input:
500000 500000 416779 59604 366180 195604 4 30957 999969109 7476 352690 368624 121597 999960303 999933891 13 14 138579 294015 227392 106760 117837 208506 999997971 34770 40258 182765 65889 206246 233051 130491 182099 117381 241945 449750 155921 356191 999955435 2243 450904 242106 178163 148523 75648 ...
output:
-1589082642:0 59 1891367656:1000000000000000 250002 1698878552:661568713826361 250002 1955331992:417788892364699 250002 787548295:28077494447002 250002 -22568885:734664119329292 250002 -1522791026:592737290415657 250002 1453526235:367992630356580 250002 -2058226200:202623682713276 250002 1924769427:...
result:
wrong output format Expected integer, but "-1589082642:0" found