随笔分类 - interval tree
摘要:比赛的时候感觉是线段树,直接求,超时了。看了题解,才知道是有点规律的,要先固定端点,求出所有以该端点为左端点的区间,然后不断移动左端点,直到求出所有区间。用nxt[i]存储下一个出现a[i]的下标。先求出所有的mex(1,i)再删除a[1],则在区间(2,nxt[1]-1)上mex(2,i)>a[1]的值全部改为a[1],因为mex(2,i)是递增的,所以可以求出第一个大于a[1]的mex(2,i)的下标,然后进行区间更新。以此类推,从左到右删除所有元素,就可以得出答案。 1 #include 2 #include 3 #include 4 #include 5 using name..
阅读全文
摘要:1 #include 2 #include 3 const int maxn=100000+5; 4 int sum[maxn>1;31 if(Lm) update(L,R,inc,m+1,r,rt>1;44 if(lm) ret+=query(L,R,m+1,r,rt<<1|1);46 return ret;47 }48 int n,m;49 int main()50 {51 int t;52 scanf("%d",&t);53 while(t--)54 {55 scanf("%d%d",&n,&m);5
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=100000+5; 6 int num[maxn>1;23 build(l,m,rt>1;35 if(x>1;46 if(Rm) return query(L,R,m+1,r,rt<<1|1);48 int a=query(L,R,l,m,rt<<1);49 int b=query(L,R,m+1,r,rt<<1|1);50 return min(a,b);51 }52 int main()53
阅读全文
摘要:线段树单点更新 因为CASE之间的换行WA了两次 1 #include 2 #include 3 const int maxn=200000+5; 4 int sum[maxn>1;18 build(l,m,rt>1;30 if(x>1;41 int ret=0;42 if(Lm) ret+=query(L,R,m+1,r,rt<<1|1);44 return ret;45 }46 int main()47 {48 int n;49 while(scanf("%d",&n)&&n)50 {51 if(CASE!=1...
阅读全文
摘要:线段树加二分查找 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=50001; 6 const int INF=100000; 7 int sum[maxn>1; 36 build(l,m,rt>1; 46 sum[rt>1; 71 if(Lm) update(L,R,v,m+1,r,rt>1; 87 int ret=0; 88 if(Lm) ret+=query(L,R,m+1,r,rtlen-query(a,n,1,n,1))120...
阅读全文
摘要:好题。 1 #include 2 #include 3 #include 4 using namespace std; 5 int CASE=1; 6 const int maxn=500000+5; 7 typedef long long LL; 8 typedef pair Interval; 9 int qL,qR; 10 LL s[maxn]; 11 Interval max_sub[maxnsum(b)?a:b; 26 } 27 void build(int l,int r,int rt) 28 { 29 if(l==r) 30 { 31 m...
阅读全文
摘要:这道题很狗血啊 赋值的时候那个v是大于等于0来着,主要考察区间赋值和更新,pushdown同时要有两个操作。代码如下: 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn=1000000+5; 6 const int INF=1000000009; 7 int sum[maxn=0) 23 { 24 add[rt>1; 52 build(l,m,rt>1; 68 if(Lm) update(L,R,inc,m+1,r,rt>1; 84 if(Lm...
阅读全文
浙公网安备 33010602011771号