QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225617#7587. Road ManagerCrysflyAC ✓1305ms156976kbC++172.8kb2023-10-24 21:08:512023-10-24 21:08:52

Judging History

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

  • [2023-10-24 21:08:52]
  • 评测
  • 测评结果:AC
  • 用时:1305ms
  • 内存:156976kb
  • [2023-10-24 21:08:51]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
typedef unsigned int uint32;
#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 10005
#define inf 0x3f3f3f3f

uint32 SA,SB,SC;int lim;
inline int rnd(){
    SA^=SA<<16;SA^=SA>>5;SA^=SA<<1;
    uint32 t=SA;SA=SB;SB=SC;SC^=t^SA;
    return SC%lim+1;
}

int n,m;
int a[maxn][105],dw[maxn][105];

int fa[maxn];
inline int getf(int x){
	while(x^fa[x])x=fa[x]=fa[fa[x]];
	return x;
}

struct edge{
	int u,v,w;
	bool operator <(const edge&b)const{return w<b.w;}
};

struct mst{
	vector<edge>e;
	int n,sum;
	inline int ask(){
		int res=sum;
		for(auto t:e)res+=t.w;
		return res;
	}
}pre[maxn],suf[maxn];

int tot;
vector<edge>e;
vector<pii>g[maxn];

inline void adde(int u,int v,int w){
	g[u].pb(mkp(v,w)),g[v].pb(mkp(u,w));
}

vector<edge>chose;
int sumw,cnt;
bool vis[maxn];
int col[maxn];

bool getvis(int u,int pa){
	int s=0;
	for(auto it:g[u]){
		int v=it.fi;
		if(v!=pa) s+=getvis(v,u);
	}
	if(s>=2) vis[u]=1;
	s+=vis[u];
	return (s>=0);
}

void dfs(int u,int pa,int lst,int lstw)
{
	if(vis[u]){
		if(lst) chose.pb((edge){col[u],lst,lstw});
		lst=col[u],sumw-=lstw,lstw=0;
	}
	for(auto it:g[u]){
		int v=it.fi;
		if(v!=pa) dfs(v,u,lst,max(lstw,it.se));
	}
}

mst merge(mst a,mst b,int*c)
{
	// 只保留左右关键点的 mst虚树上最大边 
	tot=a.n+b.n; e.clear();
	for(auto t:a.e) e.pb(t);
	for(auto t:b.e) e.pb((edge){t.u+a.n,t.v+a.n,t.w});
	For(i,1,n) e.pb((edge){a.n-n+i,a.n+i,c[i]});
	sort(e.begin(),e.end());
	
	For(i,1,tot) fa[i]=i,vis[i]=(i<=n||i>=tot-n+1),g[i].clear();
	
	chose.clear(),sumw=cnt=0;
	for(auto t:e)
		if(getf(t.u)!=getf(t.v))
			fa[getf(t.u)]=getf(t.v),adde(t.u,t.v,t.w),sumw+=t.w;
	
	getvis(1,0);
	For(i,1,tot)
		if(vis[i]) col[i]=++cnt;
	dfs(1,0,0,0);
	
	mst ret;
	ret.n=cnt; ret.sum=a.sum+b.sum+sumw;
	ret.e=chose; return ret;
}

mst getmst(int *a){
	mst ret;
	ret.n=n,ret.sum=0;
	For(i,1,n-1) ret.e.pb((edge){i,i+1,a[i]});
	return ret;
}

