QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#401347#6330. XOR Reachableevirir#WA 240ms501064kbC++142.7kb2024-04-28 15:37:392024-04-29 18:16:48

Judging History

你现在查看的是最新测评结果

  • [2024-04-29 18:16:48]
  • 管理员手动重测该提交记录
  • 测评结果:WA
  • 用时:240ms
  • 内存:501064kb
  • [2024-04-28 15:37:39]
  • 提交

answer

#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;

const int MAXN = 1e6;
int szz[MAXN],par[MAXN];
int n,m,k;
int find(int x){
	if(par[x] == x)return x;
	return par[x] = find(par[x]);
}
stack<pii>stk;
ll cur = 0;
ll eval(ll x){return (x*1LL*(x-1))/2;}
bool unite(int a,int b){
	a = find(a);
	b = find(b);
	if(a==b)return 0;
	if(szz[a] > szz[b])swap(a,b);
	cur -= eval(szz[a]);
	cur -= eval(szz[b]);
	szz[b] += szz[a];
	par[a] = b;
	cur += eval(szz[b]);
	stk.push({a,b});
	return 1;
}
void reback(){
	//assert(!stk.empty());
	int a = stk.top().fi;
	int b = stk.top().se;
	stk.pop();
	cur -= eval(szz[b]);
	par[a] = a;
	szz[b] -= szz[a];
    cur += eval(szz[a]);
	cur += eval(szz[b]);
}
const int MAXNODE = 1e7;
int ch[2][MAXNODE],nodecnt = 0;
vector<pii>edge[MAXNODE];
vector<int>ansid[MAXNODE];
ll finans[MAXN];
int newnode(){
	nodecnt++;
	return nodecnt;
}
void add(int v,int cur,int dep,int id){ //add queries
	if(dep == -1){
		ansid[v].pb(id);
		return;
	}
	int c = (cur & (1<<dep)) > 0;
	if(!ch[c][v])ch[c][v] = newnode();
	add(ch[c][v],cur,dep-1,id);
}
void addedge(int v,int cur,int dep,pii ed){ //add edges
	if(dep == -1)return;
	int c = (cur & (1<<dep)) > 0;
	if(k & (1<<dep)){ //edge can be added
		if(ch[c][v])edge[ch[c][v]].pb(ed);
		if(ch[c^1][v])addedge(ch[c^1][v],cur,dep-1,ed);
	}else if(ch[c][v])addedge(ch[c][v],cur,dep-1,ed);
}
void dfs(int v){
	int cnt = 0;
	for(pii e : edge[v])cnt+=unite(e.fi,e.se);
	for(int id:ansid[v])finans[id] = cur;
	if(ch[0][v])dfs(ch[0][v]);
	if(ch[1][v])dfs(ch[1][v]);
	for(int i=0;i<cnt;i++)reback(); //reverse the changes
}
int main()
{
	owo
	cin>>n>>m>>k;
	vector<array<int,3>>edges;
	for(int i=0;i<m;i++){
		int u,v,c;
		cin>>v>>u>>c;
		edges.pb({v-1,u-1,c});
	}
	int q;
	cin>>q;
	for(int i=1;i<=q;i++){
		int d;
		cin>>d;
		add(0,d,29,i);
	}
	for(int i=0;i<n;i++){
		par[i] = i;
		szz[i] = 1;
	}
	for(auto e : edges)addedge(0,e[2],29,{e[0],e[1]});
	dfs(0);
	for(int i=1;i<=q;i++)cout<<finans[i]<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 90ms
memory: 474296kb

input:

4 5 5
1 2 17
1 3 4
2 3 20
2 4 3
3 4 5
4
0
7
16
167

output:

2
6
3
0

result:

ok 4 number(s): "2 6 3 0"

Test #2:

score: 0
Accepted
time: 76ms
memory: 476376kb

input:

9 13 488888932
2 7 771479959
3 8 783850182
5 7 430673756
6 8 350738034
4 9 400768807
2 3 83653266
1 2 829786563
5 8 357613791
7 9 579696618
3 7 423191200
3 5 867380255
1 9 907715012
6 9 1033650694
8
498260055
144262908
117665696
848664012
983408133
32610599
478007408
134182829

output:

16
7
5
13
13
16
16
5

result:

ok 8 numbers

Test #3:

score: 0
Accepted
time: 228ms
memory: 501064kb

input:

446 99235 764320136
1 2 467639025
1 39 240791819
1 197 320023434
1 391 968343602
1 116 841220144
1 345 697806443
1 409 489643820
1 339 733516272
1 89 560099922
1 431 722346703
1 433 246809211
1 344 769002876
1 234 597076758
1 178 505730391
1 75 826728597
1 74 14756981
1 63 280238017
1 288 638627144
...

output:

99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 193ms
memory: 495328kb

input:

443 100000 587238331
315 322 662401332
43 315 536337643
315 404 1008807430
140 315 116993236
315 349 456757176
315 421 208121145
222 315 165949374
315 359 652820576
128 315 366321131
219 315 385302776
279 315 758612678
315 369 524221824
315 418 405097334
315 344 159069559
114 315 1020799146
36 315 4...

output:

97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
97903
...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 207ms
memory: 498492kb

input:

446 99235 319005349
63 98 45774435
98 419 537824294
55 98 970456100
98 295 177258162
98 148 503686739
98 355 952389094
98 110 672181282
98 113 718706403
98 222 193797576
79 98 367361921
8 98 82995994
13 98 401334976
98 427 695043885
98 366 595065071
98 161 581346320
98 128 792799449
98 178 566239903...

output:

99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
99235
...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 224ms
memory: 499056kb

input:

442 100000 203918091
334 408 765591331
65 334 841282977
34 334 774464729
135 334 790897433
118 334 220810832
334 383 37271884
334 357 975552850
334 424 634443624
330 334 811688196
321 334 48524877
280 334 40028159
251 334 193460453
198 334 689798118
146 334 734763167
326 334 899636923
89 334 1067215...

output:

97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
97461
...

result:

ok 100000 numbers

Test #7:

score: -100
Wrong Answer
time: 240ms
memory: 498084kb

input:

100000 99999 131080539
55331 77587 680598826
74630 82197 773435840
9490 88468 37670073
8680 59512 493328849
38978 96144 563550542
41963 66970 73513321
1494 85761 799508674
11271 31250 1022044318
39311 99039 1054195469
26320 50975 6951442
3560 84539 467850296
32918 83458 159835633
9576 55206 85302837...

output:

15096
14918
15004
14871
15137
14863
15398
15065
15476
15027
15038
14905
15143
15137
15104
15163
15125
15105
15052
15190
15187
15156
14992
15092
15094
15082
14919
14936
15041
15098
15107
14976
14990
15087
15401
14902
15092
15133
15098
15122
14892
15178
15093
15110
15095
15210
14931
15173
14809
15455
...

result:

wrong answer 2nd numbers differ - expected: '14956', found: '14918'