QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#766502 | #8235. Top Cluster | WrongAnswer_90 | WA | 893ms | 105184kb | C++23 | 6.1kb | 2024-11-20 17:32:05 | 2024-11-20 17:32:05 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define ll long long
#define lll __int128
#define fi first
#define se second
#define e emplace
#define eb emplace_back
#define db double
#define ef emplace_front
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vp vector<pii>
#define vt vector<tup>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define FastI
#define FastO
//#define int ll
bool ST;
static const ll MOD=1e9+7,Phi=998244352,inv2=499122177,Root=3,iRoot=332748118;
static const ll inf=1073741823,Inf=4294967296,INF=4557430888798830399;
static const ld eps=1e-9,pi=3.1415926535;
char in[1<<20],*p1=in,*p2=in;
char out[1<<20],*p3=out;
using namespace std;
struct tup
{
int x,y,z;
tup(int X=0,int Y=0,int Z=0)
{x=X,y=Y,z=Z;}
bool operator <(const tup nd)const
{return x<nd.x;}
};
#ifdef FastI
#define getchar() (p1==p2&&(p2=(p1=in)+fread(in,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#endif
#ifdef FastO
#define putchar(x) (p3-out==1<<20?fwrite(out,1,1<<20,stdout),p3=out,0:0,*p3++=x)
#define puts(x) write(x,'\n')
#endif
namespace FastIO
{
template<typename T> inline void write(T x,char ch=' ')
{
if(is_same<char,T>::value)putchar(x);
else
{
if(x<0)x=-x,putchar('-');
static char st[25];
int top=0;
do st[top++]=x%10+'0',x/=10;while(x);
while(top)putchar(st[--top]);
}
ch!='~'?putchar(ch):0;
}
inline void write(const char*x,char ch=' ')
{
for(int i=0;x[i]!='\0';++i)putchar(x[i]);
ch!='~'?putchar(ch):0;
}
inline void read(char&s){do s=getchar();while(s=='\n'||s==' ');}
inline void read(char s[])
{
int len=0;char st;
do st=getchar();while(st=='\n'||st==' ');
s[++len]=st,st=getchar();
while(st!='\n'&&st!=' '&&st!='\r')s[++len]=st,st=getchar();
s[++len]='\0';
}
template<typename T> inline void read(T &s)
{
char ch=getchar();s=0;
while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
bool tf=(ch=='-'&&(ch=getchar()));
while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
s=tf?-s:s;
}
inline void edl(){putchar('\n');}
template<typename T1,typename T2> inline void read(pair<T1,T2> &s){read(s.fi),read(s.se);}
template<typename T,typename...Args> inline void write(T x,Args...args){write(x,'~'),write(args...);}
template<typename T,typename...Args> inline void read(T&x,Args&...args){read(x),read(args...);}
#ifdef FastO
struct Writer{~Writer(){fwrite(out,1,p3-out,stdout);}}Writ;
#endif
}
using namespace FastIO;
namespace MTool
{
inline int Cadd(int a,int b){return (ll)a+b>=MOD?(ll)a+b-MOD:a+b;}
inline int Cdel(int a,int b){return a-b<0?a-b+MOD:a-b;}
inline int Cmul(int a,int b){return 1ll*a*b%MOD;}
inline int sqr(int a){return 1ll*a*a%MOD;}
inline void Madd(int&a,int b){a=((ll)a+b>=MOD?(ll)a+b-MOD:a+b);}
inline void Mdel(int&a,int b){a=(a-b<0?a-b+MOD:a-b);}
inline void Mmul(int&a,int b){a=1ll*a*b%MOD;}
inline int Cmod(int x){return (x%MOD+MOD)%MOD;}
inline void Mmod(int&x){x=(x%MOD+MOD)%MOD;}
template<typename T> inline bool Mmax(T&a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool Mmin(T&a,T b){return a>b?a=b,1:0;}
template<typename...Args> inline void Madd(int&a,int b,Args...args){Madd(a,b),Madd(a,args...);}
template<typename...Args> inline void Mmul(int&a,int b,Args...args){Mmul(a,b),Mmul(a,args...);}
template<typename...Args> inline void Mdel(int&a,int b,Args...args){Mdel(a,b),Mdel(a,args...);}
template<typename...Args> inline int Cadd(int a,int b,Args...args){return Cadd(Cadd(a,b),args...);}
template<typename...Args> inline int Cmul(int a,int b,Args...args){return Cmul(Cmul(a,b),args...);}
template<typename...Args> inline int Cdel(int a,int b,Args...args){return Cdel(Cdel(a,b),args...);}
template<typename...Args,typename T> inline bool Mmax(T&a,T b,Args...args){return Mmax(a,b)|Mmax(a,args...);}
template<typename...Args,typename T> inline bool Mmin(T&a,T b,Args...args){return Mmin(a,b)|Mmin(a,args...);}
inline int power(int x,int y){int s=1;for(;y;y>>=1,Mmul(x,x))if(y&1)Mmul(s,x);return s;}
}
using namespace MTool;
namespace WrongAnswer_90
{
int n,m;
vp T[500010];
int tot,dfn[500010],dep[500010],F[19][500010];
inline int get(int x,int y){return dfn[x]<dfn[y]?x:y;}
inline int LCA(int x,int y)
{
if(x==y)return x;
if((x=dfn[x])>(y=dfn[y]))swap(x,y);
int k=__lg(y-x++);
return get(F[k][x],F[k][y-(1<<k)+1]);
}
inline int DIS(int x,int y){return dep[x]+dep[y]-2*dep[LCA(x,y)];}
int a[500010];
map<int,int> t;
pii d[500010];
void mian()
{
int x,y,z,lim;
read(n,m);
for(int i=1;i<=n;++i)read(a[i]),t[a[i]]=i;
for(int i=1;i<n;++i)
{
read(x,y,z);
T[x].eb(mp(y,z)),T[y].eb(mp(x,z));
}
for(int i=0;;++i)if(!t[i]){lim=i-1;break;}
auto dfs=[&](auto dfs,int x,int fa)->void
{
F[0][dfn[x]=++tot]=fa;
for(auto [to,v]:T[x])if(to!=fa)
dep[to]=dep[x]+v,dfs(dfs,to,x);
};
dfs(dfs,1,0);
for(int i=1;i<19;++i)
{
for(int j=1;j+(1<<i)-1<=n;++j)
F[i][j]=get(F[i-1][j],F[i-1][j+(1<<(i-1))]);
}
d[0]=mp(t[0],t[0]);
for(int i=1;i<=lim;++i)
{
int d1=DIS(d[i-1].fi,d[i-1].se);
int d2=DIS(d[i-1].fi,t[i]);
int d3=DIS(d[i-1].se,t[i]);
if(d1>=d2&&d1>=d3)d[i]=d[i-1];
else if(d2>=d3)d[i]=mp(d[i-1].fi,t[i]);
else d[i]=mp(d[i-1].se,t[i]);
}
while(m--)
{
read(x,y);
int l=-1,r=lim,mid;
while(l<r)
{
mid=(l+r+1)>>1;
if(max(DIS(d[mid].fi,x),DIS(d[mid].se,x))<=y)l=mid;
else r=mid-1;
}
write(l+1,'\n');
}
}
inline void Mian()
{
int T=1,C;
// read(C,T);
while(T--)mian();
}
}
bool ED;
signed main()
{
// ios::sync_with_stdio(0);
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
double st=clock();
WrongAnswer_90::Mian();
double ed=clock();
cerr<<endl;
cerr<<"Time: "<<ed-st<<" ms\n";
cerr<<"Memory: "<<abs(&ST-&ED)/1024.0/1024.0<<" MB\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 16208kb
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: 839ms
memory: 105180kb
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: 893ms
memory: 105184kb
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:
59 0 250002 100311 94581 250002 250002 100311 59 0 0 94581 100311 250002 59 0 59 0 59 0 0 250002 250002 100311 100311 250002 250002 0 250002 0 0 94581 59 250002 0 250002 0 59 250002 0 0 250002 0 59 1018 250002 250002 4 59 250002 100311 94581 250002 250002 250002 250002 0 0 100311 0 0 4 611 250002 25...
result:
wrong answer 1st numbers differ - expected: '0', found: '59'