I. Yukino With Subinterval

题目链接:

Problem Descripe

Yukino has an array \(a_1, a_2 \cdots a_n\). As a tsundere girl, Yukino is fond of studying subinterval.

Today, she gives you four integers $l, r, x, y $, and she is looking for how many different subintervals \([L, R]\) are in the interval \([l, r]\)that meet the following restraints:

  1. \(a_L =a_{L+1} =\cdots=a_R\), and for any $ i\in [L,R], x \le a_i \le y$.
  2. The length of such a subinterval should be maximum under the first restraint.

Note that two subintervals \([L_1,R_1] , [L_2,R_2]\) are different if and only if at least one of the following formulas is true:

  1. \(L1 \cancel= L2\)
  2. \(R1 \cancel= R2\)

Yukino, at the same time, likes making tricks. She will choose two integers \(pos,v\), and she will change \(a_{pos}\) to \(v\).

Now, you need to handle the following types of queries:

  • \(1 \ pos \ v\) : change \(a_{pos}\) to $v $
  • \(2\) \(l \ r \ x \ y\): print the number of legal subintervals in the interval \([l, r]\)

Input

The first line of the input contains two integers \(n, m (1 \le n, m \le 2 \times 10^5)\)– the numbers of the array and the numbers of queries respectively.

The second line of the input contains nnn integers \(a_i (1 \le a_i \le n)\).

For the next mmm line, each containing a query in one of the following queries:

  • \(1\) \(pos\) \(v \ (1 \le pos, v \le n)\): change \(a_{pos}\) to \(v\)
  • \(2 \ l \ r \ x \ y (1 \le l \le r \le n) (1 \le x \le y \le n)\): print the number of legal subintervals in the interval \([l,r]\)

Output

For each query of the second type, you should output the number of legal subintervals in the interval \([l, r]\).

样例输入

6 3
3 3 1 5 6 5
2 2 3 4 5
1 3 2
2 1 6 1 5

样例输出

0
4

样例解释

For the first operations, there are \(3\) different subintervals \(([2, 2],[3, 3],[2,3])\)in the interval \([2, 3]\), but none of them meets all the restraints.

For the third operations, the legal subintervals in interval \([1, 6]\) are: \([1, 2], [3, 3], [4, 4], [6, 6]\)

Notes that although subintervals \([1,1]\) and \([2,2]\) also meet the first restraint, we can extend them to subinterval \([1, 2]\). So the length of them is not long enough, which against the second one.

题意

给你一个序列,提供两种操作

  • \(1\) \(pos\) \(v \ (1 \le pos, v \le n)\): 将 \(a_{pos}\) 改为 \(v\)
  • \(2 \ l \ r \ x \ y (1 \le l \le r \le n) (1 \le x \le y \le n)\): 输出\([l,r]\) 中权值\(\in [x,y]\) 的个数。特别注意一段连续相同的数只算一次

题解

树套树\(n\)年前打的,早就忘了,于是直接跳过,其实这就是一道可修改区间第k大模板题吧,如果不会的可以去luogu学习一下。

模板传送门:https://www.luogu.org/problem/P3380

这题唯一要解决的就是怎么处理连续段只算一次的问题了。我是树状数组套线段树,于是如果\(a[i]=a[i-1]\)那么就不处理。

