[考试总结]noip模拟47
感觉自己放弃题目还是过于容易。
其实第一题不是很难,但是自己拿了一个暴力就走人了。。
然后其实简单优化一下子就有不少分数。
然后第二题的本质不同的子序列个数的方程没有推出来,如果推出来就会直接有 \(67pts\),但是自己只能用 \(2^n\) 暴力去计算。
第三题还是对期望有一些畏惧。。。
其实这个仔细想想方程并不难,然后这样就有很多分数,然后线段树确实不是很好写,但是基础 \(dp\) 也有很多。。。。
prime
我们可以先筛出来 \(1\)~$ min(sqrt(r),k)$ 之间的素数,然后向上筛,标记后异或。
然后没了。。。
#include<bits/stdc++.h>
using std::endl; using std::cout;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
#define asm(i,x) for(register signed i=head[x];i;i=edge[i].next)
namespace xin_io
{
#define debug cout<<"debug"<<endl
#define sb(x) cout<<#x" = "<<x<<' '
#define jb(x) cout<<#x" = "<<x<<endl
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1 ++
char buf[1<<20],*p1 = buf,*p2 = buf; typedef long long ll; typedef unsigned long long ull;
class xin_stream{public:template<typename type>xin_stream &operator >> (type &s)
{
register bool f = 0; s = 0; register char ch = gc();
while(!isdigit(ch)) f |= ch == '-',ch = gc();
while( isdigit(ch)) s = (s << 1) + (s << 3) + (ch xor 48),ch = gc(); return s = f ? -s : s,*this;
}}io;
}
using namespace xin_io; static const int maxn = 1e7+10;
#define int long long
namespace xin
{
bool number[maxn];
int prime[maxn];
int l,r,k,count = 0;
bool vis[maxn];
inline short main()
{
io >> l >> r >> k;
int N = std::min((ll)std::sqrt(r) * 1ll,k * 1ll);
memset(number,true,sizeof(number));
try(i,2,N)
{
if(number[i]) prime[count++]=i;
for(register int j=0;j<count&&prime[j]*i<=N;j++)
{
number[prime[j]*i]=false;
if(i%prime[j]==0)
break;
}
}
try(i,0,count-1)
{
register int temp = l / prime[i];
if(temp * prime[i] < l) temp += 1; temp += (temp == 1);
while(temp * prime[i] <= r)
{
vis[temp * prime[i] - l] = 1;
temp ++;
}
}
int ans = 0;
try(i,0,r - l)
if(!vis[i])
ans ^= (1ll * i + l);
cout<<ans<<endl;
return 0;
}
}
signed main() {return xin::main();}
sequence
好像还是第一次考到的矩阵快速幂优化\(dp\)
然后基础 \(dp\) 求本质不同子序列个数就是设\(f_i\) 表示以 \(i\) 结尾的本质不同的子序列个数,然后 \(f_i=\sum_{j=1}^{k}f_j + 1\),我们发现这个其实是 \(\mathcal O(n)\) 的,然后 \(m==0\) 的测试点就都有了。
之后考虑如何接 \(m\),我们考虑发现每一次进行转移 \(f_i\) 的时候,其实接下来的 \(f_i\) 与 \(i\) 无关,因为本质不同的子序列个数就是 \(\sum f_i\) ,而我们要最大化这个玩意,我们就可以每次选择最小的 \(f_i\) 进行转移。
\(\color{red} {\huge{\text{但是}}}\)
你确定要使用 \(<\) 进行比较吗??
这个可是取过模的啊!!!1
你可不能认为 \(1e9+6>1e9+8\) 啊
所以我们转化一下就是我们每次找到最后出现位置最靠前的那个元素
这个就是用 \(priority\)_\(queue\) 就行。
之后我们考虑矩阵转移,我们要转移那个基础的方程,并且我们要保证这个 \(\sum\) 最大,所以我们就要保证顺序的转移。
我们的基础矩阵就是一个 \(1 * k+1\) 的矩阵
最后的\(1\) 是转移所需。
然后我们构造转移矩阵,我们保证其将基础矩阵的最小值移动到最上面,最后 \(\sum\) 就是答案
那么就是
然后最后的矩阵的 \(\sum\) 就是答案
#include<bits/stdc++.h>
using std::cout; using std::endl;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
#define asm(i,x) for(register signed i=head[x];i;i=edge[i].next)
namespace xin_io
{
#define sb(x) cout<<#x" = "<<x<<' '
#define jb(x) cout<<#x" = "<<x<<endl
#define debug cout<<"debug"<<endl
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1++
char buf[1<<20],*p1 = buf,*p2 = buf; int ak; typedef long long ll; typedef unsigned long long ull;
class xin_stream{public:template<typename type>inline xin_stream &operator >> (type &s)
{
register int f = 0;s = 0; register char ch = gc();
while(!isdigit(ch)) {f |= ch == '-'; ch = gc();}
while( isdigit(ch)) s = (s << 1) + (s << 3) + (ch xor 48),ch = gc(); return s = f ? -s : s,*this;
}}io;
}
using namespace xin_io; static const int maxn = 1e6+10,inf = 1e9+7; const ll llinf = 1e18+7;
#define int long long
namespace xin
{
const int mod = inf;
int f[maxn];
int n,m,k;
int sum = 0;
class xin_mat
{
public:
int a[110][110];
int n,m;
friend xin_mat operator * (xin_mat x,xin_mat y)
{
xin_mat temp;
try(i,1,x.n) try(j,1,y.m)
{
temp.a[i][j] = 0;
try(k,1,x.m) (temp.a[i][j] += x.a[i][k] * y.a[k][j] % mod);
temp.a[i][j] %= mod;
}
temp.n = x.n; temp.m = y.m;
return temp;
}
}mat,my,zhuan;
class xin_data
{
private:
friend bool operator < (xin_data x,xin_data y)
{return x.pos > y.pos;}
public:
int col,pos;
xin_data(){}
xin_data(int col,int pos):col(col),pos(pos){}
};
std::priority_queue<xin_data>q;
bool vis[maxn];
int a[maxn];
inline short main()
{
io >> n >> m >> k;
sum = 0;
try(i,1,n)
{
io >> a[i];
register int temp = f[a[i]];
(f[a[i]] = 1 + sum) %= mod;
(sum += f[a[i]] - temp + mod) %= mod;
}
throw(i,n,1)
if(!vis[a[i]]) q.push(xin_data(a[i],i)),vis[a[i]] = 1;
try(i,1,k)
if(!vis[i]) q.push(xin_data(i,0));
mat.n = k + 1; mat.m = 1;
try(i,1,k) mat.a[i][1] = f[q.top().col],q.pop();
mat.a[k+1][1] = 1;
my.n = my.m = k + 1;
try(i,1,k+1) my.a[i][i+1] = 1;
try(i,1,k+1) my.a[k][i] = 1;
my.a[k+1][k+1] = 1;
zhuan.n = zhuan.m = k + 1;
try(i,1,k+1) zhuan.a[i][i] = 1;
while(m)
{
if(m & 1) zhuan = zhuan * my;
my = my * my; m >>= 1;
}
mat = zhuan * mat;
int ans = 0;
try(i,1,k) (ans += mat.a[i][1]) %= mod;
cout<<ans<<endl;
return 0;
}
}
signed main() {return xin::main();}
Omeed
基础分数就是
然后 \(combo\) 应该是
然后
之后就有很多分数,之后发现可以线段树维护。
之后这个题目卡常严重!!!!
加油
#include<bits/stdc++.h>
using std::endl; using std::cout;
#define try(i,a,b) for(register signed i=a;i<=b;++i)
#define throw(i,a,b) for(register signed i=a;i>=b;--i)
#define asm(i,x) for(register signed i=head[x];i;i=edge[i].next)
namespace xin_io
{
#define debug cout<<"debug"<<endl
#define sb(x) cout<<#x" = "<<x<<' '
#define jb(x) cout<<#x" = "<<x<<endl
#define gc() p1 == p2 and (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin),p1 == p2) ? EOF : *p1 ++
char buf[1<<20],*p1 = buf,*p2 = buf; typedef long long ll; typedef unsigned long long ull;
class xin_stream{public:template<typename type>xin_stream &operator >> (type &s)
{
register bool f = 0; s = 0; register char ch = gc();
while(!isdigit(ch)) f |= ch == '-',ch = gc();
while( isdigit(ch)) s = (s << 1) + (s << 3) + (ch xor 48),ch = gc(); return s = f ? -s : s,*this;
}}io;
}
using namespace xin_io; static const int maxn = 1e7+10,mod = 998244353;
#define int long long
namespace xin
{
inline int ksm(int x,int y)
{
register int ret = 1 ;
while(y)
{
if(y & 1) ret = ret * x % mod;
x = x * x % mod; y >>= 1;
}
return ret;
}
int n,bian,q,ta,tb,A,B,t;
int p[maxn];
class xin_seg
{
private:
#define ls (x << 1)
#define rs (x << 1 | 1)
inline void up(int x)
{
shit1[x] = (shit1[ls] + shit1[rs]) % mod;
shit2[x] = (shit2[ls] + shit2[rs] * fk[ls] % mod) % mod;
fk[x] = fk[ls] * fk[rs] % mod;
shit4[x] = (shit4[rs] + shit4[ls] * fk[rs] % mod) % mod;
sum[x] = (sum[rs] + sum[ls] + shit4[ls] * shit2[rs] % mod) % mod;
}
public:
int shit1[maxn],shit4[maxn],fk[maxn],sum[maxn],siz[maxn],shit2[maxn];
class xin_data
{
public:
int rshit1,rfr,rsu;
xin_data(){}
xin_data(int rshit1,int rfr,int rsu):rshit1(rshit1),rfr(rfr),rsu(rsu){}
}data;
void build(int x,int l,int r)
{
if(l == r) {shit1[x] = shit4[x] = p[l]; fk[x] = (t - (t - 1) * p[l] % mod+ mod) % mod;
sum[x] = 0; shit2[x] = shit1[x] ;return ;}
register int mid = l + r >> 1; build(ls,l,mid); build(rs,mid+1,r); up(x);
}
void insert(int x,int l,int r,int pos,int val)
{
siz[x] = r - l + 1;
if(l == r) {shit1[x] = shit4[x] = val; fk[x ]= (t - (t - 1) * val % mod + mod) % mod;
sum[x] = 0; shit2[x] =shit1[x]; return;}
register int mid = l + r >> 1;
if(pos <= mid) insert(ls,l,mid,pos,val); else insert(rs,mid+1,r,pos,val); up(x);
}
void query(int x,int l,int r,int ql,int qr)
{
if(ql <= l and qr >= r)
{
data.rshit1 = (data.rshit1 + shit1[x]) % mod;
data.rsu = (data.rsu + sum[x] + data.rfr * shit2[x] % mod) % mod;
data.rfr = (data.rfr * fk[x] + shit4[x]) % mod; return ;
}
register int mid = l + r >> 1;
if(ql <= mid) query(ls,l,mid,ql,qr); if(qr > mid) query(rs,mid+1,r,ql,qr);
}
}seg;
inline short main()
{
io >> bian >> n >> q >> ta >> tb >> A >> B;
t = ta * ksm(tb,mod-2) % mod;
try(i,1,n)
{
register int wa,wb; io >> wa >> wb;
p[i] = wa * ksm(wb,mod - 2) % mod;
}
seg.build(1,1,n);
try(cse,1,q)
{
register int op; io >> op;
if(op)
{
register int l,r; io >> l >> r;
seg.data = xin_seg::xin_data(0,0,0);
seg.query(1,1,n,l,r);
printf("%lld\n",(seg.data.rshit1 * A % mod + (seg.data.rsu + seg.data.rshit1) * B % mod) % mod);
}
else
{
register int x, wa,wb; io >> x >> wa >> wb;
p[x] = wa * ksm(wb,mod-2) % mod;
seg.insert(1,1,n,x,p[x]);
}
}
return 0;
}
}
signed main() {return xin::main();}