QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#152339#6330. XOR ReachableaestheticWA 2874ms332328kbC++145.5kb2023-08-28 03:12:082023-08-28 03:12:09

Judging History

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

  • [2023-08-28 03:12:09]
  • 评测
  • 测评结果:WA
  • 用时:2874ms
  • 内存:332328kb
  • [2023-08-28 03:12:08]
  • 提交

answer

#include "bits/stdc++.h"
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
// #define int long long
 
#define dbg_loc() cerr << __PRETTY_FUNCTION__ << " : " << __LINE__ << "\n"
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p){ 
	return os << '(' << p.first << ", " << p.second << ')'; 
}
template<typename T_container,typename T=typename enable_if<!is_same<T_container,string>::value, typename T_container::value_type>::type> 
ostream& operator<<(ostream &os, const T_container &v){ 
	os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; 
}
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ 
	cerr << ' ' << H; 
	dbg_out(T...); 
}
#define LOCAL
#define LOCAL
#ifdef LOCAL 
#define dbg(...) cerr<<"(" << #__VA_ARGS__<<"):" , dbg_out(__VA_ARGS__) , cerr << endl
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll mod = (1000000007LL);
inline ll Mod(ll a, ll b){return (a%b);}
inline ll poww(ll a, ll b){ll res = 1;while (b > 0){if(b & 1) res = (res * a)%mod;a = (a * a)%mod;b >>= 1;}return res;}
ll gcd (ll a, ll b) { while (b) { a %= b,swap(a, b);}return a;}
void read(vector<int> &w, int n){w.resize(n);for(int i = 0; i < n; i++) cin>>w[i];}
void print(vector<int> &w){for(int i =0; i < sz(w); i++){if(i == sz(w) - 1) cout<<w[i]<<"\n";else cout<<w[i]<<" ";}}
 #define allin(a , x) for(auto a : x)

///CUIDADO COM MAXN
#define N 112345 // 1E6
 
int n, m, q, k, v[N];

const int MAXL = 31;
const int MX = N * MAXL;
int trie[MX][2], qr[MX];
int cnt[MX];
int nodes = 1;

// s(s-1)/2
//sˆ2 - s
struct UF{
	vi pai, peso, S;
	vector<vector<ll>> pilha;

	ll ans = 0;
	UF(int n=0){
		pai.resize(n+1), peso.resize(n+1);
		rep(i,1,n+1) pai[i]=i,peso[i]=1;
	}
	int Find(int x){
		if(x==pai[x]) return x;
		return Find(pai[x]);
	}
	//S2 - S
	void join(int a, int b){
		a = Find(a), b= Find(b);
		pilha.pb({a, b, pai[a], pai[b], peso[a], peso[b], ans});
		if(a==b) return;
		ans += -(1LL*peso[a]*peso[a] - 1LL*peso[a]) - (1LL*peso[b]*peso[b] - 1LL*peso[b]);
		if(peso[a] < peso[b]) swap(a,b);
		peso[a] += peso[b];
		pai[b]=a;
		ans += 1LL*peso[a]*peso[a] - 1LL*peso[a];
	}

	void rollback(){
		// assert(!pilha.empty());
		auto r = pilha.back();
		int a = r[0], b = r[1];
		pai[a] = r[2], pai[b] = r[3], peso[a] = r[4], peso[b] = r[5];
		// dbg("rem", a, b);
		ans = r[6];
		pilha.pop_back();
	}
} T;

bool terminal[30*N];
void add(int x,int val = 1){
    int no = 1; // root
    cnt[no]+=val;
    for(int i=MAXL-1;i >= 0;i--){
        int b = x>>i&1;
        if(!trie[no][b])trie[no][b] = ++nodes;
        no = trie[no][b];
        cnt[no]+=val;
    }
    terminal[no] = 1;
}

