QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#360761 | #4891. 树上的孤独 | dengtingyu | 40 | 368ms | 215580kb | C++20 | 4.9kb | 2024-03-22 07:52:13 | 2024-03-22 07:52:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200010
#define Q 1001000
ll n,m,q;
vector<ll>g[N],e[N];
ll d1[N],c1[N],df1[N],s1[N];ll dc1=0;
inline bool pd1(ll x,ll y){return df1[x]<=df1[y]&&df1[y]<=df1[x]+s1[x]-1;}
inline void dfs(ll x,ll fa){
d1[x]=d1[fa]+1;df1[x]=++dc1;s1[x]=1;
for(auto o:g[x])if(o!=fa)dfs(o,x),s1[x]+=s1[o];
return ;
}
ll dep[N],col[N];
ll siz[N],son[N],top[N],fa[N];
ll dfn[N],dfncnt=0;
inline bool pd(ll x,ll y){return dfn[x]<=dfn[y]&dfn[y]<=dfn[x]+siz[x]-1;}
inline void dfs1(ll x,ll faa){
fa[x]=faa;siz[x]=1;dep[x]=dep[faa]+1;
for(auto o:e[x]){
if(o==faa)continue;
dfs1(o,x);siz[x]+=siz[o];
if(siz[o]>siz[son[x]])son[x]=o;
}return ;
}
ll dui[N];
inline void dfs2(ll x,ll tp){
top[x]=tp;dfn[x]=++dfncnt;dui[dfncnt]=x;
if(son[x]){
dfs2(son[x],tp);
}for(auto o:e[x]){
if(!dfn[o])dfs2(o,o);
}return ;
}
inline ll lca(ll x,ll y){
while(top[x]!=top[y]){
if(dep[top[x]]<dep[top[y]])swap(x,y);
x=fa[top[x]];
}if(dep[x]<dep[y])swap(x,y);
return y;
}
ll rt[N],lc[N*40],rc[N*40],val[N*40];ll gg=0;
inline void pushup(ll o){val[o]=val[lc[o]]+val[rc[o]];return ;}
inline void update(ll &o,ll l,ll r,ll x,ll y){
if(!o)o=++gg;if(l==r){val[o]+=y;return ;}
ll mid=(l+r)>>1;
if(mid>=x)update(lc[o],l,mid,x,y);
else update(rc[o],mid+1,r,x,y);
pushup(o);return ;
}
inline ll merge(ll o,ll p,ll l,ll r){
if(!o||!p)return o+p;
ll nw=++gg;if(l==r){val[nw]=val[o]+val[p];return nw;}
ll mid=(l+r)>>1;
lc[nw]=merge(lc[o],lc[p],l,mid);
rc[nw]=merge(rc[o],rc[p],mid+1,r);
pushup(nw);return nw;
}
inline ll ask(ll o,ll l,ll r,ll x,ll y){
if(!o)return 0;if(x<=l&&r<=y)return val[o];
ll an=0,mid=(l+r)>>1;
if(mid>=x)an+=ask(lc[o],l,mid,x,y);
if(mid<y)an+=ask(rc[o],mid+1,r,x,y);
return an;
}
ll tem[N];ll cn=0;ll mi[N];
vector<ll>ex[N],wc[N];
inline bool cmp(ll x,ll y){return dfn[x]<dfn[y];}
ll vv[N];
inline void build(){
sort(tem+1,tem+cn+1,cmp);cn=unique(tem+1,tem+cn+1)-tem-1;for(int i=1;i<=cn;i++)vv[tem[i]]=1;
ll pre=cn;for(int i=1;i<pre;i++)tem[++cn]=lca(tem[i],tem[i+1]);
sort(tem+1,tem+cn+1,cmp);cn=unique(tem+1,tem+cn+1)-tem-1;
for(int i=2;i<=cn;i++)ex[lca(tem[i-1],tem[i])].push_back(tem[i]);
return ;
}
inline void gt(ll x){
if(vv[x])mi[x]=dep[x];
for(auto o:ex[x]){
gt(o);update(rt[x],1,n,mi[o],-1);
mi[x]=min(mi[x],mi[o]);
}update(rt[x],1,n,mi[x],1);
return ;
}
vector<ll>hs[N],dd[N],ji[N],xw[N];
inline void clear(ll tp){
// if(tp==3)cout<<tem[1]<<' '<<mi[tem[1]]<<' '<<dd[tem[1]].size()<<'\n';
for(int i=1;i<=cn;i++)hs[tem[i]].push_back(tp),dd[tem[i]].push_back(mi[tem[i]]),ex[tem[i]].clear(),mi[tem[i]]=n+1,vv[tem[i]]=0;cn=0;
return ;
}
inline void idfs(ll x,ll fa){
for(auto o:e[x]){
if(o==fa)continue;
idfs(o,x);rt[x]=merge(rt[x],rt[o],1,n);
}return ;
}
#define V 20001000
ll x[V],y[V],ans[V];ll cnt=0;
ll fir[Q],p1[Q],p2[Q],p3[Q],p4[Q];ll gs=0;
ll vis[N];
int main(){
// freopen("test1.in","r",stdin);
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>m>>n>>q;for(int i=1,u,v;i<m;i++)cin>>u>>v,g[u].push_back(v),g[v].push_back(u);for(int i=1,u,v;i<n;i++)cin>>u>>v,e[u].push_back(v),e[v].push_back(u);
for(int i=1;i<=m;i++)cin>>c1[i];for(int i=1;i<=n;i++)cin>>col[i],wc[col[i]].push_back(i);
dfs(1,0);dfs1(1,0);dfs2(1,1);
for(int i=1;i<=n;i++)mi[i]=n+1;
for(int i=1;i<=n;i++){
for(auto o:wc[i])tem[++cn]=o;if(!cn)continue;
build();gt(tem[1]);
clear(i);
}idfs(1,0);
for(int i=1;i<=q;i++){
ll op;cin>>op;if(op==1){
++gs;cin>>p1[gs]>>p2[gs]>>p3[gs]>>p4[gs];
fir[gs]=cnt;for(int i=1;i<=m;i++){
x[++cnt]=p2[gs];y[cnt]=c1[i];xw[p2[gs]].push_back(cnt);
}
}else{
ll x,y;cin>>x>>y;c1[x]=y;
}
}for(int t=1;t<=n;t++){
ll i=dui[t];for(auto o:xw[i])ji[y[o]].push_back(o);
ll nw=0;for(auto o:hs[i]){
ll val=dd[i][nw++];
for(auto p:ji[o]){
if(pd(x[p],i))ans[p]=val;
else ans[p]=n+1;
}ji[o].clear();
}
}for(int i=1;i<=n;i++)for(auto o:ji[i])ans[o]=n+1;
// cout<<val[rt[1]]<<'\n';
// cout<<ask(rt[1],1,n,1,3)<<'\n';return 0;
// cout<<cnt<<'\n';for(int i=1;i<=cnt;i++)cout<<ans[i]<<'\n';
ll las=0;for(int i=1;i<=gs;i++){
p3[i]^=las;p4[i]^=las;ll lim=min(dep[p2[i]]+p4[i],n);
las=ask(rt[p2[i]],1,n,1,lim);
for(int j=1;j<=m;j++){
if(!pd1(p1[i],j)||d1[j]>d1[p1[i]]+p3[i]||ans[fir[i]+j]<=lim||vis[y[fir[i]+j]])continue;
las++;vis[y[fir[i]+j]]=1;
}for(int j=fir[i]+1;j<=fir[i]+m;j++)vis[y[j]]=0;
cout<<las<<'\n';
}return 0;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 3ms
memory: 7280kb
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: 0
Accepted
time: 8ms
memory: 7356kb
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
Runtime Error
Test #3:
score: 0
Runtime Error
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:
result:
Subtask #3:
score: 30
Accepted
Test #7:
score: 30
Accepted
time: 362ms
memory: 215344kb
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:
ok 74842 numbers
Test #8:
score: 0
Accepted
time: 321ms
memory: 212072kb
input:
20 100000 100000 6 12 6 15 20 12 20 5 9 15 9 14 2 20 2 19 7 5 7 4 3 20 3 16 10 7 10 8 18 20 18 1 13 4 13 11 17 13 76027 68976 76027 57693 57693 93102 93102 28171 28171 85749 85749 99702 99702 83297 83297 72320 72320 89998 89998 69676 69676 84244 84244 44418 44418 78575 78575 4284 4284 99851 99851 90...
output:
1821 2139 1444 3155 8443 9995 2539 27 64 3274 2129 2 259 2719 152 3900 6031 5006 6290 879 1083 6041 496 6004 670 6 1451 1405 7249 977 9500 402 1104 1444 2795 2267 1171 1971 2886 5045 3 2699 765 3885 241 21 2683 1746 1756 7401 1111 4371 1107 1025 1369 1455 1420 2128 2165 6077 2793 1825 1263 2042 136 ...
result:
ok 74861 numbers
Test #9:
score: 0
Accepted
time: 352ms
memory: 210636kb
input:
20 100000 100000 16 17 16 12 15 16 15 8 1 12 1 9 2 15 2 13 7 12 7 5 11 2 11 19 3 8 3 6 4 15 10 17 10 18 14 13 14 20 67546 88879 67546 89198 89198 92647 92647 60049 60049 72475 72475 67403 67403 26140 26140 9738 9738 85753 85753 31691 31691 30604 30604 84416 84416 92592 92592 96710 96710 84006 84006 ...
output:
3320 1811 2176 1515 9571 9829 2737 1223 1728 9815 9933 897 151 272 300 6209 7663 673 1113 918 2190 1241 1106 9988 4 7359 2882 2299 3278 3088 503 3767 1274 2 2160 4738 4304 184 75 2238 3879 192 9987 2744 1320 4089 2428 2759 740 2689 9306 85 3841 1510 3091 3 9327 3677 3221 4692 9315 7211 1780 9997 170...
result:
ok 74827 numbers
Test #10:
score: 0
Accepted
time: 350ms
memory: 207724kb
input:
20 100000 100000 2 3 2 6 17 2 17 10 5 2 5 9 20 10 20 18 7 2 7 16 13 2 13 8 4 10 4 14 11 17 11 15 19 10 19 12 1 11 85514 99510 85514 84831 85514 68620 85514 48208 85514 42479 85514 71645 85514 80596 85514 88493 85514 99514 85514 31378 85514 80504 85514 81861 85514 94839 85514 69330 85514 40591 85514 ...
output:
2 1716 3641 9997 3794 1209 3165 2597 1563 8595 463 4162 893 3028 435 8705 6861 1923 2814 2796 20 2363 1933 1893 762 673 13 7862 2839 2008 2985 2779 9993 2480 3 3712 9951 113 1062 9981 2059 697 3 109 2045 7767 861 149 70 9999 928 21 1017 2082 111 3375 242 1095 3325 880 3574 538 1954 20 376 1434 3507 ...
result:
ok 74851 numbers
Test #11:
score: 0
Accepted
time: 325ms
memory: 215580kb
input:
20 100000 100000 12 10 12 5 17 5 14 10 14 8 9 8 9 13 16 12 16 19 6 8 6 3 18 19 18 15 1 12 1 7 20 19 20 4 2 12 11 4 34733 89384 34733 80376 80376 95740 95740 97840 97840 69394 69394 38211 38211 59175 59175 97280 97280 76697 76697 84307 84307 75221 75221 94161 94161 57166 57166 84005 84005 75107 75107...
output:
2486 7650 3313 2 7109 665 5733 1639 3748 5026 3376 3356 4964 9976 4326 982 2015 90 250 1631 3294 625 6789 7678 10000 653 3152 3312 3102 21 7581 2202 230 21 133 9852 3458 21 1652 5963 8692 2 121 3913 1395 3458 7411 3857 1934 355 3 3083 3213 9957 3132 281 8830 1462 6288 2980 1317 1648 897 1353 3303 19...
result:
ok 74832 numbers
Test #12:
score: 0
Accepted
time: 368ms
memory: 210740kb
input:
20 100000 100000 6 8 6 5 9 5 9 11 16 5 16 10 13 8 13 18 20 11 20 4 1 8 1 15 12 5 12 14 7 11 3 13 3 17 19 15 2 10 95202 70596 95202 63084 63084 80990 80990 97264 97264 75236 75236 76413 76413 21787 21787 79077 79077 23111 23111 87359 87359 12982 12982 71974 71974 94809 94809 78084 78084 89131 89131 9...
output:
3795 833 1450 8881 944 1103 4920 6523 2458 3126 642 4493 2278 300 3728 1304 155 474 99 6044 1871 2030 1058 2494 1320 1114 9563 853 1303 3571 377 5761 4259 1225 1700 705 24 1825 3684 2056 2800 9144 3778 1773 61 13 6935 44 9555 5851 2059 1639 3055 1632 2845 9999 9955 1577 610 587 3685 3517 865 66 1521...
result:
ok 74853 numbers
Subtask #4:
score: 0
Runtime Error
Test #13:
score: 0
Runtime Error
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:
result:
Subtask #5:
score: 0
Runtime Error
Test #15:
score: 0
Runtime Error
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...