\(\mathcal{Description}\)

  Link.

  有 \(n\) 物品,第 \(i\) 中有 \(a_i\) ,单价为 \(b_i\)。共 \(q\) 次询问,每次查询用不超过 \(c\) 的钱购买种类在 \([l,r]\) 之中的物品,有多少种方案。强制在线;答案对 \(998244353\) 取模。

  \(n\le10^4\),\(q\le5\times10^4\),\(c\le10^3\)。

\(\mathcal{Solution}\)

  快速回答区间询问,最基础但容易被忽略的处理方式——前缀和差。

  考虑第 \(i\) 中物品的 OGF,显然有

\[G_i(x)=\frac{1-x^{(a_i+1)b_i}}{1-x^{b_i}}.
\]

欲求答案 \(\sum_{k\le c}[x^k]\prod_{i=l}^rG_i(x)\),转化为前缀积乘上前缀积的逆,预处理出

\[S_i(x)=\prod_{j=1}^iG_j(x),\\
S^{-1}_i(x)=\prod_{j=1}^iG_j^{-1}(x).
\]

顺带发现 \(G_j(x)\) 和 \(G_j^{-1}\) 长相完全一样,所以这俩也就是换换加减号的事儿。精巧递推一发可以做到 \(\mathcal O(nc)\) 预处理,查询复杂度即求前缀系数和,预先将 \(S_i(x)\) 或 \(S_i^{-1}(x)\) 的系数做前缀和后即为求卷积的某项系数,暴力模拟,则有单次查询复杂度 \(\mathcal O(c)\)。

\(\mathcal{Code}\)

/* Clearink */

#include <cstdio>
#include <cstring> #define rep( i, l, r ) for ( int i = l, rep##i = r; i <= rep##i; ++i )
#define per( i, r, l ) for ( int i = r, per##i = l; i >= per##i; --i ) inline int rint() {
int x = 0, s = getchar();
for ( ; s < '0' || '9' < s; s = getchar() );
for ( ; '0' <= s && s <= '9'; s = getchar() ) x = x * 10 + ( s ^ '0' );
return x;
} inline void wint( const int x ) {
if ( 9 < x ) wint( x / 10 );
putchar( x % 10 ^ '0' );
} const int MAXN = 1e4, MAXC = 1e3, MOD = 998244353;
int n, q, a[MAXN + 5], b[MAXN + 5];
int f[MAXN + 5][MAXC + 5], g[MAXN + 5][MAXC + 5]; inline void subeq( int& a, const int b ) { ( a -= b ) < 0 && ( a += MOD ); }
inline int sub( int a, const int b ) { return ( a -= b ) < 0 ? a + MOD : a; }
inline void addeq( int& a, const int b ) { ( a += b ) >= MOD && ( a -= MOD ); }
inline int add( int a, const int b ) { return ( a += b ) < MOD ? a : a - MOD; }
inline int mul( const long long a, const int b ) { return int( a * b % MOD ); } inline void init() {
f[0][0] = g[0][0] = 1;
rep ( i, 1, n ) {
memcpy( f[i], f[i - 1], sizeof f[i] );
memcpy( g[i], g[i - 1], sizeof g[i] );
int t;
rep ( j, t = b[i], MAXC ) addeq( f[i][j], f[i][j - t] );
per ( j, MAXC, t = ( a[i] + 1 ) * b[i] ) subeq( f[i][j], f[i][j - t] );
rep ( j, t = ( a[i] + 1 ) * b[i], MAXC ) addeq( g[i][j], g[i][j - t] );
per ( j, MAXC, t = b[i] ) subeq( g[i][j], g[i][j - t] );
}
rep ( i, 0, n ) rep ( j, 1, MAXC ) addeq( g[i][j], g[i][j - 1] );
} int main() {
freopen( "shop.in", "r", stdin );
freopen( "shop.out", "w", stdout ); n = rint(), q = rint();
rep ( i, 1, n ) a[i] = rint(), b[i] = rint(); init(); for ( int ans = 0, l, r, c; q--; ) {
l = ( rint() + ans ) % n + 1, r = ( rint() + ans ) % n + 1, c = rint();
if ( l > r ) l ^= r ^= l ^= r;
ans = 0;
rep ( i, 0, c ) addeq( ans, mul( f[r][i], g[l - 1][c - i] ) );
wint( ans ), putchar( '\n' );
}
return 0;
}

