社区讨论
疑问
CF940FMachine Learning参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lobknote
- 此快照首次捕获于
- 2023/10/29 22:34 2 年前
- 此快照最后确认于
- 2023/11/02 10:45 2 年前
为什么在结构体内部重载小于号会比写cmp快啊,写cmp超时了,但是在结构体内部重载小于号就可以过。
代码:
CPP代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 2e5+10;
int size;
struct qqq{
int l,r,t,idx;
bool operator<(qqq& y)
{
return l/size==y.l/size?(r/size==y.r/size?t<y.t:r<y.r):l<y.l;
}
}q[N];
struct ccc{
int pos,val;
}c[N];
int a[N],b[N],s[N],bl[N];
int cnt1[N],cnt2[N],ans[N];
int l,r,now; //左右端点指针、时间指针
int n,m;
inline int read()
{
char ch=getchar();bool f=0;int x=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
if(f==1)x=-x;return x;
}
void add(int x)
{
--cnt2[cnt1[x]];
++cnt2[++cnt1[x]];
}
void del(int x)
{
--cnt2[cnt1[x]];
++cnt2[--cnt1[x]];
}
void change(int x,int i)
{
if(q[i].l<=c[x].pos && c[x].pos<=q[i].r)
{
del(a[c[x].pos]) , add(c[x].val);
}
swap(c[x].val,a[c[x].pos]);
}
bool cmp(qqq A,qqq B)
{
return A.l/size==B.l/size?(A.r==B.r?A.t<B.t:A.r<B.r):A.l<B.l;
}
void get_ans(int &x)
{
for(ans[x]=1; cnt2[ans[x]]>0; ++ans[x]);
}
int main()
{
n = read() ; m = read();
size = pow(n,0.67); //块的大小
for(int i=1; i<=n; i++)
{
a[i]= read() ; s[i] = a[i] ;
}
int op , qt = 0 , ct = 0 ;
for(int i=1; i<=m; i++)
{
op= read() ; l= read() ; r = read() ;
if(op==1) //询问
++qt , q[qt].l = l , q[qt].r = r , q[qt].t = ct , q[qt].idx = qt;
else //修改
++ct , c[ct].pos = l , c[ct].val = r , s[n+ct] = r;
}
//离散化的板子
sort(s+1,s+n+ct+1);
int sum=unique(s+1,s+n+ct+1)-s-1;
for(int i=1; i<=n; i++)
a[i]=lower_bound(s+1,s+sum+1,a[i])-s;
for(int i=1; i<=ct; i++)
c[i].val=lower_bound(s+1,s+sum+1,c[i].val)-s;
//询问排序
sort(q+1,q+qt+1);
l = 1 , r = 0 , now = 0;
for(int i=1; i<=qt; i++)
{
int ql = q[i].l , qr = q[i].r , qt = q[i].t;
while(ql > l) del(a[l++]);
while(ql < l) add(a[--l]);
while(qr > r) add(a[++r]);
while(qr < r) del(a[r--]);
while(qt > now) change(++now,i);
while(qt < now) change(now--,i);
get_ans(q[i].idx);
}
for(int i=1; i<=qt; i++)
cout<<ans[i]<<"\n";
return 0;
}
/*
10 3
1 2 3 1 1 2 2 2 9 9
1 2 8
2 7 1
1 2 8
*/
回复
共 0 条回复,欢迎继续交流。
正在加载回复...