int tempo=0, ini[30*N],fim[30*N];
vi tempos;
void dfs(int x){
	if(!x) return;
	ini[x] = ++tempo;
	if(terminal[x])tempos.pb(ini[x]);
	dfs(trie[x][0]), dfs(trie[x][1]);
	fim[x] = tempo;
}
vector<vi> edges;
vector<pii> intervalo[N];
int bit(int x, int i){
	if(x&(1<<i)) return 1;
	return 0;
}
void get(int x, int id){
	int no = 1;
	for(int i = MAXL - 1; i >= 0; i--){
		if(!no) return;
		int bk = bit(k, i), bx = bit(x, i);
		if(bk == 1){
			// se C e D tem o mesmo bit entao é sempre < K
			if(trie[no][bx]) intervalo[id].pb({ini[trie[no][bx]], fim[trie[no][bx]]});
			no = trie[no][bx^1];
		}
		else no = trie[no][bx];
	}
}

int mapa[2*412345];
struct dcq{
	vector<vector<ll>> st; int n;
	dcq(int n =412345) : st(2*n , vector<ll>()),  n(n){}
	void upd(int x , int y , ll q){ //evento Q em [X,Y] (eventos 0 index)
		for(x += n, y += n+1; x < y ; x/=2 , y/=2){
			if(x&1) st[x++].push_back(q);
			if(y&1) st[--y].push_back(q);
		}
		return;
	}
	void solve(int curr = 1){
		allin(w, st[curr]){
			int a = edges[w][0], b = edges[w][1];
			T.join(a, b);
		}
		if(curr >= n){
			mapa[curr-n] = T.ans;
		}
		else{
			solve(2*curr) ; solve(2*curr+1);
		}
		// da roll back
		for(int c=0;c<sz(st[curr]);c++)T.rollback();
		return;
	}	
};
int ininode[N];
int noe[N];
void solve_case(){
	cin>>n>>m>>k;
	T = UF(n);
	for(int i = 1, a, b, c; i <= m; i++){
		cin>>a>>b>>c;
		edges.pb({a, b, c});
	}
	cin>>q;
	for(int i = 1; i <= q; i++){
		cin>>qr[i];
		add(qr[i]);
	}
	dcq D;
	dfs(1);
	for(int i = 1; i<= q; i++){
		int x=qr[i];
		int no = 1; // root
	    for(int i=MAXL-1;i >= 0;i--){
	        int b = x>>i&1;
	        no = trie[no][b];
	    }
	    noe[i] = no;
	    tempos.pb(ini[no]);
	}
	for(int i=0;i<m;i++){
		get(edges[i][2], i);
		for(auto w: intervalo[i]) tempos.pb(w.f), tempos.pb(w.s);
	}
	sort(all(tempos)), tempos.erase(unique(all(tempos)), tempos.end());
	for(int i=0;i<m;i++){
		get(edges[i][2], i);

		for(auto w: intervalo[i]){
			auto l=upper_bound(all(tempos), w.f) - tempos.begin();
			auto r=upper_bound(all(tempos), w.s) - tempos.begin();		
			D.upd(l,r,i);
		}
	}

	for(int i = 1; i<= q; i++){
		int x=qr[i];
		int no = noe[i];
	    ininode[i] = upper_bound(all(tempos), ini[no]) - tempos.begin();
	}

	D.solve();

	for(int i = 1; i <= q; i++){
		cout<<mapa[ ininode[i] ]/2<<"\n";
	}
 
}
 
int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int test_case=1;
	// cin>>test_case;
	while(test_case--){
		solve_case();
	}
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 38940kb

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: 4ms
memory: 36948kb

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: 1494ms
memory: 318776kb

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: 761ms
memory: 179276kb

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: 1585ms
memory: 202556kb

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: 1102ms
memory: 204268kb

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: 0
Accepted
time: 1294ms
memory: 219220kb

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
14956
15004
14891
15137
14885
15410
15089
15502
15087
15083
14905
15143
15137
15104
15163
15143
15111
15090
15190
15187
15156
14992
15150
15100
15082
14919
14952
15047
15120
15117
14992
14990
15087
15411
14916
15092
15133
15139
15130
14910
15184
15132
15122
15105
15210
14939
15173
14829
15455
...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 2300ms
memory: 315696kb

