Codeforces Round #136 (Div. 2)D(codeforces221d) 暴力!!!!
2016-05-13 22:28
204 查看
题目链接:点这里!!!!
题意:
给你一个长度为n(n<=1e5)的序列,a1,a2,a3,...an(1<=ai<=1e9)。
再给你m(m<=1e5)个询问,每个询问里[l,r]问你al...ar这个区间。假设x在这个区间里刚好出现x次,问你这个区间里有多少个这样的x。
题解:
我们猜下这样的x最多有多少个。1+2+3+...v<=1e5,v的最大值为460。我们可以知道最多有460个这样的x。然后我们直接处理可能满足条件的x。然后直接暴力就可以了。
时间复杂度O(n*460)。
题解:
题意:
给你一个长度为n(n<=1e5)的序列,a1,a2,a3,...an(1<=ai<=1e9)。
再给你m(m<=1e5)个询问,每个询问里[l,r]问你al...ar这个区间。假设x在这个区间里刚好出现x次,问你这个区间里有多少个这样的x。
题解:
我们猜下这样的x最多有多少个。1+2+3+...v<=1e5,v的最大值为460。我们可以知道最多有460个这样的x。然后我们直接处理可能满足条件的x。然后直接暴力就可以了。
时间复杂度O(n*460)。
题解:
#include<cstdio> #include<cstring> #include<iostream> #include<sstream> #include<algorithm> #include<vector> #include<bitset> #include<set> #include<queue> #include<stack> #include<map> #include<cstdlib> #include<cmath> #define PI 2*asin(1.0) #define LL long long #define pb push_back #define pa pair<int,int> #define clr(a,b) memset(a,b,sizeof(a)) #define lson lr<<1,l,mid #define rson lr<<1|1,mid+1,r #define bug(x) printf("%d++++++++++++++++++++%d\n",x,x) #define key_value ch[ch[root][1]][0]C:\Program Files\Git\bin const LL MOD = 1000000007; const LL N = 1e5+15; const int maxn = 8e3+15; const int letter = 130; const LL INF = 1e18; const double pi=acos(-1.0); const double eps=1e-10; using namespace std; inline int read() { 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*10+ch-'0';ch=getchar();} return x*f; } int n,m,a ,ps ; int vis ,mark ; vector<int>pp; int dis [500],vv[500]; struct node{ int val,id,now; }va ; int main(){ int cnt=0; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",a+i),ps[++cnt]=a[i]; sort(ps+1,ps+cnt+1); cnt=unique(ps+1,ps+cnt+1)-(ps+1); for(int i=1;i<=n;i++){ va[i].val=a[i]; va[i].id=lower_bound(ps+1,ps+cnt+1,a[i])-ps; } for(int i=1;i<=n;i++){ vis[va[i].id]++; if(vis[va[i].id]==va[i].val) mark[va[i].id]=1; } cnt=0; for(int i=1;i<=n;i++){ if(mark[va[i].id]) ps[++cnt]=va[i].id; } sort(ps+1,ps+cnt+1); cnt=unique(ps+1,ps+cnt+1)-(ps+1); for(int i=1;i<=n;i++){ if(mark[va[i].id]){ va[i].now=lower_bound(ps+1,ps+cnt+1,va[i].id)-ps; vv[va[i].now]=va[i].val; } } for(int i=0;i<=n;i++){ for(int j=1;j<=cnt;j++) dis[i][j]=dis[i-1][j]; if(!mark[va[i].id]) continue; dis[i][va[i].now]++; } for(int i=1;i<=m;i++){ int x,y; scanf("%d%d",&x,&y); int sum=0; for(int i=1;i<=cnt;i++){ if(dis[y][i]-dis[x-1][i]==vv[i]) sum++; } printf("%d\n",sum); } return 0; } /* 13 5 2 2 4 4 4 4 3 5 5 5 5 5 5 1 13 2 5 2 6 7 9 3 8 */
相关文章推荐
- 使用VS2010自定义C++模板
- ViewConfiguration.getScaledTouchSlop () 用法
- 使用并查集判断无向图是否连通
- Error:Flash Download Failed-"Cortex-M3"
- Error:Flash Download Failed-"Cortex-M3"
- 谈情--读《白马啸西风》有感
- HTTP协议规范RFC文档的几个版本更新
- 记录两个很小很小的问题
- HTML入门笔记
- HTML入门笔记
- 常见编程语言对REPL支持情况小结[转]
- 学习篇---自定义ZoomImageView
- django model的get和filter方法的区别
- Python计算不带括号的字符串
- 探秘堆结构
- GIT基本操作命令
- codevs 1378 选课 (树形DP)
- SBT详解
- URLDecoder类API_java.net.URLDecoder
- 记忆中干过的mysql卸载和重装