QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#178539#1227. 斗主地hos_lyric100 ✓110ms7172kbC++146.8kb2023-09-14 03:12:002023-09-14 03:12:00

Judging History

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

  • [2023-09-14 03:12:00]
  • 评测
  • 测评结果:100
  • 用时:110ms
  • 内存:7172kb
  • [2023-09-14 03:12:00]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;


void experiment1() {
  for (int n = 1; n <= 8; ++n) {
    vector<Int> all(n + 1, 0);
    vector<vector<Int>> f(n + 1, vector<Int>(n, 0));
    for (int p = 0; p < 1 << n; ++p) {
      const int a = __builtin_popcount(p);
      ++all[a];
      int x = 0, y = a;
      for (int i = 0; i < n; ++i) {
        f[a][i] += ((p >> i & 1) ? x++ : y++);
      }
    }
    for (int a = 0; a <= n; ++a) {
      cerr << n << " " << a << ": " << f[a] << endl;
      assert(all[a] * (n - a) % n == 0);
      assert(f[a][0] == (all[a] * (n - a) / n) * a);
      for (int i = 0; i < n - 1; ++i) {
        assert(f[a][1] - f[a][0] == f[a][i + 1] - f[a][i]);
      }
    }
  }
}
void experiment2() {
  for (int n = 1; n <= 8; ++n) {
    vector<Int> sq(n);
    for (int x = 0; x < n; ++x) {
      sq[x] = x * x;
    }
    vector<Int> all(n + 1, 0);
    vector<vector<Int>> f(n + 1, vector<Int>(n, 0));
    for (int p = 0; p < 1 << n; ++p) {
      const int a = __builtin_popcount(p);
      ++all[a];
      int x = 0, y = a;
      for (int i = 0; i < n; ++i) {
        f[a][i] += ((p >> i & 1) ? sq[x++] : sq[y++]);
      }
    }
    for (int a = 0; a <= n; ++a) {
      vector<Int> ds(n - 1);
      for (int i = 0; i < n - 1; ++i) {
        ds[i] = f[a][i + 1] - f[a][i];
      }
      cerr << n << " " << a << ": " << f[a] << " " << ds << endl;
      assert(all[a] * (n - a) % n == 0);
      assert(f[a][0] == (all[a] * (n - a) / n) * (a * a));
      for (int i = 0; i < n - 2; ++i) {
        assert(ds[1] - ds[0] == ds[i + 1] - ds[i]);
      }
    }
  }
}

int N, M, T;
vector<int> A;
int Q;
vector<int> C;

