QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#639380 | #8049. Equal Sums | IllusionaryWhiteTraveler | TL | 0ms | 3852kb | C++23 | 10.7kb | 2024-10-13 19:14:35 | 2024-10-13 19:14:45 |
Judging History
answer
#pragma GCC optimize("Ofast,inline,unroll-loops")
#ifdef GTRAKIOI
#define _GLIBCXX_DEBUG //交题前记得注释掉不然容易T。
#endif
#include<bits/stdc++.h>
// #include<stdio.h>
#define File(s) freopen(#s".in","r",stdin),freopen(#s".out","w",stdout)
#ifdef GTRAKIOI
#include"C:/code/deb_20.cpp"
#define defrog(...) fprintf(stderr,__VA_ARGS__)
#define deb(x) (std::cerr<<#x<<"@"<<__LINE__<<"="<<(x)<<'\n')
#else
#define defrog(...) 1
#define deb(x) 1
#define debug(...) 1
#define debugArr(...) 1
#endif
#define defrogf(...) defrog(__VA_ARGS__)
#define Tp template<typename T>
#define Tl template<typename T
#define Tr >
#define IS(cond) ,std::enable_if_t<(cond), int> = 0
#if __cplusplus>=201703L
#define register
#endif
#ifdef _MSC_VER
#if __has_include(<__msvc_int128.hpp>)
#include <__msvc_int128.hpp> // https://stackoverflow.com/a/76440171
#define __int128 std::_Signed128
#define __int128_t std::_Signed128
#define __uint128_t std::_Unsigned128
#define __SIZEOF_INT128__ 16
#endif
#endif
using ll=long long;
using ull=unsigned long long;
#ifdef __SIZEOF_INT128__
using lll=__int128;
// using ulll=unsigned __int128;
#endif
using db=double;
using ld=long double;
#define INT_ALIAS(w) using i##w=std::int##w##_t;using u##w=std::uint##w##_t;
INT_ALIAS(8) INT_ALIAS(16) INT_ALIAS(32) INT_ALIAS(64)
#ifdef __SIZEOF_INT128__
using i128=__int128_t;
using u128=__uint128_t;
using i7=__int128_t;
using u7=__uint128_t;
template <class T>
using to_unsigned = typename std::conditional<
std::is_same<T, __int128_t>::value ||
std::is_same<T, __int128>::value,
std::common_type<__uint128_t>,
typename std::conditional<std::is_signed<T>::value,
std::make_unsigned<T>,
std::common_type<T>>::type>::type;
#else
template <class T>
using to_unsigned = std::make_unsigned<T>;
#endif
template <class T> using to_unsigned_t = typename to_unsigned<T>::type;
template<typename T>using vv=std::vector<T>;
template<typename T>using V=std::vector<T>;
using pii=std::pair<int,int>;
using vi=V<int>;
using vll=V<ll>;
using vpii=V<pii>;
using vvi=V<vi>;
template<typename T>using pq=std::priority_queue<T>;
template<typename T>using pqg=std::priority_queue<T,std::vector<T>,std::greater<>>;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define all(cont) std::begin(cont),std::end(cont)
char ibuf[1<<15],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=ibuf)+fread(ibuf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
struct FastIO{
Tl IS(!std::numeric_limits<T>::is_signed) Tr inline void oint(T x){
T y=1;
while(y<=x/10)y*=10;
do putchar(int(x/y)|48),x%=y,y/=10;while(y);
}
Tl IS(std::numeric_limits<T>::is_signed) Tr inline void oint(const T&x){
if(x<0){
putchar('-');
oint<to_unsigned_t<T>>(-x);
}else oint<to_unsigned_t<T>>(x);
}
Tl=int IS(std::numeric_limits<T>::is_integer) Tr inline T rint(){register char c,f=0;while((c=getchar())<48||c>57)f|=c=='-';to_unsigned_t<T> a=c&15;while((c=getchar())>=48&&c<=57)a=a*10+(c&15);return f?~a+1:a;}
// inline ll rll(){rg char c,f=0;while((c=getchar())<48||c>57)f|=c=='-';rg ull a=c&15;while((c=getchar())>=48&&c<=57)a=a*10+(c&15);return f?~a+1:a;}
// inline operator int(){return rint();}
// inline operator ll(){return rll();}
Tl IS(std::numeric_limits<T>::is_integer) Tr inline operator T(){return rint<T>();}
inline char rchar(){register char c;while(!isgraph(c=getchar()));return c;}
inline int rstr(char*s){register char c;while(!isgraph(c=getchar()));int cnt=-1;do s[++cnt]=c;while(isgraph(c=getchar()));s[++cnt]=0;return cnt;}
inline std::string rs(){register char c;while(!isgraph(c=getchar()));std::string s;do s+=c;while(isgraph(c=getchar()));return s;}
Tl IS(std::numeric_limits<T>::is_integer) Tr inline void print(const T&x){oint(x);}
inline void print(const char&x){putchar(x);}
inline void print(const char*const&x){for(int i=0;x[i];++i)putchar(x[i]);}
#if __cplusplus >= 202002L
Tp requires std::ranges::range<T> inline void print(const T&c){
bool first=true;
for(const auto&x:c){
if(!first)putchar(' ');
first=false;
print(x);
}
}
#endif
inline void print(const std::string&x){for(int i=0;x[i];++i)putchar(x[i]);}
// print with separators
// inline void prints(){putchar('\n');}
// inline void prints(const auto&x,const auto&...rst){print(x),putchar(' '),prints(rst...);}
inline void prints(const auto&...x){((print(x),putchar(' ')),...);putchar('\n');}
}g90;
inline void YON(const bool&x){puts(x?"YES":"NO");}
inline void Yon(const bool&x){puts(x?"Yes":"No");}
inline void yon(const bool&x){puts(x?"yes":"no");}
template<typename T=int>std::vector<T>rvec(std::size_t n,std::size_t start=0) {
std::vector<T>res(start+n);
for(std::size_t i=start;i<start+n;++i)res[i]=g90;
return res;
}
std::mt19937_64 rng(u32(std::chrono::high_resolution_clock::now().time_since_epoch().count()));
Tl IS(std::is_floating_point<T>::value) Tr inline T rnd(const T&a,const T&b){
return std::uniform_real_distribution<T>(a,b)(rng);
}
Tl IS(std::numeric_limits<T>::is_integer) Tr inline T rnd(const T&a,const T&b){
return std::uniform_int_distribution<T>(a,b)(rng);
}
namespace MY_STD{
Tp inline T abs(const T&a){return a<0?-a:a;}
}
#if __cplusplus >= 202002L
namespace all{
using namespace std::ranges;
using namespace std::views;
//ambiguous ones
using std::views::iota;
using std::views::empty;
using std::views::reverse;
inline constexpr auto&R=std::views::reverse;
}
#endif
struct DSU{//unweighted
using key_type=int;
std::vector<key_type>fa,size;
inline DSU(key_type n):fa(n),size(n,1){std::iota(fa.begin(),fa.end(),0);}
inline key_type& getFa(key_type x){
while(x^fa[x])x=fa[x]=fa[fa[x]];
return fa[x];
}
inline key_type& operator[](const key_type&x){return getFa(x);}
inline auto canMerge(const key_type&u,const key_type&v){return getFa(u)!=getFa(v);}
inline bool merge(key_type u,key_type v){
u=getFa(u),v=getFa(v);
return (u)!=(v)&&(size[u]<size[v]&&(std::swap(u,v),1),fa[v]=u,size[u]+=size[v],size[v]=0,true);
}
};
template<typename Compare=std::less<>>inline bool ckmax(auto& a,const auto& b,const Compare&comp={}){return comp(a,b)?(a=b,true):false;}
template<typename Compare=std::less<>>inline bool ckmin(auto& a,const auto& b,const Compare&comp={}){return comp(b,a)?(a=b,true):false;}
inline auto divf(const auto&a,const auto&b){//assume b>0
return a<0?(a+1)/b-1:a/b;
}
inline auto divc(const auto&a,const auto&b){//assume b>0
return a>0?(a-1)/b+1:a/b;
}
constexpr int N=1048576*4,M=998244353;//1000000007;
// using mint = atcoder::static_modint<M>;
inline int qpow(ll a,auto b){int res=1;for(;b;a=a*a%M,b>>=1)if(b&1)res=res*a%M;return res;}
// #define pow qpow
const int P = 998244353;
int add(int a, int b) { return (a += b) < P ? a : a - P; }
int sub(int a, int b) { return (a -= b) < 0 ? a + P : a; }
int mul(int a, int b) { return (uint64_t)(uint32_t)a * (uint32_t)b % P; }
int ceil2(int n) { return 2 << __builtin_ia32_bsrsi(n); }
int Pow(int a, int n) {
int r = 1;
for (; n; n >>= 1, a = mul(a, a))
if (n & 1) r = mul(r, a);
return r;
}
struct precalc {
int w[23], iw[23];
precalc() {
int e[22], ie[22], now = 15311432, inow = 469870224;
for (int i = 21; i >= 0; i--) {
e[i] = now, ie[i] = inow;
now = mul(now, now), inow = mul(inow, inow);
}
now = inow = 1;
for (int i = 0; i <= 21; i++) {
w[i] = mul(e[i], now), iw[i] = mul(ie[i], inow);
now = mul(now, ie[i]), inow = mul(inow, e[i]);
}
}
} pre;
void DIF(int a[], int n) {
for (int i = n >> 1, l = 1; i; i >>= 1, l <<= 1) {
int now = 1;
for (int j = 0; j < l; j++) {
int p = j * i * 2;
for (int k = p; k < p + i; k++) {
int x = a[k], y = mul(a[k + i], now);
a[k] = add(x, y), a[k + i] = sub(x, y);
}
now = mul(now, pre.w[__builtin_ctz(j + 1)]);
}
}
}
void IDIF(int a[], int n) {
for (int i = 1, l = n >> 1; l; i <<= 1, l >>= 1) {
int now = 1;
for (int j = 0; j < l; j++) {
int p = j * i * 2;
for (int k = p; k < p + i; k++) {
int x = a[k], y = a[k + i];
a[k] = add(x, y), a[k + i] = mul(x - y + P, now);
}
now = mul(now, pre.iw[__builtin_ctz(j + 1)]);
}
}
int inv = Pow(n, P - 2);
for (int i = 0; i < n; i++) a[i] = mul(a[i], inv);
}
void polyInv(int n, int a[], int b[]) {
static int c[N];
int lim = ceil2(n);
memset(b, 0, lim * 8);
b[0] = 1;
for (int k = 1; k < lim; k <<= 1) {
memcpy(c, a, k * 8);
DIF(b, k * 4), DIF(c, k * 4);
for (int i = 0; i < k * 4; i++)
b[i] = mul(b[i], 2 + P - mul(c[i], b[i]));
IDIF(b, k * 4), memset(b + k * 2, 0, k * 8);
}
memset(c, 0, lim * 8);
}
using poly=vi;
#define PROD(op) auto operator op(auto a,const auto&b){return a op##= b;}
poly&operator+=(poly&a,const poly&b){
if(b.size()>a.size())a.resize(b.size());
for(int i=0;i<ssize(b);++i)(a[i]+=b[i])%=M;
return a;
}
poly&operator-=(poly&a,const poly&b){
if(b.size()>a.size())a.resize(b.size());
for(int i=0;i<ssize(b);++i)(a[i]+=M-b[i])%=M;
return a;
}
poly&operator*=(poly&a,poly b){
int lim=std::bit_ceil(a.size()+b.size()-1);
a.resize(lim);
b.resize(lim);
DIF(a.data(),lim);
DIF(b.data(),lim);
for(int i=0;i<lim;++i){
a[i]=a[i]*ll(b[i])%M;
}
IDIF(a.data(),lim);
return a;
}
PROD(+) PROD(-) PROD(*) PROD(/)
signed main(){
using std::cin,std::cout,std::cerr;
//std::ios::sync_with_stdio(0);std::cin.tie(0);std::cout.tie(0);
int n=g90,m=g90;
++m;
V<pii>a(n),b(m);
V<poly>pa(n),pb(m);
auto res=a;
for(int i=0;i<n;++i){
auto&&[l,r]=a[i];
l=g90,r=g90;
pa[i].resize(l,0);
pa[i].resize(r+1,1);
}
for(int i=0;i<m-1;++i){
auto&&[l,r]=b[i];
l=g90,r=g90;
pb[i].resize(l,0);
pb[i].resize(r+1,1);
}
poly prod={1};
for(int i=0;i<n;++i){
prod*=pa[i];
vi ans(m);
auto solve=[&](auto&&self,int l,int r,poly&p,int of)->poly{
{
int ll=of-500*(r-l)-1,rr=of+500*(r-l)+1;
ckmax(ll,0);
ckmin(rr,ssize(p)-1);
poly tmp;
for(int i=ll;i<=rr;++i)tmp.eb(p[i]);
p=std::move(tmp);
of-=ll;
}
if(r-l<=1){
ans[l]=p[of];
return pb[l];
}
int mid=(l+r)/2;
auto tmp=p;
auto pl=self(self,l,mid,tmp,of);
tmp.clear();
reverse_copy(all(pl),back_inserter(tmp));
p*=tmp;
of+=ssize(tmp)-1;
auto pr=self(self,mid,r,p,of);
return pl*pr;
};
auto tmp=prod;
solve(solve,0,m,tmp,0);
for(int i=1;i<m;++i)printf("%d ",ans[i]);
puts("");
}
}//main()
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
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...
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 ...