Solution -「多校联训」小卖部的更多相关文章

  1. Solution -「多校联训」排水系统

    \(\mathcal{Description}\)   Link.   在 NOIP 2020 A 的基础上,每条边赋权值 \(a_i\),随机恰好一条边断掉,第 \(i\) 条段的概率正比于 \(a ...

  2. Solution -「多校联训」I Love Random

    \(\mathcal{Description}\)   给定排列 \(\{p_n\}\),可以在其上进行若干次操作,每次选取 \([l,r]\),把其中所有元素变为原区间最小值,求能够得到的所有不同序 ...

  3. Solution -「多校联训」签到题

    \(\mathcal{Description}\)   Link.   给定二分图 \(G=(X\cup Y,E)\),求对于边的一个染色 \(f:E\rightarrow\{1,2,\dots,c\ ...

  4. Solution -「多校联训」朝鲜时蔬

    \(\mathcal{Description}\)   Link.   破案了,朝鲜时蔬 = 超现实树!(指写得像那什么一样的题面.   对于整数集 \(X\),定义其 好子集 为满足 \(Y\sub ...

  5. Solution -「多校联训」消失的运算符

    \(\mathcal{Description}\)   Link.   给定长度为 \(n\) 的合法表达式序列 \(s\),其中数字仅有一位正数,运算符仅有 - 作为占位.求将其中恰好 \(k\) ...

  6. Solution -「多校联训」假人

    \(\mathcal{Description}\)   Link.   一种物品有 长度 和 权值 两种属性,现给定 \(n\) 组物品,第 \(i\) 组有 \(k_i\) 个,分别为 \((1,a ...

  7. Solution -「多校联训」古老的序列问题

    \(\mathcal{Description}\)   Link.   给定序列 \(\{a_n\}\),和 \(q\) 次形如 \([L,R]\) 的询问,每次回答 \[\sum_{[l,r]\su ...

  8. Solution -「多校联训」Sample

    \(\mathcal{Description}\)   Link   (稍作简化:)对于变量 \(p_{1..n}\),满足 \(p_i\in[0,1],~\sum p_i=1\) 时,求 \(\ma ...

  9. Solution -「多校联训」光影交错

    \(\mathcal{Description}\)   Link.   一个游戏包含若干次卡牌抽取,每次以 \(p_l\) 的概率得到 \(+1\),\(p_d\) 的概率得到 \(-1\),否则得到 ...

随机推荐

  1. Oracle 报 ORA-00054资源正忙的解决办法

    oracle之报错:ORA-00054: 资源正忙,要求指定 NOWAIT 问题如下: SQL> conn scott/tiger@vm_database Connected to Oracle ...

  2. nuxt写路由接口

    //在server/interface/city.js import Router from 'koa-router'; const router = new Router({ prefix:'/ci ...

  3. 下载并搭建maven环境

    1.下载maven 1.在官网下载maven  http://maven.apache.org/download.cgi 2.将下载maven解压.复制路径. 2.搭建maven环境 1.新建M2_H ...

  4. 51 Nod 1006 最长公共子序列(LCS & DP)

    原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1006 题目分析: 首先先知道LCS问题,这有两种: Long ...

  5. PWA 技术落地!让你的站点(Web)秒变APP(应用程序)

    Web应用方兴未艾,我们已经十分习惯习惯了在电脑上进行以自己的工作,而随着众多功能强大的在线网站,我们的Windows的桌面也不再拥挤着各种快捷方式:不光是PC端,在移动端我们也不再在浩如烟海的应用市 ...

  6. 【源码阅读】VictoriaMetrics中理解vm-backup中设置origin地址的用途

    lib/backup/actions/backup.go: // 118 行 partsToCopy := common.PartsDifference(srcParts, dstParts) //要 ...

  7. memcached 小记

    Memcached是一个自由开源的,高性能,分布式内存对象缓存系统. Memcached是一种基于内存的key-value存储,用来存储小块的任意数据(字符串.对象).这些数据可以是数据库调用.API ...

  8. 【Azure 应用服务】Azure Mobile App (NodeJS) 的服务端部署在App Service for Windows中出现404 Not Found -- The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

    问题描述 使用NodeJS的后端应用,开发一个Mobile App的服务端,手机端通过REST API来访问获取后端数据.在本地编译好后,通过npm start启动项目,访问效果如下: 但是,当把项目 ...

  9. 搭建BBS博客系统

    目录 一:搭建BBS项目 1.部署数据库 2.启动数据库 3.进入数据库 4.远程连接MySQL数据 5.pycham连接Mysql 二:开始部署BBS 1.上传代码 2.数据库迁移 3.删除文件 4 ...

  10. CKKS :Part1,普通编码/解码

    这篇文章,翻译于:[CKKS EXPLAINED: PART 1, VANILLA ENCODING AND DECODING] 主要介绍为CKKS中编码/解码做铺垫,讲一些基础知识 介绍 同态加密是 ...