多校A层冲刺NOIP2024模拟赛05
A. 好数(number)
很容易想到 \(n^3\) 枚举两个,看第三个是否出现,扩展一下,枚举一个,看剩下需要的和是否出现过,提前处理出两两的和
和最早能合出这个数的位置,复杂的 \(O(n^2)\)
点击查看代码
#include<bits/stdc++.h>
const int maxn=5000+10;
using namespace std;
int n,a[maxn],cnt,ans,pos1[200005],pos2[200005];
bool zh[200005],fu[200005];
int main()
{
freopen("number.in","r",stdin);
freopen("number.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
memset(pos1,0x7f,sizeof pos1);
memset(pos2,0x7f,sizeof pos2);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
int x=a[i]+a[j];
if(x>0)
{
zh[x]=1;
pos1[x]=min(pos1[x],max(i,j));
}
else
{
fu[-x]=1;
pos2[-x]=min(pos2[-x],max(i,j));
}
}
}
for(int i=2;i<=n;i++)
{
for(int j=1;j<i;j++)
{
int x=a[i]-a[j];
if(x>0)
{
if(zh[x]&&pos1[x]<i)
{
ans++;
break;
}
}
else
{
if(fu[-x]&&pos2[-x]<i)
{
ans++;
break;
}
}
}
}
cout<<ans;
return 0;
}
/*
*/
B. SOS字符串(sos)
还是考虑容斥,发现正着容斥不好实现,所以我们用总方案数减去个数2个以内的个数,可以直接用 \(dp\) 求,跑的很快
点击查看代码
#include<bits/stdc++.h>
const int mod=1e9+7;
const int maxn=1e6+10;
using namespace std;
int n,ans,f[maxn][3][3];
int qpow(int x,int y)
{
int ans=1;
while(y)
{
if(y&1) ans=1ll*ans*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return ans;
}
int main()
{
freopen("sos.in","r",stdin);
freopen("sos.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
f[0][0][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=2;j++)
{
if(j)
{
f[i][j][1]=(f[i-1][j][0]+f[i-1][j][1])%mod;
f[i][j][0]=1ll*(1ll*f[i-1][j][0]*25+1ll*f[i-1][j][1]*24+1ll*f[i-1][j][2]*25+f[i-1][j-1][2])%mod;
f[i][j][2]=f[i-1][j][1];
}
else
{
f[i][j][1]=(f[i-1][j][0]+f[i-1][j][1])%mod;
f[i][j][0]=1ll*(1ll*f[i-1][j][0]*25+1ll*f[i-1][j][1]*24+1ll*f[i-1][j][2]*25)%mod;
f[i][j][2]=f[i-1][j][1];
}
}
}
int ans=0;
for(int i=0;i<=2;i++)
for(int j=0;j<=2;j++) ans=(ans+f[n][i][j])%mod;
cout<<(qpow(26,n)-ans+mod)%mod;
return 0;
}
/*
10
*/
C. 集训营的气球(balloon)
发现其实是一个背包 \(dp\),可以用线段树维护 \(dp\) 过程,\(log(n)c^2\) 修改,查询可以用总方案数减去不足 \(c\) 的方案数
总复杂度 \(nc^2+qlog(n)c^2\),但 \(1e6\) 的数据范围。。。\(256\) 的空间。。。很明显极限很难过去,所以我们要卡!!!
空间比较好卡,直接把最后一层叶子节点舍去,到区间长度为2时直接维护 \(dp\) 信息,空间少了一倍,时间也少了一些
时间。。。涛哥的超级快读,\(dp\) 循环展开就卡过去了
点击查看代码
#include<bits/stdc++.h>
#define lid id<<1
#define rid id<<1|1
const int mod=1e9+7;
const int maxn=1e6+10;
using namespace std;
int n,c,q,a[maxn],b[maxn];
struct lsx
{
int dp[20],tot;
}m[maxn<<1];
namespace Octane {
//non terrae plus ultra dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#define OCTANE // dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#define BUFFER_SIZE 100000 // dqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#define ll long long // dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#define db double // dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#define ldb long double // dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
char ibuf[100000], obuf[100000], *p1=ibuf,*p2=ibuf,*p3=obuf;
#ifdef ONLINE_JUDGE//dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#define getchar() ((p1==p2) and (p2=(p1=ibuf)+fread(ibuf,1,\
BUFFER_SIZE,stdin),p1==p2)?(EOF):(*p1++)) // dqrdqrdqrdqrdqr
#define putchar(x) ((p3==obuf+BUFFER_SIZE) && (fwrite(obuf,\
p3-obuf,1,stdout),p3=obuf),*p3++=x) // dqrdqrdqrdqrdqrdqrdqr
#endif// fread in OJ, getchar in local dqrdqrdqrdqrdqrdqrdqr
#define isdigit(ch) (ch>47&&ch<58)//dqrdqrdqrdqrdqrdqrdqrdqr
#define isspace(ch) (ch<=32&&ch!=EOF)//dqrdqrdqrdqrdqrdqrdqr
#define isseen(ch) (ch>32) // dqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
struct Octane_t{~Octane_t(){fwrite(obuf,p3-obuf, 1, stdout);
}bool flag=false;operator bool(){return flag;} }io; template
<typename T>inline T read(){T s=0; int w = 1; char ch; while
(ch=getchar(), !isdigit(ch)&&(ch!=EOF))if(ch == '-') w = -1;
if(ch == EOF) return 0; while(isdigit(ch)) s = s*10+ch-48,ch
=getchar(); return s *= w; } template<typename T>inline bool
read(T &s) { s = 0; int w = 1; char ch; while(ch = getchar()
,!isdigit(ch)&&(ch!=EOF))if(ch == '-') w = -1; if(ch == EOF)
return false;while(isdigit(ch))s = s*10+ch-48, ch=getchar();
return s*=w,true;}inline bool read(char &s){while(s= getchar
(), isspace(s)); return s != EOF; } inline bool read(char *s
){char ch=getchar();while(isspace(ch))ch= getchar();if(ch ==
EOF)return false;while(isseen(ch)) *s++ = ch, ch= getchar();
*s='\000';return true;}template<typename T> void printv(T a)
{if(a== 0){ putchar('0'); return void(); }static char st[65]
; int top = 0; if (a < 0) putchar ('-'), a = - a; while(a)st
[++top]='0'+a%10,a/=10;while(top)putchar(st[top--]);} inline
void printv(char c){putchar(c);}inline void printv(char *s){
for(int i=0;s[i];i++)putchar(s[i]);}inline void printv(const
char *s){ for(int i=0;s[i];i++) putchar(s[i]); } inline void
printv(bool a){ if(a != 0)putchar('1'); else putchar('0'); }
#ifdef _GLIBCXX_STRING // support for string dqrdqrdqrdqrdqr
inline bool read(std::string& s) { s = ""; char ch; while(ch
=getchar(), isspace(ch)); if(ch == EOF) return false; while(
!isspace(ch)) s+=ch,ch=getchar(); return true; } inline bool
getline(Octane_t &io,std::string s){s="";char ch= getchar();
if(ch==EOF)return false;while(ch!='\n' and ch !=EOF)s+=ch,ch
=getchar();return true;}inline void printv(const std::string
&a){for(auto i = a.begin(); i != a.end(); ++i) putchar(*i);}
#endif// dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
template<typename T>inline void print(const char *p,T first)
{ int n = strlen(p) - 1; for(int i = 0; i <= n; i++) { if(p[
i] == '`') { putchar(p[++ i]); continue; } else if ( p[i] ==
'{'){printv(first); i++; continue; } else putchar(p[i]); } }
#if __cplusplus >= 201103L // support for many values dqrdqr
template<typename T,typename... T1>inline int read(T& a, T1&
...other){return read(a)+read(other...); } inline void print
(const char *p) { printv(p); }template<typename T1, typename
... T2>void print(const char*p, T1 first, T2 ...other) { int
n=strlen(p)-1; for(int i = 0; i <= n; i++) { if(p[i] == '`')
{putchar(p[++i]);continue;}else if(p[i]=='{'){printv(first);
print(p+i+2,other...);return void();}else putchar(p[i]); } }
#endif // dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdq
template <typename T> Octane_t& operator >> (Octane_t &io, T
&b){return io.flag=read(b),io;}Octane_t& operator>>(Octane_t
&io, char *b){return io.flag=read(b), io;} template<typename
T>Octane_t&operator<<(Octane_t&io,T b){return printv(b),io;}
#define cout io// dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#define cin io // dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#define endl '\n' // dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#undef ll// dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#undef db// dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
#undef ldb//dqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqrdqr
} using namespace Octane;
inline int mo(long long x){return x>=mod?x%mod:x;}
inline void up(int id)
{
m[id].tot=1ll*m[lid].tot*m[rid].tot%mod;
register int i;
for(i=0;i<c;i++) m[id].dp[i]=0;
if(0<c)m[id].dp[0]=(m[id].dp[0]+1ll*m[lid].dp[0]*m[rid].dp[0]%mod)%mod;else return ;
if(1<c)m[id].dp[1]=(m[id].dp[1]+1ll*m[lid].dp[1]*m[rid].dp[0]%mod+1ll*m[lid].dp[0]*m[rid].dp[1]%mod)%mod;else return ;
if(2<c)m[id].dp[2]=(m[id].dp[2]+1ll*m[lid].dp[2]*m[rid].dp[0]%mod+1ll*m[lid].dp[1]*m[rid].dp[1]%mod+1ll*m[lid].dp[0]*m[rid].dp[2]%mod)%mod;else return ;
if(3<c)m[id].dp[3]=(m[id].dp[3]+1ll*m[lid].dp[3]*m[rid].dp[0]%mod+1ll*m[lid].dp[2]*m[rid].dp[1]%mod+1ll*m[lid].dp[1]*m[rid].dp[2]%mod+1ll*m[lid].dp[0]*m[rid].dp[3]%mod)%mod;else return ;
if(4<c)m[id].dp[4]=(m[id].dp[4]+1ll*m[lid].dp[4]*m[rid].dp[0]%mod+1ll*m[lid].dp[3]*m[rid].dp[1]%mod+1ll*m[lid].dp[2]*m[rid].dp[2]%mod+1ll*m[lid].dp[1]*m[rid].dp[3]%mod+1ll*m[lid].dp[0]*m[rid].dp[4]%mod)%mod;else return ;
if(5<c)m[id].dp[5]=(m[id].dp[5]+1ll*m[lid].dp[5]*m[rid].dp[0]%mod+1ll*m[lid].dp[4]*m[rid].dp[1]%mod+1ll*m[lid].dp[3]*m[rid].dp[2]%mod+1ll*m[lid].dp[2]*m[rid].dp[3]%mod+1ll*m[lid].dp[1]*m[rid].dp[4]%mod+1ll*m[lid].dp[0]*m[rid].dp[5]%mod)%mod;else return ;
if(6<c)m[id].dp[6]=(m[id].dp[6]+1ll*m[lid].dp[6]*m[rid].dp[0]%mod+1ll*m[lid].dp[5]*m[rid].dp[1]%mod+1ll*m[lid].dp[4]*m[rid].dp[2]%mod+1ll*m[lid].dp[3]*m[rid].dp[3]%mod+1ll*m[lid].dp[2]*m[rid].dp[4]%mod+1ll*m[lid].dp[1]*m[rid].dp[5]%mod+1ll*m[lid].dp[0]*m[rid].dp[6]%mod)%mod;else return ;
if(7<c)m[id].dp[7]=(m[id].dp[7]+1ll*m[lid].dp[7]*m[rid].dp[0]%mod+1ll*m[lid].dp[6]*m[rid].dp[1]%mod+1ll*m[lid].dp[5]*m[rid].dp[2]%mod+1ll*m[lid].dp[4]*m[rid].dp[3]%mod+1ll*m[lid].dp[3]*m[rid].dp[4]%mod+1ll*m[lid].dp[2]*m[rid].dp[5]%mod+1ll*m[lid].dp[1]*m[rid].dp[6]%mod+1ll*m[lid].dp[0]*m[rid].dp[7]%mod)%mod;else return ;
if(8<c)m[id].dp[8]=(m[id].dp[8]+1ll*m[lid].dp[8]*m[rid].dp[0]%mod+1ll*m[lid].dp[7]*m[rid].dp[1]%mod+1ll*m[lid].dp[6]*m[rid].dp[2]%mod+1ll*m[lid].dp[5]*m[rid].dp[3]%mod+1ll*m[lid].dp[4]*m[rid].dp[4]%mod+1ll*m[lid].dp[3]*m[rid].dp[5]%mod+1ll*m[lid].dp[2]*m[rid].dp[6]%mod+1ll*m[lid].dp[1]*m[rid].dp[7]%mod+1ll*m[lid].dp[0]*m[rid].dp[8]%mod)%mod;else return ;
if(9<c)m[id].dp[9]=(m[id].dp[9]+1ll*m[lid].dp[9]*m[rid].dp[0]%mod+1ll*m[lid].dp[8]*m[rid].dp[1]%mod+1ll*m[lid].dp[7]*m[rid].dp[2]%mod+1ll*m[lid].dp[6]*m[rid].dp[3]%mod+1ll*m[lid].dp[5]*m[rid].dp[4]%mod+1ll*m[lid].dp[4]*m[rid].dp[5]%mod+1ll*m[lid].dp[3]*m[rid].dp[6]%mod+1ll*m[lid].dp[2]*m[rid].dp[7]%mod+1ll*m[lid].dp[1]*m[rid].dp[8]%mod+1ll*m[lid].dp[0]*m[rid].dp[9]%mod)%mod;else return ;
if(10<c)m[id].dp[10]=(m[id].dp[10]+1ll*m[lid].dp[10]*m[rid].dp[0]%mod+1ll*m[lid].dp[9]*m[rid].dp[1]%mod+1ll*m[lid].dp[8]*m[rid].dp[2]%mod+1ll*m[lid].dp[7]*m[rid].dp[3]%mod+1ll*m[lid].dp[6]*m[rid].dp[4]%mod+1ll*m[lid].dp[5]*m[rid].dp[5]%mod+1ll*m[lid].dp[4]*m[rid].dp[6]%mod+1ll*m[lid].dp[3]*m[rid].dp[7]%mod+1ll*m[lid].dp[2]*m[rid].dp[8]%mod+1ll*m[lid].dp[1]*m[rid].dp[9]%mod+1ll*m[lid].dp[0]*m[rid].dp[10]%mod)%mod;else return ;
if(11<c)m[id].dp[11]=(m[id].dp[11]+1ll*m[lid].dp[11]*m[rid].dp[0]%mod+1ll*m[lid].dp[10]*m[rid].dp[1]%mod+1ll*m[lid].dp[9]*m[rid].dp[2]%mod+1ll*m[lid].dp[8]*m[rid].dp[3]%mod+1ll*m[lid].dp[7]*m[rid].dp[4]%mod+1ll*m[lid].dp[6]*m[rid].dp[5]%mod+1ll*m[lid].dp[5]*m[rid].dp[6]%mod+1ll*m[lid].dp[4]*m[rid].dp[7]%mod+1ll*m[lid].dp[3]*m[rid].dp[8]%mod+1ll*m[lid].dp[2]*m[rid].dp[9]%mod+1ll*m[lid].dp[1]*m[rid].dp[10]%mod+1ll*m[lid].dp[0]*m[rid].dp[11]%mod)%mod;else return ;
if(12<c)m[id].dp[12]=(m[id].dp[12]+1ll*m[lid].dp[12]*m[rid].dp[0]%mod+1ll*m[lid].dp[11]*m[rid].dp[1]%mod+1ll*m[lid].dp[10]*m[rid].dp[2]%mod+1ll*m[lid].dp[9]*m[rid].dp[3]%mod+1ll*m[lid].dp[8]*m[rid].dp[4]%mod+1ll*m[lid].dp[7]*m[rid].dp[5]%mod+1ll*m[lid].dp[6]*m[rid].dp[6]%mod+1ll*m[lid].dp[5]*m[rid].dp[7]%mod+1ll*m[lid].dp[4]*m[rid].dp[8]%mod+1ll*m[lid].dp[3]*m[rid].dp[9]%mod+1ll*m[lid].dp[2]*m[rid].dp[10]%mod+1ll*m[lid].dp[1]*m[rid].dp[11]%mod+1ll*m[lid].dp[0]*m[rid].dp[12]%mod)%mod;else return ;
if(13<c)m[id].dp[13]=(m[id].dp[13]+1ll*m[lid].dp[13]*m[rid].dp[0]%mod+1ll*m[lid].dp[12]*m[rid].dp[1]%mod+1ll*m[lid].dp[11]*m[rid].dp[2]%mod+1ll*m[lid].dp[10]*m[rid].dp[3]%mod+1ll*m[lid].dp[9]*m[rid].dp[4]%mod+1ll*m[lid].dp[8]*m[rid].dp[5]%mod+1ll*m[lid].dp[7]*m[rid].dp[6]%mod+1ll*m[lid].dp[6]*m[rid].dp[7]%mod+1ll*m[lid].dp[5]*m[rid].dp[8]%mod+1ll*m[lid].dp[4]*m[rid].dp[9]%mod+1ll*m[lid].dp[3]*m[rid].dp[10]%mod+1ll*m[lid].dp[2]*m[rid].dp[11]%mod+1ll*m[lid].dp[1]*m[rid].dp[12]%mod+1ll*m[lid].dp[0]*m[rid].dp[13]%mod)%mod;else return ;
if(14<c)m[id].dp[14]=(m[id].dp[14]+1ll*m[lid].dp[14]*m[rid].dp[0]%mod+1ll*m[lid].dp[13]*m[rid].dp[1]%mod+1ll*m[lid].dp[12]*m[rid].dp[2]%mod+1ll*m[lid].dp[11]*m[rid].dp[3]%mod+1ll*m[lid].dp[10]*m[rid].dp[4]%mod+1ll*m[lid].dp[9]*m[rid].dp[5]%mod+1ll*m[lid].dp[8]*m[rid].dp[6]%mod+1ll*m[lid].dp[7]*m[rid].dp[7]%mod+1ll*m[lid].dp[6]*m[rid].dp[8]%mod+1ll*m[lid].dp[5]*m[rid].dp[9]%mod+1ll*m[lid].dp[4]*m[rid].dp[10]%mod+1ll*m[lid].dp[3]*m[rid].dp[11]%mod+1ll*m[lid].dp[2]*m[rid].dp[12]%mod+1ll*m[lid].dp[1]*m[rid].dp[13]%mod+1ll*m[lid].dp[0]*m[rid].dp[14]%mod)%mod;else return ;
if(15<c)m[id].dp[15]=(m[id].dp[15]+1ll*m[lid].dp[15]*m[rid].dp[0]%mod+1ll*m[lid].dp[14]*m[rid].dp[1]%mod+1ll*m[lid].dp[13]*m[rid].dp[2]%mod+1ll*m[lid].dp[12]*m[rid].dp[3]%mod+1ll*m[lid].dp[11]*m[rid].dp[4]%mod+1ll*m[lid].dp[10]*m[rid].dp[5]%mod+1ll*m[lid].dp[9]*m[rid].dp[6]%mod+1ll*m[lid].dp[8]*m[rid].dp[7]%mod+1ll*m[lid].dp[7]*m[rid].dp[8]%mod+1ll*m[lid].dp[6]*m[rid].dp[9]%mod+1ll*m[lid].dp[5]*m[rid].dp[10]%mod+1ll*m[lid].dp[4]*m[rid].dp[11]%mod+1ll*m[lid].dp[3]*m[rid].dp[12]%mod+1ll*m[lid].dp[2]*m[rid].dp[13]%mod+1ll*m[lid].dp[1]*m[rid].dp[14]%mod+1ll*m[lid].dp[0]*m[rid].dp[15]%mod)%mod;else return ;
if(16<c)m[id].dp[16]=(m[id].dp[16]+1ll*m[lid].dp[16]*m[rid].dp[0]%mod+1ll*m[lid].dp[15]*m[rid].dp[1]%mod+1ll*m[lid].dp[14]*m[rid].dp[2]%mod+1ll*m[lid].dp[13]*m[rid].dp[3]%mod+1ll*m[lid].dp[12]*m[rid].dp[4]%mod+1ll*m[lid].dp[11]*m[rid].dp[5]%mod+1ll*m[lid].dp[10]*m[rid].dp[6]%mod+1ll*m[lid].dp[9]*m[rid].dp[7]%mod+1ll*m[lid].dp[8]*m[rid].dp[8]%mod+1ll*m[lid].dp[7]*m[rid].dp[9]%mod+1ll*m[lid].dp[6]*m[rid].dp[10]%mod+1ll*m[lid].dp[5]*m[rid].dp[11]%mod+1ll*m[lid].dp[4]*m[rid].dp[12]%mod+1ll*m[lid].dp[3]*m[rid].dp[13]%mod+1ll*m[lid].dp[2]*m[rid].dp[14]%mod+1ll*m[lid].dp[1]*m[rid].dp[15]%mod+1ll*m[lid].dp[0]*m[rid].dp[16]%mod)%mod;else return ;
if(17<c)m[id].dp[17]=(m[id].dp[17]+1ll*m[lid].dp[17]*m[rid].dp[0]%mod+1ll*m[lid].dp[16]*m[rid].dp[1]%mod+1ll*m[lid].dp[15]*m[rid].dp[2]%mod+1ll*m[lid].dp[14]*m[rid].dp[3]%mod+1ll*m[lid].dp[13]*m[rid].dp[4]%mod+1ll*m[lid].dp[12]*m[rid].dp[5]%mod+1ll*m[lid].dp[11]*m[rid].dp[6]%mod+1ll*m[lid].dp[10]*m[rid].dp[7]%mod+1ll*m[lid].dp[9]*m[rid].dp[8]%mod+1ll*m[lid].dp[8]*m[rid].dp[9]%mod+1ll*m[lid].dp[7]*m[rid].dp[10]%mod+1ll*m[lid].dp[6]*m[rid].dp[11]%mod+1ll*m[lid].dp[5]*m[rid].dp[12]%mod+1ll*m[lid].dp[4]*m[rid].dp[13]%mod+1ll*m[lid].dp[3]*m[rid].dp[14]%mod+1ll*m[lid].dp[2]*m[rid].dp[15]%mod+1ll*m[lid].dp[1]*m[rid].dp[16]%mod+1ll*m[lid].dp[0]*m[rid].dp[17]%mod)%mod;else return ;
if(18<c)m[id].dp[18]=(m[id].dp[18]+1ll*m[lid].dp[18]*m[rid].dp[0]%mod+1ll*m[lid].dp[17]*m[rid].dp[1]%mod+1ll*m[lid].dp[16]*m[rid].dp[2]%mod+1ll*m[lid].dp[15]*m[rid].dp[3]%mod+1ll*m[lid].dp[14]*m[rid].dp[4]%mod+1ll*m[lid].dp[13]*m[rid].dp[5]%mod+1ll*m[lid].dp[12]*m[rid].dp[6]%mod+1ll*m[lid].dp[11]*m[rid].dp[7]%mod+1ll*m[lid].dp[10]*m[rid].dp[8]%mod+1ll*m[lid].dp[9]*m[rid].dp[9]%mod+1ll*m[lid].dp[8]*m[rid].dp[10]%mod+1ll*m[lid].dp[7]*m[rid].dp[11]%mod+1ll*m[lid].dp[6]*m[rid].dp[12]%mod+1ll*m[lid].dp[5]*m[rid].dp[13]%mod+1ll*m[lid].dp[4]*m[rid].dp[14]%mod+1ll*m[lid].dp[3]*m[rid].dp[15]%mod+1ll*m[lid].dp[2]*m[rid].dp[16]%mod+1ll*m[lid].dp[1]*m[rid].dp[17]%mod+1ll*m[lid].dp[0]*m[rid].dp[18]%mod)%mod;else return ;
if(19<c)m[id].dp[19]=(m[id].dp[19]+1ll*m[lid].dp[19]*m[rid].dp[0]%mod+1ll*m[lid].dp[18]*m[rid].dp[1]%mod+1ll*m[lid].dp[17]*m[rid].dp[2]%mod+1ll*m[lid].dp[16]*m[rid].dp[3]%mod+1ll*m[lid].dp[15]*m[rid].dp[4]%mod+1ll*m[lid].dp[14]*m[rid].dp[5]%mod+1ll*m[lid].dp[13]*m[rid].dp[6]%mod+1ll*m[lid].dp[12]*m[rid].dp[7]%mod+1ll*m[lid].dp[11]*m[rid].dp[8]%mod+1ll*m[lid].dp[10]*m[rid].dp[9]%mod+1ll*m[lid].dp[9]*m[rid].dp[10]%mod+1ll*m[lid].dp[8]*m[rid].dp[11]%mod+1ll*m[lid].dp[7]*m[rid].dp[12]%mod+1ll*m[lid].dp[6]*m[rid].dp[13]%mod+1ll*m[lid].dp[5]*m[rid].dp[14]%mod+1ll*m[lid].dp[4]*m[rid].dp[15]%mod+1ll*m[lid].dp[3]*m[rid].dp[16]%mod+1ll*m[lid].dp[2]*m[rid].dp[17]%mod+1ll*m[lid].dp[1]*m[rid].dp[18]%mod+1ll*m[lid].dp[0]*m[rid].dp[19]%mod)%mod;else return ;
}
void build(int id,int l,int r)
{
if(l==r)
{
m[id].dp[0]=b[l],m[id].dp[1]=a[l];
m[id].tot=(a[l]+b[l]);
return;
}
if(l+1==r)
{
m[id].tot=1ll*(a[l]+b[l])*(a[r]+b[r])%mod;
m[id].dp[0]=m[id].dp[1]=m[id].dp[2]=0;
m[id].dp[0]=(m[id].dp[0]+1ll*b[l]*b[r]%mod)%mod;
if(c>1)
{
m[id].dp[1]=(m[id].dp[1]+1ll*b[l]*a[r]%mod)%mod;
m[id].dp[1]=(m[id].dp[1]+1ll*a[l]*b[r]%mod)%mod;
}
if(c>2)
{
m[id].dp[2]=(m[id].dp[2]+1ll*a[l]*a[r]%mod)%mod;
}
return;
}
int mid= (l+r>>1);
build(lid,l,mid);
build(rid,mid+1,r);
up(id);
}
void update(int id,int l,int r,int x)
{
if(l==r)
{
m[id].dp[0]=b[l],m[id].dp[1]=a[l];
m[id].tot=(a[l]+b[l]);
return;
}
if(l+1==r)
{
m[id].tot=1ll*(a[l]+b[l])*(a[r]+b[r])%mod;
m[id].dp[0]=m[id].dp[1]=m[id].dp[2]=0;
m[id].dp[0]=(m[id].dp[0]+1ll*b[l]*b[r]%mod)%mod;
if(c>1)
{
m[id].dp[1]=(m[id].dp[1]+1ll*b[l]*a[r]%mod)%mod;
m[id].dp[1]=(m[id].dp[1]+1ll*a[l]*b[r]%mod)%mod;
}
if(c>2)
{
m[id].dp[2]=(m[id].dp[2]+1ll*a[l]*a[r]%mod)%mod;
}
return;
}
int mid=(l+r>>1);
x<=mid?update(lid,l,mid,x):update(rid,mid+1,r,x);
up(id);
}
int main()
{
freopen("balloon.in","r",stdin);
freopen("balloon.out","w",stdout);
ios::sync_with_stdio(0);
// cin.tie(0),cout.tie(0);
cin>>n>>c;
register int i;
for(i=1;i<=n;i++)
cin>>a[i];
for(i=1;i<=n;i++)
cin>>b[i];
build(1,1,n);
cin>>q;
int x,ans;
while(q--)
{
cin>>x;
cin>>a[x],cin>>b[x];
update(1,1,n,x);
ans=m[1].tot;
for(i=0;i<c;i++) ans=(ans-m[1].dp[i]+mod)%mod;
cout<<ans<<'\n';
}
return 0;
}
/*
*/
最近状态一直不太好,脑子也不太灵光,每次\(T1\)要么是想不出来磕4个小时,要么就是别人10分钟,我一个半小时才想到
我就是又菜又不服,总想写出来,写不出来后面题就摆了,部分分也不打了,还得多练。。。