input:

99248 100000 880016512
9609 60188 1029518407
67457 77348 128441060
8850 51205 291062482
9624 19858 873440302
20602 31653 646044502
60977 74199 403271514
77359 98694 422310541
18100 53413 641772941
31582 84949 147530174
20254 46153 615653756
78917 86611 850029098
1309 67868 867784476
96643 98988 2712...

output:

5879363
7746507
9770252
7878863
4967006
5004278
4977178
4462464
4171192
4889527
9480939
4983900
5303714
6557680
6810967
13375644
5057196
7210193
6272443
6998946
6557952
4869510
4462624
5179208
5002020
8220896
4489581
7017776
9264220
4838591
8881657
5606801
6164119
6939146
4997590
6840650
5164401
554...

result:

ok 100000 numbers

Test #9:

score: 0
Accepted
time: 1672ms
memory: 261728kb

input:

100000 99999 780251002
27269 79999 468071962
21739 82319 682546466
8544 67158 927078439
41968 89207 892254915
48895 55914 193589771
811 49765 490891662
16872 46729 638680406
17867 44058 1070155835
10241 98888 957737438
2201 46513 627847434
21108 88949 186267330
51802 94981 1008817703
20063 25385 676...

output:

851649
896751
856223
866092
859330
890327
903448
864667
873749
844234
887957
862832
833840
905858
833512
864850
890697
875940
877015
889585
919407
899670
879354
835757
889043
891332
909448
910965
855701
898062
868582
884660
898820
827552
858726
865812
887067
893299
882047
902597
880316
836660
868968...

result:

ok 100000 numbers

Test #10:

score: 0
Accepted
time: 2168ms
memory: 276400kb

input:

99806 100000 506098337
11316 29606 1053169611
432 77576 188106174
60898 63565 97507616
2948 56878 759293962
57945 69338 892503621
46617 98850 666735935
8904 20788 54696907
42854 49896 442509177
55987 59613 499913803
2227 46042 620057838
1275 36485 557003410
67033 68875 81080762
22626 80910 375900469...

output:

142524
143221
141571
141415
141524
142903
143150
143834
142172
143779
142631
141438
143293
143212
143554
142975
142308
143115
143789
145039
145108
143357
142820
142972
143680
143486
142794
143012
141832
141238
143252
141992
143985
143054
143789
143443
143073
141272
143134
141352
142940
143778
143199...

result:

ok 100000 numbers

Test #11:

score: 0
Accepted
time: 2085ms
memory: 310380kb

input:

100000 99999 880261730
49362 60034 719788352
49362 82351 832947612
79673 82351 727350251
79673 98801 931190441
83274 98801 44235181
21205 83274 530387154
19108 21205 173298793
19108 91835 42875759
27763 91835 658199843
27698 27763 541513285
27698 69932 660043688
51737 69932 28343715
51737 64682 7092...

output:

463133
455785
451937
457179
465888
460719
456177
451132
460492
449885
456575
457673
455205
452446
453629
450871
454195
452710
452761
454742
448762
462880
454503
450564
457018
457173
446406
455921
452926
449909
455853
452542
457657
449390
451219
455492
460180
454384
451712
451310
457955
450590
453810...

result:

ok 100000 numbers

Test #12:

score: 0
Accepted
time: 2874ms
memory: 294748kb

input:

99280 100000 664494301
16664 29169 599202135
16664 23186 47757770
23186 47063 53266202
47063 85549 1072849246
63153 85549 506433067
63153 80308 580031399
51234 80308 348201803
51234 73193 964438190
73193 84836 959143019
13056 84836 425988976
13056 24417 378109570
332 24417 407996769
332 15544 127696...

