AT_joisc2016_d 雇用計画
题意
有
分析
存在一个
但是存在一个非常简单的
考虑拆贡献,把每个连通块的
注意
点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#include<set>
#include<ctime>
#include<random>
#include<cassert>
#define IOS ios::sync_with_stdio(false)
#define PY puts("Yes")
#define PN puts("No")
#define PW puts("-1")
#define P0 puts("0")
#define P__ puts("")
#define PU puts("--------------------")
#define mp make_pair
#define fi first
#define se second
#define pc putchar
#define pb emplace_back
#define un using namespace
#define popc __builtin_popcountll
#define all(x) x.begin(),x.end()
#define rep(a,b,c) for(int a=(b);a<=(c);++a)
#define per(a,b,c) for(int a=(b);a>=(c);--a)
#define reprange(a,b,c,d) for(int a=(b);a<=(c);a+=(d))
#define perrange(a,b,c,d) for(int a=(b);a>=(c);a-=(d))
#define graph(i,j,k,l) for(int i=k[j];i;i=l[i].nxt)
#define lowbit(x) (x&-x)
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define mem(x,y) memset(x,y,sizeof x)
//#define double long double
//#define int long long
//#define int __int128
using namespace std;
using pii=pair<int,int>;
using i64=long long;
using u64=unsigned long long;
template<typename T>bool greating(T x,T y){return x>y;}
inline int rd(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-48;ch=getchar();}return x*f;
}
template<typename T>
inline void write(T x,char ch='\0'){
if(x<0){x=-x;putchar('-');}
int y=0;char z[40];
while(x||!y){z[y++]=x%10+48;x/=10;}
while(y--)putchar(z[y]);if(ch!='\0')putchar(ch);
}
bool Mbg;
const int maxn=2e5+5,maxm=4e5+5,inf=0x3f3f3f3f;
const long long llinf=0x3f3f3f3f3f3f3f3f;
int n,Q,a[maxn];
int b[maxn<<1],m;
struct BIT{
int c[maxn<<1];
void add(int x,int y){while(x<=m)c[x]+=y,x+=lowbit(x);}
void upd(int l,int r,int x){if(l<=r)add(l,x),add(r+1,-x);}
int qry(int x){int res=0;while(x)res+=c[x],x-=lowbit(x);return res;}
} T;
struct Query{
int op,x,y;
}q[maxn];
void lsh(){
sort(b+1,b+m+1),m=unique(b+1,b+m+1)-(b+1);
rep(i,1,n)a[i]=lower_bound(b+1,b+m+1,a[i])-b;
rep(i,1,Q)q[i].op==1?q[i].x=lower_bound(b+1,b+m+1,q[i].x)-b:q[i].y=lower_bound(b+1,b+m+1,q[i].y)-b;
}
void mdf(int x,int v){
if(x==n+1)return;
T.upd(a[x-1]+1,a[x],v);
}
inline void solve_the_problem(){
n=rd(),Q=rd();
rep(i,1,n)a[i]=rd(),b[++m]=a[i];
rep(i,1,Q)(q[i].op=rd())==1?(q[i].x=rd(),b[++m]=q[i].x):(q[i].x=rd(),q[i].y=rd(),b[++m]=q[i].y);
lsh();
rep(i,1,n)mdf(i,1);
rep(i,1,Q){
if(q[i].op==1){
write(T.qry(q[i].x),10);
}else{
mdf(q[i].x,-1),mdf(q[i].x+1,-1);
a[q[i].x]=q[i].y;
mdf(q[i].x,1),mdf(q[i].x+1,1);
}
}
}
bool Med;
signed main(){
// freopen(".in","r",stdin);freopen(".out","w",stdout);
// fprintf(stderr,"%.3lfMB\n",(&Mbg-&Med)/1048576.0);
int _=1;
while(_--)solve_the_problem();
}
/*
*/
分类:
数据结构 / 线段树,树状数组
, 数据结构
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现