QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472978 | #8049. Equal Sums | BalintR | AC ✓ | 2552ms | 9208kb | C++20 | 4.9kb | 2024-07-11 20:43:55 | 2024-07-11 20:43:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target "avx2"
#pragma GCC optimize "Ofast"
#include <immintrin.h>
typedef __m256i m256;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef complex<double> cpx;
template <typename T> using minPq = priority_queue<T, vector<T>, greater<T>>;
#define ms(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define fs first
#define sn second
#define ALL(v) begin(v), end(v)
#define SZ(v) ((int) (v).size())
#define lbv(v, x) (lower_bound(ALL(v), x) - (v).begin())
#define ubv(v, x) (upper_bound(ALL(v), x) - (v).begin())
template <typename T> inline void UNIQUE(vector<T> &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
#define FR(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) {cerr << #x << ' ' << x << endl;}
#define dbgArr(arr, n) {cerr << #arr; FR(_i, n) cerr << ' ' << (arr)[_i]; cerr << endl;}
template <typename T, typename U>
ostream& operator<<(ostream &os, pair<T, U> p){return os << "(" << p.fs << ", " << p.sn << ")";}
const int MOD = 998244353;
const int MOD_NINV = 998244351; // mod R
const int R_INV = 232013824; // mod M
const int ONE = (1ULL << 32) % MOD;
uint red(const uint &x){return min(x, x-MOD);}
uint redNeg(const uint &x){return min(x, x+MOD);}
uint redc(const ull &x){return red((x + (ull)(uint) ((ull)(uint) x*MOD_NINV) * MOD) >> 32);}
uint toMont(const uint &x){return ((ull) x << 32) % MOD;}
uint fromMont(const uint &x){return (ull) x * R_INV % MOD;}
#define vload(ptr) _mm256_loadu_si256((m256*) (ptr))
#define vstore(ptr, v) _mm256_storeu_si256((m256*) (ptr), v)
#define vrshift32(v) _mm256_bsrli_epi128(v, 4)
uint mulSum(int *arr, int *brr, int sz){
m256 res = _mm256_setzero_si256();
m256 mod_ninv = _mm256_set1_epi32(MOD_NINV);
m256 mod = _mm256_set1_epi32(MOD);
for(int i = 0; i < sz; i += 8){
m256 a = vload(arr+i);
m256 b = vload(brr+i);
m256 v1 = _mm256_mul_epu32(a, b);
m256 v2 = _mm256_mul_epu32(vrshift32(a), vrshift32(b));
m256 p1 = _mm256_mul_epu32(_mm256_mul_epu32(v1, mod_ninv), mod);
m256 p2 = _mm256_mul_epu32(_mm256_mul_epu32(v2, mod_ninv), mod);
v1 = vrshift32(_mm256_add_epi64(v1, p1));
v2 = _mm256_add_epi64(v2, p2);
res = _mm256_add_epi32(res, _mm256_blend_epi32(v1, v2, 0b10101010));
res = _mm256_min_epu32(res, _mm256_sub_epi32(res, mod));
res = _mm256_min_epu32(res, _mm256_sub_epi32(res, mod));
}
int tmp[8];
vstore(tmp, res);
ull ans = 0;
FR(i, 8) ans += tmp[i];
return ans % MOD;
}
const int BSZ = 28;
const int MN = 505;
int n, m;
int xlrr[MN], xdrr[MN], xlPref[MN], xdPref[MN];
int ylrr[MN], ydrr[MN], ylPref[MN], ydPref[MN];
int ans[MN][MN];
int xBigArr[MN*MN], xSmallArr[BSZ][MN*BSZ], yArr[MN*MN*2];
void conv(int *arr, int *brr, int d, int sz){
while((sz-d) & 7) sz++;
brr[0] = arr[0];
FR(i, sz) brr[i+1] = red(brr[i] + arr[i+1]);
m256 mod = _mm256_set1_epi32(MOD);
for(int i = sz-7; i > d; i -= 8){
m256 v = _mm256_sub_epi32(vload(brr+i), vload(brr+i-d-1));
v = _mm256_min_epu32(v, _mm256_add_epi32(v, mod));
vstore(brr+i, v);
}
}
void procBlk(int bl, int br){
FR(i, xdrr[bl]+1) xSmallArr[0][i] = ONE;
FOR(i, bl+1, br) conv(xSmallArr[i-1-bl], xSmallArr[i-bl], xdrr[i], xdPref[i+1]-xdPref[bl]);
int ysz = xdPref[bl];
FR(i, ysz+1) yArr[i] = xBigArr[ysz-i];
FR(bp, m){
conv(yArr, yArr, ydrr[bp], ysz += ydrr[bp]);
FOR(ap, bl, br){
int dif = xlPref[ap+1] - ylPref[bp+1] + xdPref[bl];
int l = max(0, -dif);
int r = min(ysz-dif, xdPref[ap+1]-xdPref[bl]) + 1;
ans[ap][bp] = mulSum(xSmallArr[ap-bl] + l, yArr + dif + l, r-l);
}
}
FR(i, ysz+1) yArr[i] = 0;
FOR(i, bl, br) FR(j, xdPref[i+1]-xdPref[bl]+1) xSmallArr[i-bl][j] = 0;
FOR(i, bl, br) conv(xBigArr, xBigArr, xdrr[i], xdPref[i+1]);
}
int main(){
cin.sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
FR(i, n){
int l, r;
cin >> l >> r;
xlrr[i] = l;
xdrr[i] = r-l;
xlPref[i+1] = xlPref[i] + xlrr[i];
xdPref[i+1] = xdPref[i] + xdrr[i];
}
FR(i, m){
int l, r;
cin >> l >> r;
ylrr[i] = l;
ydrr[i] = r-l;
ylPref[i+1] = ylPref[i] + ylrr[i];
ydPref[i+1] = ydPref[i] + ydrr[i];
}
xBigArr[0] = ONE;
for(int bl = 0; bl < n; bl += BSZ) procBlk(bl, min(n, bl+BSZ));
FR(i, n) FR(j, m) cout << fromMont(ans[i][j]) << " \n"[j == m-1];
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7748kb
input:
2 3 1 2 2 3 1 4 2 2 1 3
output:
2 0 0 3 4 4
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 2333ms
memory: 9080kb
input:
500 500 19 458 1 480 7 485 50 461 12 476 15 461 48 466 40 453 46 467 9 458 27 478 26 472 46 459 29 490 6 500 17 487 48 484 28 472 28 459 25 480 4 491 29 481 36 460 2 491 44 499 22 473 20 458 4 483 27 471 2 496 11 461 43 450 2 478 37 466 15 459 42 482 7 451 19 455 2 453 47 475 48 450 1 474 46 471 9 4...
output:
411 79401 9145270 673005095 180581065 984223118 586589234 293043270 404363796 865361724 665487988 118838806 926189944 226338288 521479857 808644951 786041288 340769021 177100 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 250000 numbers
Test #3:
score: 0
Accepted
time: 2322ms
memory: 9188kb
input:
500 500 36 457 29 497 27 469 21 497 12 498 35 496 40 478 47 497 45 451 34 488 5 500 22 453 6 462 17 491 3 482 12 468 37 461 27 476 45 470 37 491 49 498 45 485 29 455 8 478 25 493 48 491 2 496 40 493 10 485 22 455 18 475 42 450 8 464 39 498 28 497 18 455 13 492 44 471 39 478 40 481 37 459 37 486 38 4...
output:
410 67896 5410240 335246275 482170226 913746165 370327287 785404079 322053982 763512109 721728384 612084387 267089167 247309721 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 250000 numbers
Test #4:
score: 0
Accepted
time: 2323ms
memory: 9100kb
input:
500 500 14 454 10 476 22 452 18 488 4 463 12 495 31 472 19 464 20 476 10 467 44 485 6 496 31 474 39 461 45 483 1 496 25 471 47 462 23 463 42 494 2 481 5 465 41 468 4 496 49 498 24 472 18 500 7 497 2 493 15 491 10 463 31 466 7 469 50 483 46 478 19 458 2 481 20 455 22 485 20 455 45 486 16 469 21 495 5...
output:
441 96580 10039316 711563490 841935541 132520335 384371932 889484040 482637692 883143772 885148661 571513373 992796968 47082194 1307504 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 250000 numbers
Test #5:
score: 0
Accepted
time: 2324ms
memory: 9168kb
input:
500 500 4 480 6 477 36 454 25 450 38 458 50 464 47 458 1 479 46 485 26 494 10 478 2 480 23 463 35 453 7 454 33 479 44 496 17 471 27 487 36 473 43 497 32 476 22 490 25 496 50 479 4 456 49 456 26 497 2 450 46 496 27 455 32 459 50 495 22 491 15 484 14 488 39 484 1 463 13 483 38 499 35 468 45 453 32 468...
output:
471 108433 16539764 292114332 355294571 926046361 659177551 39453824 529783563 221351807 826151817 498533391 891430723 97219089 48882128 5311735 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 250000 numbers
Test #6:
score: 0
Accepted
time: 2337ms
memory: 9016kb
input:
500 500 43 451 14 483 4 497 14 485 6 485 5 475 10 490 22 467 42 492 21 500 2 464 16 494 14 460 45 498 6 487 39 479 40 455 42 452 24 465 47 493 47 489 33 450 38 453 26 492 14 473 15 464 24 495 38 459 24 486 20 484 50 490 31 454 21 470 17 456 1 494 46 488 19 470 50 470 4 460 25 487 20 463 4 451 50 493...
output:
409 89162 8789000 491134490 623734175 365970533 223879607 360062656 147167272 222184069 514225818 592269397 267978286 652587298 178132946 5311735 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 250000 numbers
Test #7:
score: 0
Accepted
time: 2326ms
memory: 8852kb
input:
500 500 7 474 40 477 4 450 2 467 24 493 23 500 37 476 8 462 48 454 14 500 24 471 30 458 47 472 12 482 33 480 4 457 43 496 14 458 3 453 2 488 32 483 27 476 1 478 38 477 39 482 22 476 30 466 20 452 48 491 16 484 32 450 5 471 19 466 15 494 22 497 7 457 28 462 35 478 5 483 12 496 14 495 10 461 33 471 38...
output:
445 95266 12085216 891881376 822602426 628274758 777305802 720102318 584565217 344805696 719285527 962838807 38728957 237533998 133972150 285609131 565722720 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 250000 numbers
Test #8:
score: 0
Accepted
time: 2329ms
memory: 9160kb
input:
500 500 40 469 34 468 14 460 23 491 50 487 4 478 27 487 29 485 7 482 40 488 4 453 30 453 10 464 7 477 50 455 13 473 29 467 41 457 20 485 29 457 45 461 6 483 37 499 30 451 24 491 30 482 9 467 18 492 23 463 25 490 3 461 42 466 12 451 14 454 6 487 33 500 33 492 5 488 49 452 42 463 34 477 25 465 46 493 ...
output:
425 79003 9585345 673005095 166390422 312570528 382836489 657074927 891491975 222184069 637806782 379313566 471700636 436538635 376444469 790552202 699660129 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 250000 numbers
Test #9:
score: 0
Accepted
time: 2319ms
memory: 9064kb
input:
500 500 29 460 24 466 22 489 41 452 37 476 45 496 10 481 28 497 16 462 13 500 7 497 38 477 12 470 38 455 1 464 1 461 42 482 41 479 35 494 34 496 20 486 4 484 37 484 42 483 40 464 3 494 2 469 23 496 42 490 46 490 1 499 43 466 23 467 13 450 29 461 9 450 13 486 44 495 24 475 35 481 44 495 20 496 46 456...
output:
432 81003 9511040 658029065 210103247 157666582 911617106 139298029 394317956 942022131 132310594 949626827 397291702 827047093 542880657 13037895 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 250000 numbers
Test #10:
score: 0
Accepted
time: 2312ms
memory: 9104kb
input:
500 500 37 486 47 452 43 485 12 489 33 457 41 477 48 451 46 471 23 491 3 496 25 472 30 493 38 473 24 478 17 477 10 485 4 455 45 473 39 494 11 490 45 459 38 452 4 500 43 461 6 484 24 464 38 452 45 472 47 497 10 493 46 494 18 482 45 500 26 450 1 483 35 458 50 497 40 489 36 456 2 498 9 487 20 479 41 47...
output:
427 98226 12975676 196463462 258622537 453526973 901311823 584108635 114036479 448310004 182637702 246235809 818487751 385016335 315415866 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 250000 numbers
Test #11:
score: 0
Accepted
time: 2319ms
memory: 8944kb
input:
500 500 6 488 11 482 18 465 15 482 24 500 45 462 12 470 44 462 37 468 3 475 10 456 47 452 16 467 48 470 10 463 9 451 26 468 43 453 50 498 37 488 2 474 39 480 10 456 8 485 39 453 24 497 6 481 37 457 36 493 34 488 23 472 50 457 27 475 18 453 36 451 15 468 13 452 18 471 26 489 19 474 29 500 39 472 48 4...
output:
437 87153 10586800 744617 776616085 219865658 11667831 253804241 276378294 195939520 774230261 389813264 982059869 291850838 281913196 120767384 883852143 635936961 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 250000 numbers
Test #12:
score: 0
Accepted
time: 2552ms
memory: 9204kb
input:
499 500 5 497 6 494 4 491 5 492 7 497 2 495 8 494 3 491 9 495 3 496 9 497 8 490 6 500 4 491 6 490 9 496 3 490 2 495 7 492 4 494 9 494 4 494 4 496 7 496 9 491 1 490 10 498 1 496 9 500 6 500 10 498 2 492 8 490 10 498 6 493 1 499 8 497 10 498 9 494 5 492 6 497 9 497 6 492 9 492 10 496 9 493 1 499 4 496...
output:
492 119316 19250136 243105014 640259429 848017016 967479743 49685914 88145869 832148397 30876722 1398353 430300916 946263737 959886182 814780656 842820257 851356460 725192293 653152937 171714960 38586424 354934143 179039285 691583334 292858116 924240829 942890381 17716633 70051478 600806382 85421878...
result:
ok 249500 numbers
Test #13:
score: 0
Accepted
time: 2538ms
memory: 9160kb
input:
495 499 3 493 4 499 6 493 7 498 4 493 8 496 8 496 1 494 7 493 10 495 1 491 10 495 7 491 7 499 8 493 6 490 1 496 10 490 2 494 3 493 6 493 5 490 7 496 5 493 9 492 2 496 5 496 5 500 1 493 8 499 4 497 6 498 4 499 8 493 3 494 2 490 6 496 1 497 5 497 8 499 4 498 8 495 1 497 1 490 9 497 6 499 2 490 1 493 6...
output:
486 117855 18896570 243105014 498103446 288895653 869907239 731058819 348958708 846266690 601172751 881333656 414211605 200965223 685846017 658884484 832411088 155603293 345398839 916499158 768292862 810285565 553123425 768278573 468641963 649236052 587548408 684588651 112307655 969837483 707495282 ...
result:
ok 247005 numbers
Test #14:
score: 0
Accepted
time: 2008ms
memory: 9208kb
input:
500 496 7 403 40 458 40 409 86 414 54 464 1 436 96 484 79 431 90 497 8 460 89 475 97 483 96 437 76 490 64 422 79 496 49 442 25 451 40 496 88 459 15 450 85 414 72 418 83 407 6 445 44 473 65 497 90 438 94 474 68 407 1 439 42 402 54 481 28 412 97 439 72 450 78 461 20 407 58 477 33 470 68 445 54 403 48 ...
output:
370 60726 5616324 261630670 367803058 938693299 232384977 763859516 576315935 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 248000 numbers
Test #15:
score: 0
Accepted
time: 1222ms
memory: 8784kb
input:
499 497 118 399 25 370 50 271 193 468 47 287 67 488 109 387 55 372 81 442 16 429 199 429 19 421 137 273 107 495 245 451 217 370 42 347 85 288 236 310 226 437 205 311 15 460 128 440 36 444 179 481 203 389 203 355 212 407 221 416 210 343 89 296 124 405 165 282 131 334 113 374 20 327 175 314 185 433 39...
output:
87 1953 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 248003 numbers
Test #16:
score: 0
Accepted
time: 747ms
memory: 9092kb
input:
494 492 207 238 118 361 121 225 458 481 14 404 50 188 20 217 147 336 51 373 228 395 382 402 158 396 58 68 173 467 371 468 86 104 302 372 261 410 128 312 52 181 152 266 22 497 40 115 207 319 18 45 256 405 28 339 72 434 153 155 117 243 186 300 69 174 258 485 200 425 306 308 22 154 17 237 470 472 341 4...
output:
32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 243048 numbers
Extra Test:
score: 0
Extra Test Passed