还有几个需要注意的地方

  1. 如果改变了\(a[i]\)的值,记得更改\(a[i-1]\)和\(a[i+1]\)
  2. 对于区间\([l,r]\),记得特判\(a[l]\),可能\(a[l]=a[l-1]\),但是这时也要算

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x7f7f7f7f
#define N 200050
template<typename T>void read(T&x)
{ll k=0; char c=getchar();x=0;while(!isdigit(c)&&c!=EOF)k^=c=='-',c=getchar();if (c==EOF)exit(0);while(isdigit(c))x=x*10+c-'0',c=getchar();x=k?-x:x;
}
void read_char(char &c)
{while(!isalpha(c=getchar())&&c!=EOF);}
int n,m,treeNode;
int a[N],ql[20],qr[20];
struct Tree{int ls,rs,sum;}tr[N*150];
void update(int&x,int p,int tt,int l,int r)
{if (x==0)x=++treeNode;tr[x].sum+=tt;if (l==r)return;int mid=(l+r)>>1;if (p<=mid)update(tr[x].ls,p,tt,l,mid);else update(tr[x].rs,p,tt,mid+1,r);
}
void change(int x,int p,int tt)
{while(x<=n)update(x,p,tt,1,n+1),x+=x&-x;}
void getRt(int l,int r)
{ql[0]=qr[0]=0;while(l)ql[++ql[0]]=l,l-=l&-l;while(r)qr[++qr[0]]=r,r-=r&-r;
}
int getSum()
{int ans=0;for(int i=1;i<=ql[0];i++)ans-=tr[tr[ql[i]].ls].sum;for(int i=1;i<=qr[0];i++)ans+=tr[tr[qr[i]].ls].sum;return ans;
}
void move_L()
{for(int i=1;i<=ql[0];i++)ql[i]=tr[ql[i]].ls;for(int i=1;i<=qr[0];i++)qr[i]=tr[qr[i]].ls;
}
void move_R()
{for(int i=1;i<=ql[0];i++)ql[i]=tr[ql[i]].rs;for(int i=1;i<=qr[0];i++)qr[i]=tr[qr[i]].rs;
}
int _Rank(int p,int l,int r)
{if (l==r)return 0;int mid=(l+r)>>1,tp=getSum();if (p<mid){move_L();return _Rank(p,l,mid);}move_R(); return tp+_Rank(p,mid+1,r);
}
int Rank(int l,int r,int k)
{getRt(l-1,r);return _Rank(k-1,1,n+1);
}
void work()
{int id,pos,v,l,r,x,y;read(n); read(m);treeNode=n;for(int i=1;i<=n;i++)read(a[i]);for(int i=1;i<=n;i++)if (a[i]!=a[i-1])change(i,a[i],1);for(int i=1;i<=m;i++){read(id);if (id==1){read(pos); read(v);if (a[pos]!=a[pos-1])change(pos,a[pos],-1);if (v!=a[pos-1])change(pos,v,1);if (a[pos]==a[pos+1])change(pos+1,a[pos+1],1);if (v==a[pos+1])change(pos+1,a[pos+1],-1);a[pos]=v;}if (id==2){read(l); read(r); read(x); read(y);int ans=-Rank(l,r,x)+Rank(l,r,y+1);if (a[l]==a[l-1]&&x<=a[l]&&a[l]<=y)ans++;printf("%d\n",ans);}}
}
int main()
{
#ifndef ONLINE_JUDGEfreopen("aa.in","r",stdin);
#endifwork();
}

转载于:https://www.cnblogs.com/mmmqqdd/p/11508864.html

