QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#397140 | #2678. 多边形 | LVJBot1 | 100 ✓ | 39ms | 14888kb | C++14 | 2.2kb | 2024-04-23 17:29:27 | 2024-04-23 17:29:27 |
Judging History
answer
/* Submission UUID: 40a62217-9e2b-43c4-8ac4-22f4c0daf95d. */
#include<bits/stdc++.h>
#define il inline
#define rg register
#define vd void
#define mod 1000000007
il int gi(){int x=0,f=0;char ch=getchar();while(!isdigit(ch))f^=ch=='-',ch=getchar();while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return f?-x:x;}int n,x[100010],y[100010];int s[100010],m;std::vector<int>G[100010];int L[100010],R[100010],ch[100010][2],cnt;std::vector<int>ch0;il int build(int l,int r){if(r-l<2)return 0;++cnt;L[cnt]=l,R[cnt]=r;int ret=cnt,t=*--std::lower_bound(G[l].begin(),G[l].end(),r);ch[ret][0]=build(l,t);ch[ret][1]=build(t,r);return ret;}int p[100010],ip[100010];il int C(int n,int m){if(n<m)return 0;return 1ll*p[n]*ip[m]%mod*ip[n-m]%mod;}il int invC(int n,int m){if(n<m)return 0;return 1ll*ip[n]*p[m]%mod*p[n-m]%mod;}int f[100010];il vd dp(int x){if(!ch[x][0]&&!ch[x][1]){f[x]=1;return;}if(!ch[x][0]||!ch[x][1]){dp(ch[x][0]|ch[x][1]);f[x]=f[ch[x][0]|ch[x][1]];return;}dp(ch[x][0]),dp(ch[x][1]);f[x]=1ll*f[ch[x][0]]*f[ch[x][1]]%mod*C(R[x]-L[x]-2,R[ch[x][0]]-L[ch[x][0]]-1)%mod;}int main(){int W=gi();n=gi();int ans1=n-3;for(int i=1;i<n;++i)G[i].push_back(i+1);G[1].push_back(n);for(int i=1;i<=n-3;++i){x[i]=gi(),y[i]=gi();if(x[i]>y[i])std::swap(x[i],y[i]);if(y[i]==n)--ans1,s[++m]=x[i];G[x[i]].push_back(y[i]);}for(int i=1;i<=n;++i)std::sort(G[i].begin(),G[i].end());int Q=gi();s[++m]=1,s[++m]=n-1;std::sort(s+1,s+m+1);for(int i=1;i<m;++i)ch0.push_back(build(s[i],s[i+1]));p[0]=1;ip[0]=1;for(int i=1;i<=n;++i)p[i]=1ll*p[i-1]*i%mod;ip[1]=1;for(int i=2;i<=n;++i)ip[i]=mod-1ll*ip[mod%i]*(mod/i)%mod;for(int i=1;i<=n;++i)ip[i]=1ll*ip[i-1]*ip[i]%mod;int ans=1,siz=0;for(auto i:ch0)if(i)dp(i),ans=1ll*ans*C(siz+R[i]-L[i]-1,siz)%mod*f[i]%mod,siz+=R[i]-L[i]-1;if(W)printf("%d %d\n",ans1,ans);else printf("%d\n",ans1);while(Q--){int l=gi(),r,k=gi(),t;if(l>k)std::swap(l,k);r=*std::upper_bound(G[l].begin(),G[l].end(),k);t=*--std::lower_bound(G[l].begin(),G[l].end(),k);if(r==n){if(W)printf("%d %d\n",ans1-1,1ll*ans*invC(ans1,k-l-1)%mod*C(ans1-1,k-l-2)%mod);else printf("%d\n",ans1-1);continue;}if(W)printf("%d %d\n",ans1-(r==n),1ll*ans*invC(k-l-2,t-l-1)%mod*invC(r-l-2,r-k-1)%mod*C(r-t-2,k-t-1)%mod*C(r-l-2,t-l-1)%mod);else printf("%d\n",ans1-(r==n));}return 0;}
详细
Test #1:
score: 5
Accepted
time: 0ms
memory: 8136kb
input:
1 9 1 6 1 4 2 4 4 6 6 9 6 8 0
output:
5 15
result:
ok 2 number(s): "5 15"
Test #2:
score: 5
Accepted
time: 1ms
memory: 7984kb
input:
1 10 1 8 1 7 1 4 2 4 4 7 5 7 8 10 0
output:
6 6
result:
ok 2 number(s): "6 6"
Test #3:
score: 5
Accepted
time: 1ms
memory: 8640kb
input:
1 11 1 6 1 4 2 4 4 6 6 11 7 11 7 9 9 11 11 1 6 7 9 7 9 7 9 7 9 7 9 7 9 1 4 1 6 7 9 1 4
output:
5 15 4 12 4 3 4 3 4 3 4 3 4 3 4 3 5 10 4 12 4 3 5 10
result:
ok 24 numbers
Test #4:
score: 5
Accepted
time: 1ms
memory: 8476kb
input:
1 12 1 9 1 8 1 7 1 6 1 5 1 4 2 4 9 12 10 12 12 1 8 1 9 1 9 1 8 1 8 1 4 1 7 1 7 1 6 1 4 1 4 1 7
output:
7 1 7 6 6 1 6 1 7 6 7 6 7 1 7 5 7 5 7 4 7 1 7 1 7 5
result:
ok 26 numbers
Test #5:
score: 5
Accepted
time: 0ms
memory: 8100kb
input:
1 13 1 10 1 9 1 5 1 3 3 5 5 9 6 9 6 8 10 13 11 13 13 6 8 1 3 1 9 6 8 6 8 6 8 1 9 6 8 6 8 6 8 6 8 6 8 6 8
output:
8 40 8 40 8 20 8 70 8 40 8 40 8 40 8 70 8 40 8 40 8 40 8 40 8 40 8 40
result:
ok 28 numbers
Test #6:
score: 5
Accepted
time: 2ms
memory: 8136kb
input:
1 14 1 10 1 7 1 6 1 5 1 3 3 5 7 10 8 10 10 14 10 13 10 12 14 10 12 1 5 10 12 10 12 10 12 1 6 1 10 10 12 10 12 1 3 1 6 1 10 10 12 10 12
output:
10 1890 10 1890 10 2835 10 1890 10 1890 10 1890 10 7560 9 1512 10 1890 10 1890 10 945 10 7560 9 1512 10 1890 10 1890
result:
ok 30 numbers
Test #7:
score: 5
Accepted
time: 1ms
memory: 7972kb
input:
1 100 1 98 1 96 1 95 1 94 1 91 1 89 1 79 1 78 1 77 1 76 1 75 1 74 1 73 1 70 1 68 1 67 1 64 1 60 1 58 1 57 1 56 1 55 1 54 1 53 1 51 1 49 1 45 1 44 1 42 1 38 1 32 1 30 1 29 1 28 1 27 1 26 1 22 1 21 1 19 1 18 1 16 1 15 1 13 1 11 1 10 1 6 1 5 1 4 1 3 6 10 6 9 7 9 11 13 13 15 16 18 19 21 22 26 23 26 24 2...
output:
96 671291031 96 332953896 96 342582055 96 249715422 96 346826975 96 895054708 96 671291031 96 936673945 96 671291031 96 671291031 96 544638907 96 671291031 96 398074371 96 887220962 96 205973725 96 895054708 96 686225340 96 835645519 96 586258144 96 223763677 96 223763677 96 917822763 96 466378536 9...
result:
ok 202 numbers
Test #8:
score: 5
Accepted
time: 1ms
memory: 8020kb
input:
1 100 1 98 1 97 1 96 1 94 1 93 1 91 1 89 1 88 1 87 1 86 1 84 1 82 1 80 1 72 1 71 1 70 1 68 1 64 1 62 1 61 1 58 1 56 1 53 1 49 1 46 1 45 1 44 1 43 1 42 1 41 1 40 1 34 1 28 1 27 1 26 1 25 1 24 1 23 1 21 1 19 1 17 1 16 1 13 1 11 1 10 1 8 1 7 1 5 1 4 1 3 5 7 8 10 11 13 13 16 14 16 17 19 19 21 21 23 28 3...
output:
96 906354055 96 73575642 96 906354055 96 906354055 96 906354055 96 953177031 96 538429361 96 107010664 96 906354055 96 906354055 96 859531079 96 953177031 96 953177031 96 658851221 96 906354055 96 555170114 96 953177031 96 625416199 96 204009415 96 953177031 96 906354055 96 906354055 96 302687 96 83...
result:
ok 202 numbers
Test #9:
score: 5
Accepted
time: 1ms
memory: 8092kb
input:
1 100 1 96 1 95 1 92 1 90 1 89 1 88 1 87 1 85 1 84 1 82 1 81 1 78 1 77 1 73 1 68 1 66 1 64 1 63 1 60 1 59 1 58 1 57 1 54 1 51 1 46 1 45 1 39 1 36 1 35 1 34 1 33 1 26 1 25 1 23 1 19 1 18 1 17 1 8 1 5 1 3 3 5 5 8 5 7 8 17 8 13 8 11 9 11 11 13 13 17 13 15 15 17 19 23 19 22 19 21 23 25 26 33 26 30 26 28...
output:
96 199865574
result:
ok 2 number(s): "96 199865574"
Test #10:
score: 5
Accepted
time: 0ms
memory: 9984kb
input:
1 100 1 98 1 96 1 95 1 90 1 88 1 87 1 86 1 85 1 84 1 81 1 76 1 74 1 73 1 72 1 71 1 69 1 68 1 63 1 61 1 60 1 58 1 57 1 56 1 55 1 52 1 50 1 49 1 44 1 43 1 39 1 38 1 36 1 34 1 32 1 30 1 28 1 25 1 24 1 23 1 19 1 17 1 16 1 15 1 14 1 13 1 11 1 10 1 4 1 3 4 10 4 6 6 10 7 10 8 10 11 13 17 19 19 23 20 23 21 ...
output:
96 982685481
result:
ok 2 number(s): "96 982685481"
Test #11:
score: 5
Accepted
time: 15ms
memory: 9024kb
input:
0 10000 1 9997 1 9996 1 9992 1 9991 1 9990 1 9989 1 9975 1 9974 1 9973 1 9968 1 9966 1 9964 1 9963 1 9957 1 9955 1 9954 1 9950 1 9947 1 9945 1 9944 1 9942 1 9939 1 9936 1 9932 1 9925 1 9923 1 9921 1 9919 1 9916 1 9915 1 9910 1 9908 1 9907 1 9906 1 9903 1 9902 1 9900 1 9896 1 9893 1 9892 1 9891 1 989...
output:
9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9994 9995 9995 9995 9995 9995 9995 9994 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 ...
result:
ok 100001 numbers
Test #12:
score: 5
Accepted
time: 16ms
memory: 10496kb
input:
0 10000 1 9995 1 9994 1 9993 1 9991 1 9990 1 9987 1 9986 1 9985 1 9983 1 9975 1 9974 1 9970 1 9969 1 9966 1 9965 1 9964 1 9963 1 9961 1 9957 1 9955 1 9954 1 9953 1 9952 1 9947 1 9946 1 9944 1 9941 1 9940 1 9939 1 9936 1 9934 1 9933 1 9932 1 9926 1 9925 1 9924 1 9923 1 9922 1 9917 1 9915 1 9914 1 991...
output:
9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9994 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 9995 ...
result:
ok 100001 numbers
Test #13:
score: 5
Accepted
time: 0ms
memory: 10484kb
input:
1 10000 1 9997 1 9996 1 9995 1 9992 1 9991 1 9990 1 9989 1 9987 1 9985 1 9984 1 9982 1 9981 1 9979 1 9978 1 9977 1 9975 1 9973 1 9972 1 9969 1 9966 1 9964 1 9963 1 9961 1 9958 1 9956 1 9955 1 9954 1 9953 1 9952 1 9947 1 9945 1 9943 1 9941 1 9940 1 9939 1 9936 1 9935 1 9931 1 9928 1 9925 1 9920 1 991...
output:
9996 618240676 9996 78827115 9995 802652618 9996 104350952 9996 927361014 9996 321033864 9996 618240676 9996 868527075 9996 618240676 9996 618240676 9996 618240676 9996 618240676 9996 618240676 9996 233865248 9996 618240676 9996 618240676 9996 539413561 9996 753351125 9996 539413561 9996 309120338 9...
result:
ok 2002 numbers
Test #14:
score: 5
Accepted
time: 3ms
memory: 8676kb
input:
1 10000 1 9998 1 9995 1 9993 1 9991 1 9989 1 9987 1 9985 1 9975 1 9973 1 9972 1 9971 1 9969 1 9967 1 9964 1 9962 1 9960 1 9958 1 9955 1 9954 1 9949 1 9948 1 9945 1 9943 1 9940 1 9939 1 9938 1 9935 1 9934 1 9932 1 9931 1 9930 1 9928 1 9927 1 9921 1 9920 1 9919 1 9918 1 9917 1 9916 1 9915 1 9914 1 991...
output:
9996 776488706 9996 838290966 9996 776488706 9995 776488706 9996 752405372 9996 776488706 9995 776488706 9996 776488706 9996 48661017 9996 776488706 9996 776488706 9996 388244353 9996 776488706 9996 651178911 9996 776488706 9996 125254238 9996 776488706 9996 211799436 9996 665893225 9996 962610175 9...
result:
ok 2002 numbers
Test #15:
score: 5
Accepted
time: 16ms
memory: 14648kb
input:
1 100000 1 99994 1 99992 1 99991 1 99990 1 99987 1 99986 1 99985 1 99982 1 99979 1 99978 1 99973 1 99971 1 99970 1 99969 1 99968 1 99966 1 99964 1 99959 1 99954 1 99953 1 99952 1 99950 1 99947 1 99946 1 99945 1 99944 1 99943 1 99942 1 99939 1 99938 1 99934 1 99933 1 99932 1 99931 1 99930 1 99927 1 9...
output:
99992 989014950
result:
ok 2 number(s): "99992 989014950"
Test #16:
score: 5
Accepted
time: 39ms
memory: 14828kb
input:
1 100000 1 99998 1 99996 1 99994 1 99993 1 99989 1 99988 1 99987 1 99985 1 99980 1 99978 1 99977 1 99970 1 99969 1 99966 1 99965 1 99963 1 99962 1 99961 1 99960 1 99959 1 99954 1 99953 1 99952 1 99950 1 99945 1 99944 1 99942 1 99940 1 99939 1 99937 1 99934 1 99933 1 99932 1 99931 1 99930 1 99929 1 9...
output:
99996 546482694 99996 546482694 99996 546482694 99996 546482694 99996 273241347 99996 546482694 99996 92965381 99996 546482694 99996 83877054 99996 273241347 99996 273241347 99996 552801627 99996 185930762 99996 546482694 99996 150734663 99996 441698118 99996 46013942 99996 546482694 99996 92965381 ...
result:
ok 200002 numbers
Test #17:
score: 5
Accepted
time: 31ms
memory: 14492kb
input:
1 100000 1 99998 1 99994 1 99992 1 99991 1 99988 1 99987 1 99985 1 99984 1 99982 1 99981 1 99979 1 99978 1 99976 1 99972 1 99970 1 99969 1 99963 1 99961 1 99959 1 99958 1 99957 1 99956 1 99955 1 99951 1 99950 1 99949 1 99947 1 99945 1 99944 1 99943 1 99941 1 99940 1 99938 1 99936 1 99932 1 99931 1 9...
output:
99996 592833083 99996 592833083 99996 513261872 99996 898208276 99996 412564599 99996 592833083 99996 592833083 99996 469937914 99996 78209004 99995 592833083 99996 592833083 99996 796416545 99996 718584671 99996 796416545 99996 318566618 99996 88596616 99996 659559772 99996 318566618 99996 59283308...
result:
ok 200002 numbers
Test #18:
score: 5
Accepted
time: 30ms
memory: 14888kb
input:
1 100000 1 99995 1 99993 1 99991 1 99990 1 99989 1 99987 1 99985 1 99984 1 99983 1 99982 1 99981 1 99980 1 99976 1 99975 1 99974 1 99970 1 99969 1 99967 1 99965 1 99964 1 99962 1 99960 1 99958 1 99957 1 99956 1 99955 1 99953 1 99949 1 99947 1 99946 1 99945 1 99943 1 99939 1 99938 1 99937 1 99933 1 9...
output:
99994 745361137 99994 745361137 99994 872680572 99994 490722267 99994 84675932 99994 745361137 99994 470979652 99994 181701416 99994 745361137 99994 745361137 99994 745361137 99994 706671509 99994 577810856 99993 881270336 99994 511935884 99994 745361137 99994 797334315 99994 36626873 99994 58178704...
result:
ok 200002 numbers
Test #19:
score: 5
Accepted
time: 23ms
memory: 14424kb
input:
1 100000 1 99996 1 99995 1 99994 1 99990 1 99988 1 99987 1 99984 1 99983 1 99982 1 99980 1 99979 1 99978 1 99974 1 99971 1 99970 1 99965 1 99961 1 99956 1 99955 1 99954 1 99953 1 99950 1 99948 1 99946 1 99944 1 99942 1 99941 1 99937 1 99929 1 99928 1 99924 1 99923 1 99920 1 99918 1 99916 1 99914 1 9...
output:
99995 694231833 99995 694231833 99995 694231833 99995 694231833 99995 82695485 99995 595296260 99995 949454647 99995 107072901 99995 787752201 99995 987245967 99995 694231833 99995 388463659 99995 694231833 99995 694231833 99995 616226252 99995 694231833 99995 76899199 99995 288287780 99995 69423183...
result:
ok 200002 numbers
Test #20:
score: 5
Accepted
time: 33ms
memory: 14828kb
input:
1 100000 1 99997 1 99995 1 99991 1 99987 1 99985 1 99980 1 99979 1 99978 1 99975 1 99974 1 99971 1 99970 1 99969 1 99968 1 99967 1 99965 1 99963 1 99962 1 99960 1 99956 1 99953 1 99952 1 99950 1 99945 1 99944 1 99942 1 99940 1 99939 1 99937 1 99936 1 99933 1 99928 1 99923 1 99921 1 99918 1 99915 1 9...
output:
99996 582102809 99996 582102809 99996 862280762 99996 370338886 99996 582102809 99996 186577105 99996 582102809 99996 186577105 99996 211645172 99996 582102809 99996 582102809 99996 390548303 99996 582102809 99996 845338016 99996 582102809 99996 896624983 99996 164205611 99996 514211117 99996 420622...
result:
ok 200002 numbers