QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#543498#9. 简单回路5un_xiaomivita_msg100 ✓3ms4520kbC++143.5kb2024-09-01 17:01:092024-09-01 17:01:09

Judging History

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

  • [2024-09-01 17:01:09]
  • 评测
  • 测评结果:100
  • 用时:3ms
  • 内存:4520kb
  • [2024-09-01 17:01:09]
  • 提交

answer

#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=1005,M=10,S=55,mod=1e9+7;
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
int n,m;
int a[N];
void in_a(){
	int k=read(),x,y;
	while (k--)
		x=read(),y=read(),a[x]|=1<<y;
}
int id[N],val[S][M],scnt=0,can[S];
vector <pii> trans[S];
vector <int> opp[S];
void getmatch(int *s,int *p){
	static int st[M];
	int top=0;
	For(i,1,m)
		if (s[i]==1)
			st[++top]=i;
		else if (s[i]==-1)
			p[i]=st[top],p[st[top]]=i,top--;
}
void get_trans(int x,int e){
	static int f[M],p[M],d[M],res[M],vis[M];
	clr(f),clr(p),clr(res),clr(vis);
	int *s=val[x];
	For(i,1,m-1)
		f[i]=e>>(i-1)&1;
	int zzy=0;
	For(i,1,m){
		d[i]=(s[i]!=0)+f[i-1]+f[i];
		if (s[i]!=0&&f[i-1]&&f[i])
			return;
		if (d[i])
			zzy|=1<<i;
	}
	getmatch(s,p);
	For(i,1,m){
		if (vis[i]||d[i]!=1)
			continue;
		int j=i;
		while (j==i||d[j]==2){
			int nxt=0;
			vis[j]=1;
			if (p[j]&&!vis[p[j]])
				nxt=p[j];
			else if (f[j-1]&&!vis[j-1])
				nxt=j-1;
			else if (f[j]&&!vis[j+1])
				nxt=j+1;
			if (!nxt)
				return;
			j=nxt;
		}
		vis[j]=1;
		res[min(i,j)]=1,res[max(i,j)]=-1;
	}
	For(i,1,m)
		if (d[i]&&!vis[i])
			return;
	int Res=0;
	Fod(i,m,1)
		Res=Res*3+res[i]+1;
	trans[x].pb(mp(id[Res],zzy));
}
int check_opposite(int *a,int *b){
	static int pa[M],pb[M],vis[M];
	clr(vis);
	For(i,1,m)
		if ((a[i]!=0)^(b[i]!=0))
			return 0;
	getmatch(a,pa),getmatch(b,pb);
	int cnt=0;
	For(i,1,m)
		if (a[i]!=0)
			cnt++;
	For(i,1,m)
		if (a[i]!=0){
			int x=i;
			For(t,1,cnt){
				vis[x]=1,x=(t&1?pa:pb)[x];
				if (t<cnt&&vis[x])
					return 0;
			}
			return 1;
		}
}
void getval(int m){
	static int tmp[M];
	int p3=pow(3,m);
	For(i,0,p3-1){
		clr(tmp);
		int t=i,s=0,flag=1,empty=1,Can=0;
		For(j,1,m){
			tmp[j]=t%3-1;
			if (s==1&&Can!=-1)
				Can|=1<<j;
			s+=tmp[j];
			if (s==1&&Can!=-1)
				Can|=1<<j;
			if (s>1)
				Can=-1;
			empty&=s==0;
			flag&=s>=0;
			t/=3;
		}
		flag&=s==0;
		flag&=!empty;
		if (flag){
			id[i]=++scnt;
			For(j,1,m)
				val[scnt][j]=tmp[j];
			can[scnt]=Can;
		}
	}
	For(i,1,scnt){
		For(e,0,(1<<(m-1))-1)
			get_trans(i,e);
		For(j,1,scnt)
			if (check_opposite(val[i],val[j]))
				opp[i].pb(j);
	}
}
int pre[N][S],suf[N][S];
int ans[N][M];
int main(){
	n=read(),m=read();
	in_a();
	getval(m);
	For(i,1,n){
		For(j,1,scnt){
			if (can[j]!=-1&&!(can[j]&a[i]))
				Add(pre[i][j],1);
			int v=pre[i-1][j];
			if (!v)
				continue;
			for (auto t : trans[j])
				if (!(t.se&a[i]))
					Add(pre[i][t.fi],v);
		}
	}
	Fod(i,n,1){
		For(j,1,scnt){
			if (can[j]!=-1&&!(can[j]&a[i]))
				Add(suf[i][j],1);
			int v=suf[i+1][j];
			if (!v)
				continue;
			for (auto t : trans[j])
				if (!(t.se&a[i]))
					Add(suf[i][t.fi],v);
		}
	}
	For(i,1,n-1)
		For(j,1,scnt)
			for (auto o : opp[j]){
				int v=(LL)pre[i][j]*suf[i+1][o]%mod;
				For(k,1,m)
					if (val[j][k]!=0)
						Add(ans[i][k],v);
			}
	int q=read();
	while (q--){
		int x=read(),y=read();
		printf("%d\n",ans[x][y]);
	}
	return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 0ms
memory: 4128kb

input:

100 1 10
68 1
13 1
48 1
51 1
30 1
90 1
74 1
79 1
80 1
63 1
10
73 1
84 1
10 1
44 1
3 1
16 1
17 1
47 1
49 1
94 1

output:

0
0
0
0
0
0
0
0
0
0

result:

ok 10 lines

Test #2:

score: 10
Accepted
time: 0ms
memory: 4436kb

input:

1000 2 10
468 2
177 1
597 1
396 1
548 2
279 1
601 1
349 1
453 2
217 2
100
954 1
468 1
427 2
948 1
739 2
605 2
177 1
20 2
506 1
778 2
141 1
621 1
273 1
203 2
584 2
718 2
371 2
973 2
892 2
374 2
585 2
419 2
953 2
347 2
575 2
353 2
830 1
196 1
603 2
630 2
144 2
84 2
566 1
598 2
749 1
878 1
322 1
250 2
...

output:

16238
0
775
18044
36018
1580
0
3120
1558
39294
4935
7580
280
338
432
32994
528
10044
31428
525
407
759
16544
68
567
168
38930
380
794
10730
4608
7728
540
2
37148
33794
1118
924
1548
2119
26918
34250
39618
34100
1134
39420
343
39248
495
35244
23288
5980
0
1134
35894
108
205
39800
29088
6783
2744
6960...

result:

ok 100 lines

Test #3:

score: 10
Accepted
time: 1ms
memory: 4492kb

input:

1000 2 10
378 2
63 1
276 2
245 2
826 1
422 1
634 1
970 1
707 1
386 1
100
987 1
262 2
913 1
201 1
685 1
969 2
382 1
460 1
45 1
535 2
54 2
16 2
436 2
668 1
136 1
210 1
660 2
956 1
743 1
549 2
228 2
967 2
624 2
465 1
135 1
854 1
593 1
359 2
941 1
459 1
456 2
763 2
558 2
116 2
38 2
187 2
108 2
749 1
911...

output:

221
221
4872
5934
1071
0
12
6574
765
11074
432
736
2758
1292
7884
4998
1196
1690
2952
10668
2640
282
1818
7224
7848
3220
6840
1494
3220
6438
6018
3472
10200
6784
912
7068
6120
3192
4930
2338
2508
910
2640
120
276
3192
3820
5022
306
4120
2394
8160
4056
8778
420
6550
1007
861
3780
672
0
232
7638
5124
...

result:

ok 100 lines

Test #4:

score: 10
Accepted
time: 1ms
memory: 4520kb

input:

1000 3 10
186 3
140 3
410 1
639 1
836 2
399 2
432 3
712 1
946 3
958 3
100
203 3
895 1
351 1
503 2
991 1
61 2
760 1
647 3
70 3
75 1
522 2
539 3
417 1
53 2
404 1
467 2
283 1
313 2
793 3
290 2
410 1
827 1
572 1
534 3
765 2
977 1
97 3
797 3
966 3
404 2
479 1
653 3
212 2
164 2
960 1
655 1
304 1
182 1
190...

output:

774407976
694095038
666138398
204700661
487361334
79350260
823916526
764051786
649505956
109016625
819157802
869272506
187719766
93956822
405866989
762991904
313225905
177696788
482536746
637310259
0
626821887
869378231
769919477
251726603
475569128
292349487
564212025
952435308
73133171
62595819
36...

result:

ok 100 lines

Test #5:

score: 10
Accepted
time: 1ms
memory: 4420kb

input:

1000 5 10
230 1
368 1
815 1
540 3
496 4
860 4
892 1
183 2
175 2
704 1
100
365 1
79 5
154 1
775 4
451 2
382 2
641 2
509 2
613 4
629 2
24 3
628 4
438 2
894 5
386 3
588 5
742 2
700 2
470 5
333 4
347 3
824 2
98 2
946 4
359 4
199 3
903 1
13 2
545 4
718 5
158 3
462 5
15 3
138 5
101 3
525 5
394 2
282 3
566...

output:

255313133
198711426
709908692
202266051
77483890
70816947
486244587
535778571
857174696
464921974
591852597
571087830
900923282
627572960
657973436
588444767
456815831
993400752
550269707
309249815
991055086
72310503
6278116
270111338
157378677
840998873
389578400
24785591
885045730
151955912
804470...

result:

ok 100 lines

Test #6:

score: 10
Accepted
time: 2ms
memory: 4436kb

input:

1000 6 10
459 1
653 6
840 4
256 3
298 1
841 2
749 1
30 5
155 2
534 5
100
703 1
169 2
577 3
818 1
784 5
520 3
106 5
52 4
38 1
533 1
729 4
88 4
586 5
828 6
547 1
194 2
74 4
448 3
673 6
778 1
180 3
612 1
814 6
784 6
658 3
969 3
350 5
606 2
257 1
753 3
309 4
480 4
355 4
33 2
47 4
195 3
282 4
867 5
226 4...

output:

999278415
594533423
158845938
194065635
769822666
533011343
700362024
443754879
944208745
831983863
707285307
174723803
935733740
978498081
724829584
280201524
183926651
442776458
126095745
8538043
43419260
968594228
294701620
390790060
458477986
195299986
160837961
155893675
711976636
159043597
948...

result:

ok 100 lines

Test #7:

score: 10
Accepted
time: 3ms
memory: 4476kb

input:

1000 6 10
322 5
8 2
165 5
590 3
823 6
171 1
987 1
130 2
474 3
838 5
10000
854 4
329 1
324 2
361 4
479 4
657 6
27 1
121 3
57 5
790 4
81 1
246 3
720 5
917 4
430 6
506 3
129 3
752 2
119 6
382 1
146 4
233 3
420 5
20 1
413 5
925 5
466 4
682 5
632 4
128 4
574 1
503 4
543 1
274 3
273 5
742 2
399 4
36 3
237...

output:

595188785
667944190
314417791
752439644
641823686
515316433
58804700
336950961
933535521
2868079
207144313
71277070
386636137
916684593
867094095
830746248
811397768
929504184
87024646
747954891
34929422
395035741
217238535
699184158
736012085
223990011
802132336
915351442
958365629
736885883
759678...

result:

ok 10000 lines

Test #8:

score: 10
Accepted
time: 3ms
memory: 4496kb

input:

1000 6 10
454 6
42 2
861 3
46 2
592 2
220 1
641 1
415 4
687 3
803 5
10000
646 2
362 3
870 5
523 5
589 4
984 1
981 1
361 4
496 5
584 2
271 1
707 1
111 5
714 3
855 4
793 5
943 2
459 2
422 2
194 6
404 6
786 3
12 5
33 6
628 3
199 1
87 2
882 4
207 2
890 5
121 5
769 2
611 2
398 5
869 6
479 6
926 1
952 4
3...

output:

907977256
741709128
835059245
542122265
475578983
916515386
69389990
49669586
484301249
151643224
898801156
512291994
750542508
665420875
978604406
575992047
600837253
899909003
913430850
681088320
768699588
277603055
187322115
204278151
2217376
363853699
805776298
217379303
394742930
847780993
4583...

result:

ok 10000 lines

Test #9:

score: 10
Accepted
time: 3ms
memory: 4520kb

input:

1000 6 10
855 4
342 2
897 3
652 6
279 2
715 3
439 1
582 6
711 1
249 3
10000
581 2
907 2
221 6
92 2
355 3
342 2
130 5
820 6
90 2
802 1
803 1
87 3
170 5
553 4
432 2
891 1
523 2
519 4
174 6
933 6
796 3
691 6
982 5
871 1
430 6
230 2
133 6
271 4
442 6
268 6
452 5
656 2
502 3
14 3
248 2
470 2
710 5
954 5
...

output:

55066393
47567952
899919307
785112996
677520802
0
211618816
14834145
924330903
765282866
286990013
923382338
640289977
515759832
942286492
710493309
968735934
290525150
574558298
731844661
91067461
292231136
448817826
320805179
282925392
449866469
867779040
525405846
539977418
224538208
737887203
79...

result:

ok 10000 lines

Test #10:

score: 10
Accepted
time: 3ms
memory: 4500kb

input:

1000 6 10
959 3
380 5
181 5
388 6
749 5
342 5
944 1
918 3
870 1
753 4
10000
383 4
321 3
646 1
893 4
776 3
664 2
518 5
234 1
114 6
639 1
764 1
207 1
877 3
273 5
764 1
799 5
385 6
314 3
982 6
784 6
819 5
83 6
651 4
221 3
355 1
829 4
144 6
862 3
786 2
385 6
857 4
53 4
55 4
710 4
186 2
735 2
878 3
955 5...

output:

933292809
241755375
509075825
738068601
863044446
479708205
232992174
981436143
81390251
616737139
7883133
974806893
97687945
198614136
7883133
623895941
755943096
500138829
136995774
639388494
973798975
551405043
939360725
552988652
584245979
700640766
834722332
917451907
571653342
755943096
148462...

result:

ok 10000 lines