QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472602 | #8049. Equal Sums | BalintR | RE | 0ms | 5660kb | C++20 | 3.3kb | 2024-07-11 17:28:43 | 2024-07-11 17:28:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
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 BSZ = 21;
const int BC = 24;
const int MN = 505;
const int MOD = 998244353;
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];
uint red(const uint &x){return min(x, x-MOD);}
uint redNeg(const uint &x){return min(x, x+MOD);}
void conv(int *arr, int *brr, int d, int sz){
brr[0] = arr[0];
FR(i, sz) brr[i+1] = red(brr[i] + arr[i+1]);
FORR(i, sz, d+1) brr[i] = redNeg(brr[i] - brr[i-d-1]);
}
void procBlk(int bl, int br){
FR(i, xdrr[bl]+1) xSmallArr[0][i] = 1;
FOR(i, bl+1, br) conv(xSmallArr[i-1-bl], xSmallArr[i-bl], xdrr[i], xdPref[i+1]-xdPref[bl]);
//FOR(i, bl, br) dbgArr(xSmallArr[i-bl], xdPref[i+1]-xdPref[bl]+1);
int ysz = xdPref[bl];
FR(i, ysz+1) yArr[i] = xBigArr[ysz-i];
FR(bp, m){
conv(yArr, yArr, ydrr[bp], ysz += ydrr[bp]);
//dbgArr(yArr, ysz+1);
FOR(ap, bl, br){
ll v = 0;
FR(i, xdPref[ap+1]-xdPref[bl]+1){
int j = i+xlPref[ap+1] - ylPref[bp+1] + xdPref[bl];
if(j < 0 || j > ysz) continue;
v += (ll) xSmallArr[ap-bl][i] * yArr[j] % MOD;
}
ans[ap][bp] = v % MOD;
}
}
FR(i, ysz+1) yArr[i] = 0;
FOR(i, bl, br) FR(j, xdPref[i+1]-xdPref[bl]+1) xSmallArr[i][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] = 1;
for(int bl = 0; bl < n; bl += BSZ) procBlk(bl, min(n, bl+BSZ));
FR(i, n) FR(j, m) cout << ans[i][j] << " \n"[j == m-1];
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5660kb
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: -100
Runtime Error
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...