P3901-数列找不同【模拟】
生活随笔
收集整理的這篇文章主要介紹了
P3901-数列找不同【模拟】
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
正題
題目鏈接:https://www.luogu.org/problem/P3901
題目大意
一個序列AAA,每次詢問一個區(qū)間求這個區(qū)間的數(shù)是否各不相同。
解題思路
用lastilast_ilasti?表示前一個與iii相同數(shù)的位置。
然后Lasti=max{lastj}(j<=i)Last_i=max\{last_j\}(j<=i)Lasti?=max{lastj?}(j<=i)表示的時選擇iii為右端點時最左的左端點可以在的位置。
然后用LastrLast_rLastr?判斷即可。
codecodecode
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=1e5+100; int n,m,last[N],Last[N],v[N]; int main() {scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){int x;scanf("%d",&x);last[i]=v[x];v[x]=i;Last[i]=max(Last[i-1],last[i]); }for(int i=1;i<=m;i++){int l,r;scanf("%d%d",&l,&r);if(Last[r]<l) printf("Yes\n");else printf("No\n");} }總結
以上是生活随笔為你收集整理的P3901-数列找不同【模拟】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: P4427-[BJOI2018]求和【L
- 下一篇: 暗黑2野蛮人最强玩法 野蛮人最强玩法推荐