QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#401359#6330. XOR Reachableevirir#WA 216ms506508kbC++142.7kb2024-04-28 15:52:572024-04-28 15:52:57

Judging History

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

  • [2024-04-28 15:52:57]
  • 评测
  • 测评结果:WA
  • 用时:216ms
  • 内存:506508kb
  • [2024-04-28 15:52:57]
  • 提交

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];
}
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: 97ms
memory: 478696kb

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: 84ms
memory: 478624kb

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: -100
Wrong Answer
time: 216ms
memory: 506508kb

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:

3206785848745
3191047971721
3203945009821
3158150076553
99235
3155587107253
3175605859201
99235
99235
99235
99235
99235
99235
99235
3159944774101
99235
99235
99235
3202395991921
3156868461853
3204203215885
99235
99235
99235
99235
99235
99235
99235
3209886381505
3158919170221
3199557098545
99235
3198...

result:

wrong answer 1st numbers differ - expected: '99235', found: '3206785848745'