算法分析
差分变种
事实证明关同步 是比scanf快的
题解先gugu了 放个代码 明天再来补
AC Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e5 + 10;
int a[N],b[N],c[N],d[N],f[N];
int zero = 0;
int n,q,mod;
void inline update(int pos,int val)
{
if(pos >= 1 && pos <= n)
{
zero -= (d[pos] == 0);
d[pos] = (d[pos] + val + mod) % mod;
zero += (d[pos] == 0);
}
return ;
}
signed main()
{
cin.tie(0);
ios::sync_with_stdio(false);
//scanf("%lld%lld%lld",&n,&q,&mod);
cin >> n >> q >> mod;
for(int i = 1;i <= n;i ++) cin >> a[i];
for(int i = 1;i <= n;i ++) cin >> b[i];
for(int i = 1;i <= n;i ++) c[i] = a[i] - b[i];
//d[i] = c[i] - c[i - 1] - c[i - 2]
d[1] = c[1] % mod;
d[2] = (c[2] - c[1] + mod) % mod;
for(int i = 3;i <= n;i ++) d[i] = (c[i] - c[i - 1] + mod - c[i - 2] + mod)% mod;
for (int i = 1; i <= n; i++) zero += (d[i] == 0);
f[1] = 1,f[2] = 1;
for(int i = 3;i <= n + 2;i ++) f[i] = (f[i - 1] + f[i - 2]) % mod;
for(int i = 1;i <= q;i ++)
{
char op;int L,R;
cin >> op >> L >> R;
if(op == 'A')
{
//d[l] += 1
//d[r + 1] -= (f[R - L + 2])
//d[r + 2] -= f[R - L + 1]
update(L,1);
update(R + 1,- f[R - L + 2]);
update(R + 2,- f[R - L + 1]);
}
else
{
update(L,-1);
update(R + 1,f[R - L + 2]);
update(R + 2,f[R - L + 1]);
}
if(zero == n) puts("YES");
else puts("NO");
}
return 0;
}