2019南昌网络赛  I. Yukino With Subinterval 树状数组套线段树相关推荐

  1. 2019ICPC南昌网络赛 - I. Yukino With Subinterval

    题意: 给定一个长为 n 的数组,定义值相同的区间为一子段,有 m 个操作,①:1,pos,v,修改 pos 上的值为 v:②:2,l,r,x,y,询问区间 [ l, r ] 的值域在 [ x, y ...

  2. 2019南昌网络赛 C题,Hello 2019

    题意:求包含9012,但是不包含8012的最小删除次数 解题思路:首先将字符串反转,按照题解思路为线段树维护矩阵即可 我们将线段树的每个区间用矩阵表示,矩阵mat[5][5]维护2019这个序列的情况 ...

  3. 2019南昌网络赛 Yukino With Subinterval —— 树套树 或 cbq分治

    题目链接:点我啊╭(╯^╰)╮ 评测机好像换了,没有当初那么卡了... 最快写法: #include<bits/stdc++.h> #define rint register int #d ...

  4. 2019 南昌网络赛D FFT多个多项式相乘

    2019 Asia Nanchang D. Interesting Series 链接:https://nanti.jisuanke.com/t/41351 题意:首先题目给了若干定义 定义:Fn=( ...

  5. 2019南昌网络赛-I(单调栈+线段树)

    题目链接:https://nanti.jisuanke.com/t/38228 题意:定义一段区间的值为该区间的和×该区间的最小值,求给定数组的最大的区间值. 思路:比赛时还不会线段树,和队友在这题上 ...

  6. 2019南昌网络赛G. tsy‘s number(反演 + 积性函数O(n)预处理)

    tsy's number 推式子 ∑i=1n∑j=1n∑k=1nϕ(i)ϕ(j2)ϕ(k3)ϕ(i)ϕ(j)ϕ(k)ϕ(gcd(i,j,k))我们假定j=p1k1p2k2p3p3--pnkn,有ϕ(j ...

  7. 2019南昌网络赛 H. The Nth Item(广义斐波那契数列求通项公式模板)(二次剩余+分块)

    链接:https://nanti.jisuanke.com/t/41355 题意: Q个询问,每次求F(N),但是N要用上一次询问的结果得到. 思路: 1.直接矩阵快速幂求,再用map记一下答案,求过 ...

  8. 2019年ACM-ICPC - 南昌网络赛I:Yukino With Subinterval【带修主席树】

    题目: 2019ICPC南昌网络赛I:Yukino With Subinterval 题意: 给定长度为 N 的数组,有两种操作:(1)单点修改,(2)查询区间[qL,qR]内有多少个不同的段(连续相 ...

  9. 2019 ICPC 南昌网络赛 H. The Nth Item

    2019 ICPC 南昌网络赛 H. The Nth Item 题目大意:已知一个数列F(n): F(0)=0,F(1)=1 F(n)=3∗F(n−1)+2∗F(n−2),(n≥2) ​ 给你一个操作 ...

最新文章

  1. 单例模式Java实现
  2. flask-blueprint的简单使用
  3. 成功解决pywintypes.com_error: (-2147352573, ‘找不到成员。‘, None, None)
  4. Python学习笔记:web开发3
  5. C#操作项目配置文件
  6. window server2008 r2
  7. java中遍历collection_使用Java中的Iterator遍历Collection
  8. golang debug 配置_新鲜出炉的golang日志库
  9. Python迷宫游戏(基础版)
  10. .NET Core 获取 Request/Headers 等信息
  11. SQLSERVER dbo 解释
  12. 最新免费ip代理分享
  13. Leveraging Long-Range Temporal Relationships Between Proposals for Video Object Detection论文详读
  14. 弹性盒子flex布局实现骰子六个面并让骰子3D空间旋转
  15. 程序员期望月薪那些事儿
  16. 学临床专业和计算机哪个好,大学里“炙手可热”的专业,未来10年也不会被淘汰,发展前景更好...
  17. Axure RP8 下载、安装、破解、汉化一条龙服务
  18. STM32 DSP库
  19. JWT简介、JWT优缺点、JWT使用方法、.NET6使用JWT示例、JWT与Session对比
  20. NeurIPS 2022 | MoVQ: 基于Modulating Quantized Vectors的高保真图像生成

热门文章

  1. 【Python 必会技巧】获取字典中(多个)最大值(value)的键(key)
  2. PWN-PRACTICE-BUUCTF-22
  3. 突然吐字不清_要注意说话吐字不清小心是脑中风前兆
  4. node输出mysql的数据_node.js+async+mysql 查询数据输出问题,如何分别统计、提取每个sql语句的结果!!...
  5. CCNP-第十五篇-VXLAN(一)
  6. 【LeetCode - 32】最长有效括号
  7. 【NC54 三数之和】(待整理)
  8. 【HihoCoder - 1881】特殊任务 (树形图,遍历)
  9. 【HDU - 2553】N皇后问题 (dfs经典问题,回溯,搜索)
  10. 使用特征_R语言-使用caret包实现特征选择:递归特征消除(RFE)算法