QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#472695 | #8049. Equal Sums | BalintR | TL | 1ms | 7792kb | C++20 | 3.2kb | 2024-07-11 18:31:19 | 2024-07-11 18:31:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize "Ofast"
#pragma GCC target "avx2"
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 = 28;
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]);
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){
ll v = 0;
int dif = xlPref[ap+1] - ylPref[bp+1] + xdPref[bl];
FOR(i, max(0, -dif), min(ysz-dif, xdPref[ap+1]-xdPref[bl]) + 1){
v += (ull) xSmallArr[ap-bl][i] * yArr[i+dif] % 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-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] = 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];
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7792kb
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
Time Limit Exceeded
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...