output:

169861
168547
170195
167590
167947
171070
169400
169439
168358
168772
169763
168179
170227
169694
170376
170362
170270
168542
168205
170671
170992
167808
170218
169766
169488
169765
169621
169346
170434
169658
168462
167814
168089
169909
169162
169769
169559
169763
171592
170886
168176
170407
170956...

result:

ok 100000 numbers

Test #13:

score: 0
Accepted
time: 1752ms
memory: 290068kb

input:

100000 99999 387919793
43583 94512 58705781
10271 43583 170607984
10271 32855 106243875
16854 32855 410273584
3517 16854 890474326
3517 30975 1001361623
20910 30975 1002711314
20910 35013 187670767
32382 35013 239178409
18343 32382 649107746
18343 98413 178223318
98413 99691 35024867
52041 99691 870...

output:

55965
57403
55280
57482
55332
57469
55577
56542
55629
55614
57389
56900
56227
55407
56343
56292
55715
55744
55868
55483
56329
56020
55483
56524
55703
57237
55332
55946
56013
55305
56717
56599
56629
57509
57456
56122
57308
56593
55645
55568
57383
55493
55754
55628
55604
55622
55635
57476
56916
55462
...

result:

ok 100000 numbers

Test #14:

score: 0
Accepted
time: 2033ms
memory: 332328kb

input:

99215 100000 802557726
18718 91317 755608910
18718 63717 531481378
30529 63717 642051004
30529 98706 599162314
42379 98706 1033145474
12300 42379 475403483
12300 12338 704395523
12338 98081 711250138
57669 98081 696479725
3890 57669 159898669
3890 64697 759770705
64697 85928 251213884
11945 85928 50...

output:

325883
325574
325225
327438
326494
328594
325193
325522
326677
325193
326907
327836
326189
325885
325339
326122
325379
327013
327616
326596
326962
324792
325751
325773
325810
326287
327825
325773
327896
326283
327310
325931
326309
326164
324663
326225
324826
325760
327847
325563
326191
325762
325419...

result:

ok 100000 numbers

Test #15:

score: 0
Accepted
time: 1932ms
memory: 316992kb

input:

100000 99999 402174476
58524 93393 539162433
24909 58524 573965219
58524 88865 99051060
58524 97907 525721613
28122 58524 520563970
18857 58524 305560747
492 58524 1044154487
58524 84138 410295914
4924 58524 880315377
58524 79039 763682384
58524 88879 903645824
58524 84125 286649901
58524 98278 1032...

output:

698949966
700146910
701756916
705846378
701831845
702281503
705808806
702056656
696820446
701906778
701307426
702656328
703631341
701831845
701157628
700371451
701569611
696745785
702056656
699884991
702918765
705696096
696633801
698763036
699361300
701831845
700221753
699697936
706184571
701831845
...

result:

ok 100000 numbers

Test #16:

score: -100
Wrong Answer
time: 1697ms
memory: 312016kb

input:

99105 100000 921189055
27602 89467 871564070
73578 89467 892334196
33998 89467 730765033
42525 89467 490770744
10543 89467 48350959
23444 89467 648340211
63556 89467 691268936
37607 89467 427726217
32870 89467 435269802
72115 89467 999718290
6379 89467 905774706
15973 89467 135638767
21262 89467 507...

output:

-670174327
-670429764
-651247618
-651332991
-676302149
-668897056
-657135534
-669067373
-671962153
-661484396
-658244314
-670089193
-671281130
-660290850
-670089193
-653808171
-661910615
-652271953
-670855466
-659438192
-651162252
-666171443
-660290845
-670429766
-657050232
-661484396
-651503721
-67...

result:

wrong answer 1st numbers differ - expected: '3624792969', found: '-670174327'