日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BZOJ4810:[YNOI2017]由乃的玉米田(莫队,bitset)

發(fā)布時間:2025/3/17 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BZOJ4810:[YNOI2017]由乃的玉米田(莫队,bitset) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Description

由乃在自己的農(nóng)田邊散步,她突然發(fā)現(xiàn)田里的一排玉米非常的不美。這排玉米一共有N株,它們的高度參差不齊。 由乃認為玉米田不美,所以她決定出個數(shù)據(jù)結(jié)構(gòu)題 這個題是這樣的: 給你一個序列a,長度為n,有m次操作,每次詢問一個區(qū)間是否可以選出兩個數(shù)它們的差為x,或者詢問一個區(qū)間是 否可以選出兩個數(shù)它們的和為x,或者詢問一個區(qū)間是否可以選出兩個數(shù)它們的乘積為x ,這三個操作分別為操作1 ,2,3選出的這兩個數(shù)可以是同一個位置的數(shù)

Input

第一行兩個數(shù)n,m 后面一行n個數(shù)表示ai 后面m行每行四個數(shù)opt l r x opt表示這個是第幾種操作,l,r表示操作的區(qū)間,x表示這次操作的x 定義c為每次的x和ai中的最大值,ai >= 0,每次的x>=2n,m,c <= 100000

Output

對于每個詢問,如果可以,輸出yuno,否則輸出yumi

Sample Input

5 5
1 1 2 3 4
2 1 1 2
1 1 2 2
3 1 1 1
3 5 5 16
1 2 3 4

Sample Output

yuno
yumi
yuno
yuno
yumi

Solution

先莫個隊,然后對值域開個$bitset$。

差相等就是$f$并上$f$右移$x$不為$0$。

和相等就是$f$并上翻轉(zhuǎn)的$f$右移$N-x$位不為$0$。

積的話就$sqrt$枚舉$x$的的因子然后查詢存在性就好了。

Code

1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<bitset> 5 #include<cmath> 6 #include<algorithm> 7 #define N (100000) 8 using namespace std; 9 10 struct Que{int opt,l,r,x,id;}Q[N+1]; 11 int n,m,unit,opt,l,r,x,a[N+1],ID[N+1]; 12 int ans[N+9],Keg[N+9]; 13 bitset<N+1>f,g; 14 15 inline int read() 16 { 17 int x=0,w=1; char c=getchar(); 18 while (!isdigit(c)) {if (c=='-') w=-1; c=getchar();} 19 while (isdigit(c)) x=x*10+c-'0', c=getchar(); 20 return x*w; 21 22 } 23 24 void Ins(int p) 25 { 26 if (!Keg[a[p]]) f[a[p]]=1, g[N-a[p]]=1; 27 ++Keg[a[p]]; 28 } 29 30 void Del(int p) 31 { 32 --Keg[a[p]]; 33 if (!Keg[a[p]]) f[a[p]]=0, g[N-a[p]]=0; 34 } 35 36 bool check(int opt,int x) 37 { 38 if (opt==1) return (f&(f>>x)).any(); 39 if (opt==2) return (f&(g>>(N-x))).any(); 40 if (opt==3) 41 { 42 for (int i=1; i<=sqrt(x); ++i) 43 if (x%i==0 && f[i] && f[x/i]) return 1; 44 return 0; 45 } 46 } 47 48 bool cmp(Que a,Que b) 49 { 50 if (ID[a.l]==ID[b.l]) return a.r<b.r; 51 return ID[a.l]<ID[b.l]; 52 } 53 54 int main() 55 { 56 n=read(); m=read(); unit=sqrt(n); 57 for (int i=1; i<=n; ++i) ID[i]=i/unit; 58 for (int i=1; i<=n; ++i) a[i]=read(); 59 for (int i=1; i<=m; ++i) 60 { 61 opt=read(); l=read(); r=read(); x=read(); 62 Q[i]=(Que){opt,l,r,x,i}; 63 } 64 sort(Q+1,Q+m+1,cmp); 65 int l=1,r=0; 66 for (int i=1; i<=m; ++i) 67 { 68 while (l<Q[i].l) Del(l++); 69 while (l>Q[i].l) Ins(--l); 70 while (r<Q[i].r) Ins(++r); 71 while (r>Q[i].r) Del(r--); 72 ans[Q[i].id]=check(Q[i].opt,Q[i].x); 73 } 74 for (int i=1; i<=m; ++i) puts(ans[i]?"yuno":"yumi"); 75 }

轉(zhuǎn)載于:https://www.cnblogs.com/refun/p/10453209.html

新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎!定制產(chǎn)品紅包拿不停!

總結(jié)

以上是生活随笔為你收集整理的BZOJ4810:[YNOI2017]由乃的玉米田(莫队,bitset)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。