11.【2024初三集训模拟测试3】
\(\Huge打了一场模拟赛,又垫底了。qwq\)
2024初三集训模拟测试3
\(\Huge还是垫底赛大佬。qwq\)
T1排序
\(100pts\)
题解 \(\Huge 🈚\)
代码 \(\Huge 🈶\)
#include<bits/stdc++.h>
#define int long long
#define N (1000010)
#define I i
#define J j
#define raed read
#define reaD read
#define reAD read
#define rEAD read
#define READ read
#define REAd read
#define REad read
#define Read read
#define Reda read
#define redA read
#define reDA read
#define redA read
#define itn signed
#define Itn signed
#define ITN signed
#define Int signed
#define INT signed
#define foR for
#define fot for
#define foT for
#define sort stable_sort
using namespace std;
namespace IO
{
#define ll long long
const int MAX=1<<24;
char buf[MAX],*p1=buf,*p2=buf;
char obuf[MAX],*o=obuf;
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<24,stdin),p1==p2)?EOF:*p1++)
//template<typename T>
//inline T read()
inline int read()
{
int x=0;bool f=1;
char c=gc();
for(;c<48||c>57;c=gc())if(c=='-')f=0;
for(;c>=48&&c<=57;c=gc())x=(x<<3)+(x<<1)+(c^48);
return f?x:~x+1;
}
void print(ll x){if(x>9)print(x/10);*o++=(x%10)+'0';}
void pit(ll x){if(x<0)*o++='-',x=~x+1;print(x);}
void write(ll x,char ed){pit(x);*o++=ed;}
void flush(){fwrite(obuf,o-obuf,1,stdout);}
#undef ll
}
using IO::read;using IO::write;using IO::flush;using std::complex;
inline int min(int x,int y){return y&((y-x)>>31)|x&(~(y-x)>>31);}
inline int max(int x,int y){return x&((y-x)>>31)|y&(~(y-x)>>31);}
inline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
long long n,m;
void init_set()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
}
int tot,t;
bool honkai_star_rail[20];
int furina[10010],fucaros[1000010];
int fontaine[1000010];
int panzer;
signed main()
{
init_set();
n=read();
for(int i(1);i<=(n<<2);++i)fontaine[i]=read();
sort(fontaine+1,fontaine+1+(n<<2));
for(int i(1);i<=n;++i)
tot+=fontaine[(n<<2)-(i<<1)+2]*fontaine[(n<<2)-(i<<1)+1],
tot-=fontaine[i]*fontaine[(n<<1)-i+1];
write(tot,' ');
flush();
return 0;
}
T2牛吃草
\(0pts\)
题解 \(\Huge 🈚\)
代码 \(\Huge 🈚\)
T3树上的宝藏
\(0pts\)
题解 \(\Huge 🈚\)
代码 \(\Huge 🈚\)
T4MEX
\(0pts\)
题解 \(\Huge 🈚\)
代码 \(\Huge 🈶\)
#include<bits/stdc++.h>
#define int long long
#define N (1000010)
#define ls (p<<1)
#define rs (p<<1|1)
#define I i
#define J j
#define raed read
#define reaD read
#define reAD read
#define rEAD read
#define READ read
#define REAd read
#define REad read
#define Read read
#define Reda read
#define redA read
#define reDA read
#define redA read
#define itn signed
#define Itn signed
#define ITN signed
#define Int signed
#define INT signed
#define foR for
#define fot for
#define foT for
#define sort stable_sort
using namespace std;
namespace IO
{
#define ll long long
const int MAX=1<<24;
char buf[MAX],*p1=buf,*p2=buf;
char obuf[MAX],*o=obuf;
#define gc()(p1==p2&&(p2=(p1=buf)\
+fread(buf,1,1<<24,stdin),p1==p2)?EOF:*p1++)
//template<typename T>
//inline T read()
inline int read()
{
int x=0;bool f=1;
char c=gc();
for(;c<48||c>57;c=gc())if(c=='-')f=0;
for(;c>=48&&c<=57;c=gc())x=(x<<3)+(x<<1)+(c^48);
return f?x:~x+1;
}
void print(ll x){if(x>9)print(x/10);*o++=(x%10)+'0';}
void pit(ll x){if(x<0)*o++='-',x=~x+1;print(x);}
void write(ll x,char ed){pit(x);*o++=ed;}
void flush(){fwrite(obuf,o-obuf,1,stdout);}
#undef ll
}
using IO::read;using IO::write;using IO::flush;using std::complex;
inline int min(int x,int y){return y&((y-x)>>31)|x&(~(y-x)>>31);}
inline int max(int x,int y){return x&((y-x)>>31)|y&(~(y-x)>>31);}
inline void swap(int &x,int &y){x^=y^=x^=y;}
long long n,m;
void init_set()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
}
int tot,x,y;
struct aa
{
int nahida,sumeru,panzer;//min num sum
//min 最小值, num 记录区间和, sum 记录历史和
struct lazytag
{
int furina,Paimon,fucaros;//cover time add
//cover -1 不覆盖, time 乘法懒标记,记录历史被求和过多少次, add 加法懒标记
//构造函数,初始化
inline lazytag()
{furina=-1,Paimon=fucaros=0;}
//赋值
inline lazytag(int furina):furina(furina)
{if(furina==-1)Paimon=1;}
}tag;
}t[4000010];
bool tp2=true;
int disco;
int fontaine[1000010];//a
int honkai_star_rail;//last_0
int kamisato_ayaka;//answer_0
int Cyberpunk_2077[1000010];//next
int Soviet[1000010];//last
int honkai[1000010];
inline void pushup(int p)
{
t[p].nahida=min(t[ls].nahida,t[rs].nahida);
t[p].sumeru=t[ls].sumeru,t[rs].sumeru;
t[p].panzer=t[ls].panzer,t[rs].panzer;
}
void build(int p=1,int l=0,int r=m)
{
if(l==r){t[p].sumeru=t[p].nahida=Soviet[l];return;}
int mid(l+r>>1);
build(ls,l,mid),build(rs,mid+1,r);
pushup(p);
}
inline void down(aa::lazytag tag,int p,int l,int r)
{
t[p].panzer+=t[p].sumeru*tag.Paimon+tag.fucaros;
//sum=sum+num*time+add
if(~tag.furina)
{
if(~t[p].tag.furina)//下传 add
t[p].tag.fucaros+=t[p].tag.furina*tag.Paimon+tag.fucaros;
else
t[p].tag.Paimon+=tag.Paimon,//下传 time
t[p].tag.fucaros+=tag.fucaros;//下传 add
t[p].sumeru=t[p].nahida=tag.furina;
t[p].tag.furina=tag.furina;//下传 cover
}
else
{
//下传 add
if(~t[p].tag.furina)t[p].tag.fucaros+=t[p].tag.furina*tag.Paimon;
//下传 time
else t[p].tag.Paimon+=tag.Paimon;
}
}
inline void pushdown(int p,int l,int r)
{
int mid(l+r>>1);
down(t[p].tag,ls,l,mid),down(t[p].tag,rs,mid+1,r);
t[p].tag=aa::lazytag();
}
void update(int p,int ql,int qr,int l,int r,int v)
{
if(qr<l||r<ql)return;
if(ql<=l&&r<=qr)
{down(aa::lazytag(v),p,l,r);return;}
pushdown(p,l,r);
int mid(l+r>>1);
update(ls,ql,qr,l,mid,v),update(rs,ql,qr,mid+1,r,v);
pushup(p);
}
inline void PaimonDown()
{down(aa::lazytag(-1),1,1,m);}
int search(int p,int ql,int qr,int l,int r,int v)
{
if(qr<l||r<ql||v<=t[p].nahida)return -1;
//越界或比该最小值还要小。
if(l==r&&ql<=l&&r<=qr)return l;
int mid(l+r>>1);
int res(search(rs,ql,qr,mid+1,r,v));
return ~res?res:search(ls,ql,qr,l,mid,v);
}
void SetAns(int p=1,int l=0,int r=m)
{
if(l==r){honkai[l]=t[p].panzer;return;}
int mid(l+r>>1);
pushdown(p,l,r),SetAns(ls,l,mid),SetAns(rs,mid+1,r);
}
signed main()
{
init_set();
n=read();m=read();
for(signed i(1);i<=n;++i)
{
fontaine[i]=read();
if(!fontaine[i])
{
kamisato_ayaka+=(i-honkai_star_rail-1)*(i-honkai_star_rail)>>1;//对 0 进行特判。
honkai_star_rail=i;
}
if(fontaine[i]!=i%m)tp2=false;
}
if(tp2)//10pts 特判所有元素都为 i%m 的情况
{
x=read(),y=read();
disco=n*(n+1)>>1;
for(int i(x);i<=y;++i)
{
if(i==0)write(((n/m)*((m-1)*m)>>1)+(((n%m))*(n%m+1)>>1),' '),
disco-=((n/m)*((m-1)*m)>>1)+(((n%m))*(n%m+1)>>1);
else if(i==m)
write(disco,' ');
else write(((n-i+1)/m)*(m-i),' '),disco-=((n-i+1)/m)*(m-i);
}
flush();exit(0);
}
kamisato_ayaka+=(n-honkai_star_rail)*(n+1-honkai_star_rail)>>1;
for(int i(0);i<=m;++i)
Soviet[i]=n+1;//last 数组初始化。
for(int i(n);i;--i)
Cyberpunk_2077[i]=Soviet[fontaine[i]],
//next 数组存下一个 i 的位置 ,由于倒序,所以是下一个。
Soviet[fontaine[i]]=i;//之后让 last 数组记录上一个。
//未出现过 i ,last=next=n+1 。
//只出现一次,last 为第一次出现位置, nxt=n+1
//出现两次以上 , last 同上, nxt 为第二次出现位置。
for(int i(1);i<m;++i)
Soviet[i]=max(Soviet[i],Soviet[i-1]);
//无论如何, mex 为 i 时,区间内至少也要有 1 至 i-1 。
build(1,0,m);
for(int i(1);i<=n;++i)
{
PaimonDown();
int browser(search(1,fontaine[i],m,0,m,Cyberpunk_2077[i]));
//二分查找在 a[i] 与 m 之间的最大的数位置。
if(~browser)update(1,fontaine[i],browser,0,m,Cyberpunk_2077[i]);
}
SetAns(1,0,m);
x=read(),y=read();
if(!x)write(kamisato_ayaka,' '),x=1;
for(int i(x);i<=y;++i)
write(honkai[i]-honkai[i-1],' ');
flush();
return 0;
}