QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404085 | #4891. 树上的孤独 | Butanlishi | 10 | 16ms | 99364kb | C++14 | 2.2kb | 2024-05-03 11:19:07 | 2024-05-03 11:19:12 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define rg int
#define ci const int
#define ls x<<1
#define rs x<<1|1
#define mid ((l+r)>>1)
#define ld long double
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fd(i,l,r) for(int i=(l);i>=(r);--i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
#define gcd __gcd
#define P(x) __builtin_popcountll(x)
using namespace std;
ci N=2e6+5,M=5e3+5,mod=998244353,_g=3,_ig=(mod+1)/3;
ll ksm(ll a,ll b=mod-2)
{
ll ans=1;
while(b)
{
if(b&1)ans=(ll)ans*a%mod;
a=(ll)a*a%mod,b>>=1;
}
return ans;
}
const ld eps=1e-10;
inline ll read(){ll u,f=1;char o;while((o=getchar())<48||o>57)if(o==45)f=-1;u=(o^48);while((o=getchar())>=48&&o<=57)u=(u<<1)+(u<<3)+(o^48);return u*f;}
void write(ll x){if(x<0)putchar(45),x=-x;if(x>9)write(x/10);putchar(x%10+48);}
mt19937 rad(chrono::steady_clock::now().time_since_epoch().count());
ll n,m,q,v[N],v1[N],p1,p2,d1,d2,ans;
vector<ll>w[N],w1[N];
bool f[N];
ll ceng[N],ceng1[N];
void tree(int x,int c)
{
f[x]=1;
ceng[x]=c;
for(auto d:w[x])if(!f[d])
{
tree(d,c+1);
}
}
void tree1(int x,int c)
{
f[x]=1;
ceng1[x]=c;
for(auto d:w1[x])if(!f[d])
{
tree1(d,c+1);
}
}
bool t[N];
void tr(int x,int c)
{
if(c>d1)return;
if(!t[v[x]])++ans;
t[v[x]]=1;
for(auto d:w[x])if(ceng[d]>ceng[x])
{
tr(d,c+1);
}
}
void tre(int x,int c)
{
if(c>d2)return;
if(!t[v1[x]])++ans;
t[v1[x]]=1;
for(auto d:w1[x])if(ceng1[d]>ceng1[x])
{
tre(d,c+1);
}
}
int main()
{//freopen("1.in","r",stdin);
int T=1;
while(T--)
{
n=read();m=read();q=read();
fu(i,1,n)
{
ll x=read(),y=read();
w[x].push_back(y);
w[y].push_back(x);
}
fu(i,1,m)
{
ll x=read(),y=read();
w1[x].push_back(y);
w1[y].push_back(x);
}
fo(i,1,n)v[i]=read();
fo(i,1,m)v1[i]=read();
tree(1,1);
memset(f,0,sizeof(f));
tree1(1,1);
ll last=0;
while(q--)
{
int op=read();
if(op==1)
{
ans=0;
fo(i,1,m)t[i]=0;
p1=read(),p2=read(),d1=(read()^last),d2=(read()^last);
tr(p1,0);
tre(p2,0);
write(last=ans),putchar('\n');
}
else
{
int x=read(),y=read();
v[x]=y;
}
}
}
return 0;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 11ms
memory: 99364kb
input:
20 2000 2000 8 15 8 13 14 8 14 7 12 14 12 1 9 13 9 4 5 9 5 10 2 5 2 19 6 19 6 16 11 7 11 20 18 2 18 17 3 6 1395 1783 1395 1735 1735 457 457 739 739 438 438 101 101 441 441 1879 1879 1238 1238 501 501 1732 1732 1910 1910 2000 2000 834 834 917 917 111 111 780 780 1966 1966 1604 1604 623 623 1748 1748 ...
output:
105 93 2 44 19 54 192 25 69 21 21 200 78 88 137 33 68 68 54 35 24 8 23 78 59 100 27 200 40 74 97 21 87 36 197 76 28 49 11 20 55 60 24 5 109 158 23 21 15 102 36 108 26 78 171 82 32 147 145 9 136 31 109 142 119 68 34 64 18 40 56 48 54 14 35 154 111 130 144 200 21 80 84 37 73 24 28 37 160 51 62 51 95 2...
result:
ok 1481 numbers
Test #2:
score: 10
Accepted
time: 16ms
memory: 99296kb
input:
20 2000 2000 7 9 7 4 20 4 20 15 19 7 19 3 11 9 11 8 5 19 5 1 13 19 13 10 12 5 6 3 17 8 17 14 2 3 2 18 16 5 304 1166 304 1254 1254 1939 1939 430 430 1573 1573 1917 1917 934 934 226 226 1722 1722 453 453 562 562 151 151 1985 1985 1689 1689 1492 1492 108 108 948 948 753 753 92 92 1347 1347 1940 1940 10...
output:
34 197 20 99 87 35 26 19 2 36 87 19 66 199 5 156 19 35 129 62 12 199 96 19 52 4 38 198 19 200 36 60 47 64 44 172 15 48 20 166 147 53 23 46 140 48 56 77 134 39 49 200 67 19 19 40 2 19 158 24 21 79 91 45 12 126 183 20 122 29 21 28 27 65 28 58 141 25 20 172 20 3 179 7 46 141 57 57 43 150 2 86 25 8 72 2...
result:
ok 1495 numbers
Subtask #2:
score: 0
Time Limit Exceeded
Test #3:
score: 0
Time Limit Exceeded
input:
20 200000 500000 8 18 8 4 2 4 2 14 13 4 13 16 6 4 6 3 1 4 1 17 15 6 15 19 7 17 7 11 5 14 5 10 20 7 12 15 9 8 165302 77239 165302 198189 165302 180850 165302 192738 165302 173589 165302 194087 165302 191990 165302 167370 165302 101092 165302 92553 165302 163654 165302 122381 165302 152105 165302 1919...
output:
2 17595 3898 3423 16 518 5138 11355 21 7340 21 18327 15797 6638 514 1184 6110 1884 6241 662 16738 13230 1597 5446 6074 2387 6265 2 21 282 3511 1806 1236 1038 17804 4657 5536 4633 4547 21 244 2703 2 4610 8571 4037 21 13498 5648 2054 3489 4869 5828 802 2072 1482 13232 2593 938 16769 2 17623 353 5 21 7...
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #7:
score: 0
Time Limit Exceeded
input:
20 100000 100000 16 12 16 20 6 12 6 18 2 16 2 8 5 20 5 13 3 6 3 11 19 11 19 17 9 12 9 15 4 15 4 7 10 5 14 15 14 1 85812 94626 85812 91172 91172 93788 93788 96567 96567 75524 75524 23275 23275 98340 98340 81608 81608 91480 91480 75108 75108 56605 56605 93317 93317 41617 41617 77160 77160 727 727 7559...
output:
2568 612 8337 8985 3561 9182 649 301 2478 7307 2682 1175 1401 1268 8228 4407 109 2696 640 4478 3165 9184 21 8980 2092 9950 8009 9944 21 5038 87 2038 1881 19 1292 2183 336 1101 9386 3477 7723 1958 2741 1256 2331 715 21 545 21 448 699 2332 447 18 38 1424 2321 693 2459 21 2320 714 9999 8 196 1366 8933 ...
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #13:
score: 0
Time Limit Exceeded
input:
1 200000 500000 189127 137023 189127 199761 199761 160701 160701 130639 130639 190908 190908 176819 176819 193363 193363 188021 188021 182446 182446 186028 186028 198828 198828 190792 190792 155378 155378 189428 189428 177276 177276 146159 146159 175923 175923 188073 188073 182206 182206 131072 1310...
output:
3782 1773 771 7328 18160 19394 1952 2 5498 2 2859 3368 7393 5131 5706 2 6001 19866 2 5123 2 12549 1497 4837 7770 16333 18175 5926 17983 19707 3821 17709 17094 4226 3822 576 5637 3660 4987 15686 2 18774 29 5068 16606 2276 16601 4544 598 845 19976 7054 882 164 2744 1683 6747 5091 1632 5137 2931 2778 1...
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #15:
score: 0
Time Limit Exceeded
input:
20 200000 1000000 13 10 13 5 19 5 19 20 15 10 15 6 12 6 12 3 8 10 8 2 1 20 1 11 14 10 14 16 18 3 18 7 4 3 9 10 9 17 194055 154514 194055 148156 148156 115271 115271 198116 198116 179433 179433 171975 171975 196600 196600 167194 167194 185078 185078 191409 191409 163496 163496 178243 178243 154093 15...
output:
459 5817 10120 7654 4894 19469 3577 16028 2835 7538 1131 9925 18495 497 11876 2132 9849 7576 7278 111 1850 7391 3350 6100 19488 16462 6207 1725 5922 5596 3820 1918 718 3319 2715 19890 5606 634 753 1301 15995 2973 1671 14675 5218 2639 118 1896 3266 1935 14603 4577 7219 5902 11027 4392 7461 9754 19632...