QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67524#2678. 多边形alpha1022100 ✓123ms26048kbC++232.5kb2022-12-10 16:57:262022-12-10 16:57:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-10 16:57:26]
  • 评测
  • 测评结果:100
  • 用时:123ms
  • 内存:26048kb
  • [2022-12-10 16:57:26]
  • 提交

answer

#include <cstdio>
#include <vector>
#include <algorithm>
#include <tr1/unordered_map>
using namespace std;
const int N = 1e5;
const int mod = 1e9 + 7;
inline int fpow(int a, int b) {
  int ret = 1;
  for (; b; b >>= 1)
    (b & 1) && (ret = (long long)ret * a % mod), a = (long long)a * a % mod;
  return ret;
}
int W, n, m;
int fac[N + 5], ifac[N + 5];
int cnt, sum = 1, ans1, ans2;
vector<int> e[N + 5];
inline int C(int n, int m) {
  return n < m ? 0 : (long long)fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
inline int Ci(int n, int m) {
  return n < m ? 0 : (long long)ifac[n] * fac[m] % mod * fac[n - m] % mod;
}
tr1::unordered_map< int, tr1::unordered_map<int, int>> id;
int fa[N + 5], ls[N + 5], rs[N + 5], sz[N + 5], rt;
void build(int &p, int l, int r) {
  static int tot = 0;
  if (r - l == 1)
    return ;
  id[l][r] = p = ++tot;
  int mid = *upper_bound(e[r].begin(), e[r].end(), l);
  build(ls[p], l, mid), build(rs[p], mid, r),
        ls[p] &&(fa[ls[p]] = p),
        rs[p] && (fa[rs[p]] = p),
        sz[p] = sz[ls[p]] + 1 + sz[rs[p]],
                sum = (long long)sum * C(sz[p] - 1, sz[ls[p]]) % mod;
}
int main() {
  scanf("%d%d", &W, &n), fac[0] = 1;
  for (register int i = 1; i <= n; ++i)
    fac[i] = (long long)fac[i - 1] * i % mod;
  ifac[n] = fpow(fac[n], mod - 2);
  for (register int i = n; i; --i)
    ifac[i - 1] = (long long)ifac[i] * i % mod;
  int u, v;
  for (register int i = 1; i <= n - 3; ++i)
    scanf("%d%d", &u, &v), e[u].push_back(v), e[v].push_back(u);
  for (register int i = 1; i <= n; ++i)
    e[i].push_back(i % n + 1), e[i % n + 1].push_back(i);
  for (register int i = 1; i <= n; ++i)
    sort(e[i].begin(), e[i].end());
  for (register vector<int>::iterator i = e[n].begin(), j = i + 1; j != e[n].end(); ++i, ++j)
    rt = 0, build(rt, *i, *j), sum = (long long)sum * C(cnt += sz[rt], sz[rt]) % mod;
  printf("%d%c", cnt, "\n "[W]), W &&printf("%d\n", sum);
  for (scanf("%d", &m); m; --m) {
    scanf("%d%d", &u, &v), ans1 = cnt, ans2 = sum;
    int p = id[u][v];
    if (fa[p])
      ans2 = (long long)ans2 * Ci(sz[p] - 1, sz[ls[p]]) % mod * Ci(sz[fa[p]] - 1, sz[p]) % mod,
      ans2 = (long long)ans2 * C(sz[rs[p]] + sz[rs[fa[p]]], sz[rs[p]]) % mod * C(sz[p] + sz[rs[fa[p]]],
             sz[ls[p]]) % mod;
    else
      --ans1,
      ans2 = (long long)ans2 * Ci(sz[p] - 1, sz[ls[p]]) % mod * Ci(cnt, sz[p]) % mod,
      ans2 = (long long)ans2 * C(cnt - sz[rs[p]] - 1, sz[ls[p]]) % mod * C(cnt - 1, sz[rs[p]]) % mod;
    printf("%d%c", ans1, "\n "[W]), W &&printf("%d\n", ans2);
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 0ms
memory: 5440kb

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

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: 2ms
memory: 5448kb

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

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: 2ms
memory: 5380kb

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: 3ms
memory: 5336kb

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: 5444kb

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: 2ms
memory: 5448kb

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: 3ms
memory: 5396kb

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: 3ms
memory: 5404kb

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: 46ms
memory: 7388kb

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: 39ms
memory: 7464kb

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: 9ms
memory: 7424kb

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: 5ms
memory: 7336kb

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: 49ms
memory: 26040kb

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: 87ms
memory: 26016kb

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: 123ms
memory: 25980kb

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: 104ms
memory: 26048kb

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: 109ms
memory: 25988kb

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: 108ms
memory: 26012kb

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