int main() {
  // experiment1();
  // experiment2();
  
  for (; ~scanf("%d%d%d", &N, &M, &T); ) {
    A.resize(M);
    for (int m = 0; m < M; ++m) {
      scanf("%d", &A[m]);
    }
    scanf("%d", &Q);
    C.resize(Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d", &C[q]);
      --C[q];
    }
    
    Mint p, q, r;
    if (T == 1) {
      p = 0; q = 1; r = 1;
    } else if (T == 2) {
      p = 1; q = 2; r = 1;
    } else {
      assert(false);
    }
    auto f = [&](Mint x) -> Mint {
      return (p * x + q) * x + r;
    };
    
    const Mint inv0 = Mint(N).inv();
    const Mint inv1 = Mint(N - 1).inv();
    /*
      [ 1       1     ]^-1
      [ (N-1)^2 (N-1) ]
    */
    const Mint invDet = (Mint(N - 1) - Mint(N - 1) * Mint(N - 1)).inv();
    const Mint c11 = invDet * Mint(N - 1);
    const Mint c12 = invDet * -1;
    const Mint c21 = invDet * -Mint(N - 1) * Mint(N - 1);;
    const Mint c22 = invDet * 1;
    for (int m = 0; m < M; ++m) {
      const int a = A[m];
      const int b = N - a;
      Mint g0 = inv0 * (a * f(0) + b * f(a));
      Mint g1 = inv0 * (a * (inv1 * ((a-1) * f(1) + b * f(a))) + b * (inv1 * (a * f(0) + (b-1) * f(a+1))));
      Mint g2 = inv0 * (a * f(a-1) + b * f(N-1));
      r = g0;
      g1 -= r;
      g2 -= r;
      p = c11 * g1 + c12 * g2;
      q = c21 * g1 + c22 * g2;
    }
    
    for (int q = 0; q < Q; ++q) {
      const Mint ans = f(C[q]);
      printf("%u\n", ans.x);
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 45ms
memory: 5232kb

input:

10 1 1
6
500000
7
3
3
9
6
1
5
8
10
7
5
9
5
10
6
3
5
7
6
7
7
7
4
9
7
5
7
8
6
10
1
10
7
8
5
5
1
4
3
6
2
8
6
8
7
5
4
7
4
4
10
9
6
9
10
10
2
8
2
3
4
5
1
6
8
3
10
5
8
1
6
5
5
6
4
4
7
4
6
9
3
2
10
6
10
1
4
7
7
3
1
3
3
4
8
7
4
3
8
5
9
10
2
2
6
5
9
5
6
6
5
5
2
9
9
1
1
3
2
6
8
3
1
5
2
4
4
2
6
4
10
2
8
4
9
10...

output:

598946618
332748122
332748122
732045866
532396994
199648874
465847370
665496242
798595490
598946618
465847370
732045866
465847370
798595490
532396994
332748122
465847370
598946618
532396994
598946618
598946618
598946618
399297746
732045866
598946618
465847370
598946618
665496242
532396994
798595490
...

result:

ok 500000 lines

Test #2:

score: 10
Accepted
time: 46ms
memory: 5400kb

input:

80 80 1
68 27 44 69 72 69 67 26 2 42 28 49 31 22 47 79 9 76 41 60 51 37 32 8 70 63 47 59 63 26 54 22 0 33 53 52 30 1 15 23 73 16 56 19 30 40 25 23 26 28 44 41 15 10 41 33 2 21 11 50 30 21 68 72 79 57 75 67 35 37 20 62 54 50 70 43 10 15 42 67
500000
29
32
14
60
13
62
69
58
76
20
48
13
28
7
71
80
65
1...

output:

430027396
14032848
513511430
789890714
984924397
845309133
540151423
734472295
234993713
679766687
457380200
984924397
901440363
818669140
595569842
345830551
429314585
984924397
818669140
624348268
69451267
540864234
789890714
124156875
345830551
650988261
152935301
928793167
318477747
374608977
65...

result:

ok 500000 lines

Test #3:

score: 10
Accepted
time: 50ms
memory: 5268kb

input:

80 80 2
75 20 1 41 78 35 46 17 47 13 44 27 49 17 80 17 80 36 35 50 24 71 72 34 35 79 24 38 32 66 50 10 5 21 17 20 29 0 47 48 58 64 7 72 31 73 30 47 77 47 56 26 7 2 2 76 75 37 23 78 70 48 14 2 64 27 2 57 80 58 8 53 65 63 28 17 24 76 36 60
500000
3
72
77
70
18
76
52
75
57
4
13
14
28
34
44
18
45
68
33
...

output:

112551916
649151954
729604264
985309728
749349409
608274174
505119625
539563898
314812300
385612996
219832581
20847448
763647350
103595257
551108614
749349409
985093362
533702405
248428463
50460573
750062202
750062202
606277784
750062202
543726900
252497435
722533551
292574338
775662289
219832581
47...

result:

ok 500000 lines

Test #4:

score: 10
Accepted
time: 88ms
memory: 7084kb

input:

100 500000 2
52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52...

output:

895875950
451035659
449208912
424833975
874809297
634797231
491345655
231829688
344616971
675756186
530510176
623474085
175127304
317311001
874809297
71513808
901278115
629195723
117886078
907309213
912302951
209096742
456265355
831117515
779772670
639835297
500037215
288001241
907309213
125524554
8...

result:

ok 500000 lines

Test #5:

score: 10
Accepted
time: 106ms
memory: 7124kb

input:

10000000 500000 1
5327684 4923455 4830294 9422889 216505 4038701 6236091 5634812 6919219 545534 8228559 169097 8203049 106402 4335782 3794853 9759823 9240793 8508896 5425261 8530551 7754052 6522487 105131 3774882 9668981 3254388 646284 2135256 6347326 1949671 1836992 7092039 5012034 585861 9153685 4...

output:

879350663
757138263
993250658
985515831
40232114
824569250
703478262
742485068
593832760
325960330
657467736
895494303
661352278
176854565
422413186
971268773
339043593
644833662
892329231
517731137
260839934
755232383
789354177
633649745
362025362
296627731
520824931
930493364
543158005
694653008
6...

result:

ok 500000 lines

Test #6:

score: 10
Accepted
time: 107ms
memory: 7172kb

input:

10000000 500000 1
8375617 8839488 3109677 2985714 205177 7734839 3116449 8084206 2679892 3794701 5586731 8041619 1883689 6390985 1111535 7718858 668622 6637233 7829083 7450630 5616137 9014113 3858581 4298131 3087195 6476619 430162 8142144 300960 2853430 9592264 3990728 650852 1991440 4744816 4118649...

output:

162176357
986449738
710376684
449898920
188041664
684951127
278446884
541857455
122945293
526934503
289000523
86405485
474159829
639238349
937534173
545535783
456786093
809103607
362953004
55848299
316626379
890815653
542151113
65703444
68658951
893767381
273030006
532991834
368194533
856547977
1828...

result:

ok 500000 lines

Test #7:

score: 10
Accepted
time: 95ms
memory: 7092kb

input:

10000000 500000 1
8761253 8480991 3342702 9906508 9408367 7645976 1561991 9243035 5412760 5970120 9771280 7569477 105243 6287684 2732112 6020771 1923917 4644582 8833472 1617253 4351738 8675236 5430218 9681503 5215488 7075945 9761691 3782744 8558408 8058905 1064756 9533506 5371805 6099121 5608607 601...

output:

2310879
621249658
559038579
535720860
925655094
225213152
484548739
615963492
997092750
886429758
455161382
27345302
257878886
626035051
677522683
865073626
127368400
201279205
728978393
246064150
249407241
232377303
371833200
895923172
284295189
344622567
829755978
896139268
231540262
856940316
658...

result:

ok 500000 lines

Test #8:

score: 10
Accepted
time: 110ms
memory: 7124kb

input:

10000000 500000 2
3134002 9080054 4639258 3513762 939650 7834164 2834044 1089563 916684 4514117 499727 276333 4006916 3617322 9253590 991250 2179088 6624325 1817023 9480297 1021173 3889163 3099204 445344 6269173 7375828 9211807 2451712 2776359 2094072 313786 3433743 644127 2536719 2241731 8383348 53...

output:

118630024
141318714
674142046
976245500
514982398
719903847
86682263
599768963
488270655
371983822
378590571
241802034
686621423
806670555
328893910
342474295
402993931
214624147
278986037
920760287
626105629
330637732
18512839
470766459
607926381
177007985
772027698
30293805
625066212
67789154
1456...

result:

ok 500000 lines

Test #9:

score: 10
Accepted
time: 106ms
memory: 7084kb

input:

10000000 500000 2
5050959 7224888 7453279 297518 1676582 9119172 8181423 8507016 8057622 8159044 3779318 624386 432647 7111216 6953024 9222311 5605981 2565948 8753448 5268756 7496314 6409234 1258480 4012735 7627626 8303571 5006758 8269940 3249380 7528315 9317541 6075424 6500014 7739772 993136 162565...

output:

567479693
550270446
822223033
939394827
503207497
266805645
351357571
852231077
752203357
644468344
707871728
426293210
176335188
346023880
893451401
665249249
23214582
318391768
758627056
882679643
99141681
202954201
814963036
755161680
752284041
51622740
663908717
607966033
748214043
689897776
924...

result:

ok 500000 lines

Test #10:

score: 10
Accepted
time: 106ms
memory: 7076kb

input:

10000000 500000 2
7360031 3740481 4242109 447964 4478753 7178594 9318799 3061252 6052405 15405 6980778 9361394 3408025 4796117 8813043 3219316 5265201 2515444 5949379 2204891 2908925 6539115 5834292 3627295 33983 9594775 775986 9896158 3331315 7783090 7644352 4716278 3105694 5351459 7457182 5806903 ...

output:

295840578
803693843
973141286
799916675
598106838
862673563
468009784
841335298
725827655
788978751
950661053
571500200
578808068
740275150
434333585
442873162
971743576
402622261
966956385
954539796
637515050
886348376
922058574
731413527
906645832
724032029
91932440
984887463
636144933
28411549
86...

result:

ok 500000 lines

Extra Test:

score: 0
Extra Test Passed