signed main()
{
	cin>>n>>m>>SA>>SB>>SC>>lim;
	For(i,1,n)
		For(j,1,m) a[j][i]=rnd();
	For(i,1,n-1)
		For(j,1,m) dw[j][i]=rnd();
	
	pre[1]=getmst(dw[1]);
	For(i,2,m-1)
		pre[i]=merge(pre[i-1],getmst(dw[i]),a[i-1]);
	suf[m]=getmst(dw[m]);
	Rep(i,m-1,2)
		suf[i]=merge(getmst(dw[i]),suf[i+1],a[i]);
	
	int Q=read();
	while(Q--)
	{
		int l=read(),r=read();
		printf("%lld\n",(merge(suf[r+1],pre[l-1],a[m])).ask());
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 6888kb

input:

2 4 1 2 3 5
3
2 2
2 3
3 3

output:

9
5
13

result:

ok 3 number(s): "9 5 13"

Test #2:

score: 0
Accepted
time: 2ms
memory: 8864kb

input:

50 50 858397672 21575781 421714252 50
50
10 30
25 41
10 44
41 45
47 47
39 42
20 38
28 47
12 15
26 32
9 25
18 26
7 15
5 8
7 31
8 37
41 42
18 21
32 32
14 35
6 22
12 26
42 45
9 23
14 14
5 6
8 24
25 43
37 38
15 46
26 43
35 48
22 30
20 45
21 49
11 12
6 46
15 45
21 43
4 40
4 18
28 37
32 38
18 26
32 32
10 ...

output:

21046
24218
11414
32468
35179
33298
22126
22012
33300
30838
23977
29055
29918
33069
18185
14871
34615
32954
35312
20094
24226
25181
33130
25535
35374
34492
24067
22758
34675
13257
23443
26215
29241
17292
15165
34743
7157
13953
19672
9730
25603
29117
31267
29055
35312
8400
2536
14565
27209
33993

result:

ok 50 numbers

Test #3:

score: 0
Accepted
time: 1063ms
memory: 153184kb

input:

100 10000 753738892 852022308 109208427 5
10000
6068 9618
3347 9710
3237 5987
428 8918
183 2017
3654 8017
6218 8094
1812 4054
783 4265
638 6139
1780 6091
1559 1706
6627 8952
2958 6234
6213 8049
1860 9764
988 8148
4992 5669
7214 9591
4245 8494
5417 9671
2840 4466
5799 8328
5436 7160
1136 1170
3134 38...

output:

1211623
682743
1361117
283679
1533910
1058719
1526089
1457348
1224581
844519
1068307
1850478
1441600
1262311
1533505
393355
533670
1750612
1431335
1079803
1078983
1572722
1403657
1554603
1871623
1742851
796103
1436810
1618909
1627701
824187
1689150
1552343
1846414
1756497
505159
1260003
174270
83303...

result:

ok 10000 numbers

Test #4:

score: 0
Accepted
time: 1056ms
memory: 154660kb

input:

100 10000 252296658 470686114 738681417 5
10000
19 9941
4573 8431
1956 8010
6495 7523
1584 9576
3805 7368
945 8568
753 6106
3261 6017
4137 4690
8260 8284
3732 7371
2222 9531
174 6288
4011 4548
7675 8100
787 5858
3504 4912
5358 9086
492 8450
4746 5765
2833 5471
6990 8945
4020 8049
2168 5355
4144 7941...

output:

14776
1154093
741074
1685175
377030
1209281
446018
873015
1360987
1773494
1873502
1195181
505818
729771
1776734
1797785
925822
1613267
1178272
383399
1687330
1382812
1510227
1121331
1279314
1165058
781005
726730
964577
989349
1175799
1824181
1485743
1279135
1225339
594598
1482362
1727286
655503
1852...

result:

ok 10000 numbers

Test #5:

score: 0
Accepted
time: 1254ms
memory: 154384kb

input:

100 10000 784936363 827067061 800454511 1000000000
10000
2056 2962
5233 5350
1346 2099
8529 8825
2358 3371
3217 6419
1175 9635
2998 7699
1494 9244
2710 5459
1647 8372
6360 8398
1256 9955
1252 1473
4171 4704
4867 7373
3208 7839
2949 8996
4731 7531
8915 9536
2199 5546
2265 6448
1463 9131
2358 2383
625...

output:

218107916833770
236956297236591
221611594649234
232654372445039
215511117763537
163015473624889
37013079700783
127182022450125
54041351200568
173843674045542
78674875729514
191084774917088
31305721956998
234464326245872
227032500475120
179858820611878
128837146174236
94963670830748
172797399335623
2...

result:

ok 10000 numbers

Test #6:

score: 0
Accepted
time: 1258ms
memory: 155644kb

input:

100 10000 72129929 485897764 129463885 1000000000
10000
383 7372
2861 4738
5799 7101
3570 9122
3175 4173
1444 7532
6191 9348
3164 6316
2122 4663
1589 2869
4784 7741
3529 5974
4792 7378
6016 8170
864 1289
1647 7570
293 1602
1054 8521
6193 9882
4543 5121
956 5006
1858 7086
4117 7517
9736 9847
7917 865...

output:

72090982299191
194600560760132
208326087759066
106457378837533
215695913806908
93645900885474
163942628341738
164031689768437
178662309764579
208841353815076
168610752734842
180880159627225
177470699352697
187964294311616
229294854382327
97557084520879
208227727138432
60656821171511
151175099594593
...

result:

ok 10000 numbers

Test #7:

score: 0
Accepted
time: 1305ms
memory: 156504kb

input:

100 10000 963446001 261040754 78671748 1000000000
10000
1308 8621
2948 6287
2647 3069
103 5392
3204 9085
7669 8375
2823 5662
6455 7017
530 4194
567 9892
2436 9869
3149 6625
3015 7571
1051 1155
30 5077
1138 9673
8598 9184
5453 8895
902 7796
2749 5653
334 2677
4818 7123
2693 8574
1945 2913
6278 7799
6...

output:

64264200768233
159631014825609
229412046850098
112894812377726
98703295232189
222675254882181
171598041130418
226137587624448
151655725634932
16103717296049
61433187417017
156336180363989
130459314798835
237120775693771
118682572200864
34995983081351
225547690108471
157054836420411
74239996440524
17...

result:

ok 10000 numbers

Test #8:

score: 0
Accepted
time: 1295ms
memory: 156976kb

input:

100 10000 64237141 422265017 577403465 1000000000
10000
1335 3887
3017 4150
13 5940
619 9252
2124 8016
6189 8581
3524 6793
5826 9716
880 1859
6383 6421
1312 3139
4259 6148
1005 2744
1353 8445
6463 9223
6923 9215
901 1803
1202 1820
1053 6563
3677 7206
7691 9391
4533 8068
4360 7698
4769 8394
1629 5350...

output:

178476322146618
212581735474540
97664015826725
32720953154164
98586242468815
182463260674934
161421747872055
146457120526990
216189917671016
238821446345616
195878926340178
194435416584804
198022374418219
69770884358102
173557137328055
184789377313284
218050741659725
224873943256047
107596574583740
...

result:

ok 10000 numbers