QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#860920 | #9678. 网友小 Z 的树 | XY_Eleven | 41 | 1810ms | 43980kb | C++23 | 4.9kb | 2025-01-18 15:34:19 | 2025-01-18 15:34:53 |
Judging History
answer
#include <bits/stdc++.h>
#include "diameter.h"
// #include <windows.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define pii pair<int,int>
#define pli pair<long long,int>
#define vct vector
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 __xx00__
#define y1 __yy11__
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
// cLL mod[2]={1686688681ll,1666888681ll},base[2]={166686661ll,188868881ll};
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; } template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; } template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; } template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_) { if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; } LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); } void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); } template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
template <typename Type> Type bk(vector <Type> &V_) { auto T_=V_.back(); V_.pop_back(); return T_; } template <typename Type> Type tp(stack <Type> &V_) { auto T_=V_.top(); V_.pop(); return T_; } template <typename Type> Type frt(queue <Type> &V_) { auto T_=V_.front(); V_.pop(); return T_; }
template <typename Type> Type bg(set <Type> &V_) { auto T_=*V_.begin(); V_.erase(V_.begin()); return T_; } template <typename Type> Type bk(set <Type> &V_) { auto T_=*prev(V_.end()); V_.erase(*prev(V_.end())); return T_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
int rnd(int l,int r) { return rd()%(r-l+1)+l; }
void main_init()
{
}
unordered_map <ULL,int> mp;
int qry(vct <int> w)
{
sort(all(w));
ULL hs=(((ULL)w[0]<<40)|((ULL)w[1]<<20)|((ULL)w[2]));
if(mp.find(hs)!=mp.end()) return mp[hs];
return (mp[hs]=query(w[0],w[1],w[2]));
}
void operator += (array <int,3> &w1,array <int,3> w2)
{
vct <int> h={w1[0],w1[1],w1[2],w2[0],w2[1],w2[2]};
sort(all(h)); h.erase(unique(all(h)),h.end());
int len=sz(h),mx=0;
For_(i,0,len) For_(j,i+1,len) For_(k,j+1,len)
{
int t=qry({h[i],h[j],h[k]});
if(t>=mx)
w1={h[i],h[j],h[k]},mx=t;
}
}
std::pair<int, int> find_diameter(int task_id, int n)
{
if(n==1) return {1,1};
if(n==2) return {1,2};
// printf("well...\n");
mp.clear();
vct <int> a(n);
For_(i,0,n) a[i]=i+1;
shuffle(all(a),gen);
vct <array<int,3> > g;
for(int i=0;i<n;i+=3)
{
if(i+2<n) g.pb({a[i],a[i+1],a[i+2]});
else g.pb({a[n-1],a[n-2],a[n-3]});
}
int m=sz(g);
// printf("good.\n");
For_(i,1,m) g[0]+=g[i];
// printf("well down!\n");
auto [w1,w2,w3]=g[0];
auto dis=[&](int x,int y)->array<int,2>
{
array <int,2> mn={n<<2|11,0};
For(i,1,n) if(i!=x&&i!=y)
get_min(mn,{qry({x,y,i}),i});
return mn;
};
auto t1=dis(w1,w2),t2=dis(w2,w3),t3=dis(w1,w3),t=max({t1,t2,t3});
// printf("keep on!\n");
if(t2==t) w1=w3;
else if(t3==t) w2=w3;
w3=t[1];
// printf("%d,%d,%d\n",w1,w2,w3);
if(in(w1,w2,w3)) return {w2,w3};
if(in(w2,w1,w3)) return {w1,w3};
// printf("done!!!\n");
return {w1,w2};
}
详细
Subtask #1:
score: 16
Accepted
Test #1:
score: 16
Accepted
time: 6ms
memory: 10176kb
input:
1 100 25 1 3 2 18 3 8 4 18 5 14 6 22 7 18 8 10 9 11 10 12 11 25 12 16 13 11 14 17 15 17 16 25 17 2 18 20 19 18 20 12 21 1 22 17 23 14 24 1 50 1 37 2 27 3 10 4 25 5 16 6 17 7 10 8 36 9 16 10 6 11 48 12 2 13 28 14 30 15 10 16 44 17 31 18 1 19 6 20 7 21 30 22 42 23 45 24 23 25 27 26 39 27 45 28 48 29 4...
output:
correct
result:
ok Correct
Subtask #2:
score: 15
Accepted
Dependency #1:
100%
Accepted
Test #2:
score: 15
Accepted
time: 193ms
memory: 20760kb
input:
2 2006 42 1 32 2 4 3 6 4 29 5 1 6 42 7 10 8 16 9 6 10 25 11 42 12 8 13 36 14 8 15 17 16 3 17 6 18 21 19 23 20 31 21 42 22 6 23 32 24 7 25 27 26 34 27 31 28 6 29 41 30 20 31 9 32 7 33 3 34 5 35 5 36 1 37 8 38 14 39 15 40 12 41 22 95 1 94 2 88 3 13 4 71 5 37 6 45 7 87 8 24 9 76 10 54 11 69 12 95 13 90...
output:
correct
result:
ok Correct
Test #3:
score: 15
Accepted
time: 1360ms
memory: 25916kb
input:
2 100 10000 5442 1084 1084 8984 8984 3299 3299 6385 6385 6079 6079 6806 6806 2300 2300 2996 2996 1765 1765 257 257 5537 5537 2337 2337 5445 5445 2873 2873 336 336 6307 6307 4968 4968 8078 8078 9944 9944 5675 5675 7896 7896 5943 5943 2412 2412 7448 7448 7852 7852 1684 1684 3437 3437 3980 3980 1919 19...
output:
correct
result:
ok Correct
Test #4:
score: 15
Accepted
time: 1463ms
memory: 25660kb
input:
2 100 10000 1 5915 2 3020 3 9265 4 5171 5 1304 6 6769 7 1914 8 4904 9 7545 10 2296 11 4189 12 3509 13 7725 14 133 15 4023 16 7720 17 2707 18 9553 19 5215 20 6984 21 4421 22 2279 23 33 24 4737 25 4205 26 9619 27 1848 28 4322 29 5602 30 1476 31 2636 32 8841 33 3701 34 590 35 8382 36 9625 37 240 38 311...
output:
correct
result:
ok Correct
Test #5:
score: 15
Accepted
time: 1444ms
memory: 25128kb
input:
2 100 10000 9186 8585 8585 2991 9186 2522 2991 2727 2991 3356 8585 7483 3356 6258 3356 3554 2727 9199 2991 6593 2727 3223 3223 780 2727 1306 7483 6018 3223 2570 7483 826 6258 7695 6593 303 9199 8280 8280 3057 3223 2719 1306 3966 7695 7382 3966 8835 8280 983 7382 5734 8280 3094 3057 4999 2719 5934 73...
output:
correct
result:
ok Correct
Test #6:
score: 15
Accepted
time: 1430ms
memory: 27052kb
input:
2 100 10000 258 225 225 9405 9405 2228 225 912 258 2001 2001 7782 9405 2373 258 747 2001 7685 747 1101 7782 7229 2228 5458 2228 9451 9451 2073 2073 7753 5458 2328 7753 1592 1101 6637 2328 5359 1101 4393 4393 8882 1592 928 4393 9422 6637 2468 7753 3759 4393 6763 5359 8404 9422 7471 8882 7360 8404 184...
output:
correct
result:
ok Correct
Test #7:
score: 15
Accepted
time: 1424ms
memory: 26504kb
input:
2 100 10000 5715 7993 5715 6965 7993 426 6965 2015 426 1744 2015 9193 426 4406 1744 7821 7821 4607 426 1151 7821 1378 4607 999 7821 5563 1744 8800 4607 3167 7821 4424 4406 6427 8800 2796 5563 8767 6427 2096 2796 659 659 7524 8800 39 4424 2158 8767 1736 2796 4824 659 2410 2096 8710 7524 2078 8710 119...
output:
correct
result:
ok Correct
Test #8:
score: 15
Accepted
time: 1272ms
memory: 31268kb
input:
2 100 10000 475 1 475 2 475 3 475 4 475 5 475 6 475 7 475 8 475 9 475 10 475 11 475 12 475 13 475 14 475 15 475 16 475 17 475 18 475 19 475 20 475 21 475 22 475 23 475 24 475 25 475 26 475 27 475 28 475 29 475 30 475 31 475 32 475 33 475 34 475 35 475 36 475 37 475 38 475 39 475 40 475 41 475 42 475...
output:
correct
result:
ok Correct
Subtask #3:
score: 5
Accepted
Dependency #2:
100%
Accepted
Test #9:
score: 5
Accepted
time: 307ms
memory: 30212kb
input:
3 2006 95 1 50 2 83 3 65 4 31 5 64 6 83 7 22 8 17 9 12 10 24 11 81 12 82 13 70 14 71 15 16 16 66 17 68 18 25 19 64 20 90 21 19 22 14 23 4 24 55 25 11 26 15 27 47 28 90 29 33 30 10 31 73 32 4 33 32 34 13 35 46 36 42 37 36 38 17 39 47 40 67 41 23 42 72 43 75 44 92 45 57 46 88 47 78 48 43 49 58 50 62 5...
output:
correct
result:
ok Correct
Test #10:
score: 5
Accepted
time: 1495ms
memory: 34432kb
input:
3 50 20000 12483 13249 13249 6419 6419 18097 18097 17847 17847 2932 2932 14960 14960 6371 6371 3371 3371 18403 18403 18882 18882 16513 16513 13330 13330 7685 7685 2725 2725 9445 9445 10962 10962 6952 6952 5108 5108 12657 12657 4299 4299 9621 9621 4521 4521 16644 16644 14790 14790 15234 15234 13858 1...
output:
correct
result:
ok Correct
Test #11:
score: 5
Accepted
time: 1616ms
memory: 35908kb
input:
3 50 20000 1 10511 2 8258 3 11981 4 12921 5 14758 6 443 7 5500 8 4105 9 15921 10 19586 11 6477 12 14217 13 9381 14 10767 15 6566 16 3232 17 18904 18 15280 19 17754 20 1743 21 994 22 16695 23 13403 24 2947 25 14089 26 19962 27 12998 28 4014 29 8751 30 8029 31 14686 32 8019 33 13808 34 852 35 2992 36 ...
output:
correct
result:
ok Correct
Test #12:
score: 5
Accepted
time: 1581ms
memory: 36640kb
input:
3 50 20000 14783 6405 14783 997 14783 15183 6405 4079 14783 3959 6405 13688 13688 394 6405 18458 997 2652 2652 8182 6405 8855 13688 13569 3959 9652 18458 19932 3959 2233 13688 2925 2925 17109 9652 520 2652 3931 2925 12446 2233 17300 520 11989 17300 14352 17300 1490 14352 17585 17109 15867 3931 7306 ...
output:
correct
result:
ok Correct
Test #13:
score: 5
Accepted
time: 1557ms
memory: 36800kb
input:
3 50 20000 5219 5072 5072 18451 5219 1483 5219 6164 6164 11035 1483 9913 9913 10220 6164 6063 6164 2560 1483 987 6164 16481 16481 13784 6063 485 10220 11717 2560 16335 6063 19981 987 6387 13784 14504 2560 14762 16481 11230 13784 13201 14504 9437 14762 19951 6387 7610 16335 1501 9437 14901 9437 13391...
output:
correct
result:
ok Correct
Test #14:
score: 5
Accepted
time: 1559ms
memory: 36100kb
input:
3 50 20000 11410 9893 11410 2259 11410 13823 2259 14136 9893 18639 2259 5699 9893 13085 9893 13095 2259 4627 5699 5572 13823 12950 13823 17350 12950 12984 4627 14584 5572 9511 13095 18547 17350 13655 17350 11614 14584 17057 5572 1023 13655 3546 17057 8142 1023 2641 17057 13187 13655 10323 11614 1419...
output:
correct
result:
ok Correct
Test #15:
score: 5
Accepted
time: 1350ms
memory: 39212kb
input:
3 50 20000 13608 1 13608 2 13608 3 13608 4 13608 5 13608 6 13608 7 13608 8 13608 9 13608 10 13608 11 13608 12 13608 13 13608 14 13608 15 13608 16 13608 17 13608 18 13608 19 13608 20 13608 21 13608 22 13608 23 13608 24 13608 25 13608 26 13608 27 13608 28 13608 29 13608 30 13608 31 13608 32 13608 33 1...
output:
correct
result:
ok Correct
Subtask #4:
score: 5
Accepted
Dependency #3:
100%
Accepted
Test #16:
score: 5
Accepted
time: 418ms
memory: 39952kb
input:
4 2006 72 1 11 2 33 3 63 4 45 5 70 6 23 7 41 8 51 9 63 10 71 11 56 12 36 13 55 14 1 15 45 16 68 17 37 18 65 19 1 20 42 21 16 22 27 23 1 24 14 25 4 26 13 27 52 28 34 29 28 30 72 31 43 32 13 33 47 34 6 35 26 36 69 37 16 38 9 39 47 40 6 41 10 42 50 43 28 44 9 45 35 46 28 47 51 48 68 49 59 50 26 51 10 5...
output:
correct
result:
ok Correct
Test #17:
score: 5
Accepted
time: 1696ms
memory: 41500kb
input:
4 33 30000 14256 19392 19392 17693 17693 12064 12064 29690 29690 2629 2629 2231 2231 8291 8291 20777 20777 13056 13056 17592 17592 3521 3521 9564 9564 20486 20486 11910 11910 5841 5841 8074 8074 8949 8949 27794 27794 5140 5140 628 628 23696 23696 219 219 27931 27931 12329 12329 11380 11380 16340 163...
output:
correct
result:
ok Correct
Test #18:
score: 5
Accepted
time: 1810ms
memory: 42560kb
input:
4 33 30000 1 10055 2 15066 3 26132 4 2602 5 25450 6 3181 7 10378 8 16011 9 14843 10 5467 11 23120 12 20330 13 4410 14 24149 15 1259 16 25325 17 5148 18 22993 19 14548 20 17083 21 21423 22 4431 23 2608 24 27414 25 7398 26 680 27 6389 28 7789 29 24276 30 23976 31 21652 32 14331 33 4244 34 2538 35 1511...
output:
correct
result:
ok Correct
Test #19:
score: 5
Accepted
time: 1750ms
memory: 41040kb
input:
4 33 30000 5160 22570 5160 4162 22570 4564 22570 2953 22570 6160 2953 16958 5160 18469 18469 16390 4564 4820 4820 26260 4820 23921 4820 22416 16390 5064 18469 21384 4820 18969 22416 2213 18469 10791 23921 18801 2213 28618 23921 12934 12934 23199 2213 2731 23199 13937 18801 7907 18969 12659 2213 1006...
output:
correct
result:
ok Correct
Test #20:
score: 5
Accepted
time: 1703ms
memory: 42860kb
input:
4 33 30000 5124 14169 14169 7693 14169 3148 7693 7827 7827 5425 14169 4462 7693 5036 7827 1840 5036 15358 3148 354 15358 25457 354 23612 5036 809 15358 28504 15358 220 28504 12793 1840 25908 354 240 25908 14658 354 12184 23612 25257 14658 26851 809 10856 12184 23643 14658 23748 23643 7400 7400 19133...
output:
correct
result:
ok Correct
Test #21:
score: 5
Accepted
time: 1717ms
memory: 41100kb
input:
4 33 30000 16458 22215 22215 25117 16458 10098 16458 19468 19468 19780 22215 18948 25117 1930 10098 601 22215 28765 1930 28418 25117 12818 10098 29737 29737 8189 12818 2531 28765 23263 12818 20088 20088 3660 28765 3752 29737 2048 3752 10286 20088 14216 20088 5154 3752 12129 2531 5116 3660 12518 5116...
output:
correct
result:
ok Correct
Test #22:
score: 5
Accepted
time: 1485ms
memory: 43980kb
input:
4 33 30000 16829 1 16829 2 16829 3 16829 4 16829 5 16829 6 16829 7 16829 8 16829 9 16829 10 16829 11 16829 12 16829 13 16829 14 16829 15 16829 16 16829 17 16829 18 16829 19 16829 20 16829 21 16829 22 16829 23 16829 24 16829 25 16829 26 16829 27 16829 28 16829 29 16829 30 16829 31 16829 32 16829 33 1...
output:
correct
result:
ok Correct
Subtask #5:
score: 0
Wrong Answer
Dependency #4:
100%
Accepted
Test #23:
score: 0
Wrong Answer
time: 204ms
memory: 42180kb
input:
5 2006 74 1 63 2 63 3 55 4 35 5 36 6 63 7 64 8 71 9 61 10 47 11 18 12 62 13 41 14 59 15 70 16 27 17 5 18 30 19 59 20 65 21 28 22 41 23 18 24 20 25 14 26 4 27 63 28 17 29 37 30 49 31 7 32 64 33 2 34 7 35 32 36 22 37 7 38 26 39 46 40 18 41 37 42 73 43 19 44 53 45 15 46 20 47 53 48 63 49 10 50 15 51 15...
output:
WA
result:
wrong answer Wrong Answer
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%
Subtask #9:
score: 0
Skipped
Dependency #8:
0%
Subtask #10:
score: 0
Skipped
Dependency #9:
0%
Subtask #11:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
0%