标签:des style http color java os strong io
A.预处理出来,0(1)输出。
1 5 5 1 2 3 5 6 1 2 3 4 5
4 4 4 4 7
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include <iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include <stack> #include <map> #include <set> #define eps 1e-10 ///#define LL __int64 #define LL long long ///#define INF 0x7ffffff #define INF 0x3f3f3f3f #define PI 3.1415926535898 #define zero(x) ((fabs(x)<eps)?0:x) const int maxn = 201000; using namespace std; int vis[maxn]; int num[maxn]; int main() { int T; cin >>T; while(T--) { int n, m; cin >>n>>m; memset(vis, 0, sizeof(vis)); int x; for(int i = 1; i <= n; i++) { scanf("%d",&x); vis[x] = 1; } int now; for(int i = maxn-1; i >= 1; i--) { if(!vis[i]) { now = i; num[i] = now; continue; } num[i] = now; } while(m--) { scanf("%d",&x); printf("%d\n",num[x]); } } return 0; }
1 1 1 5 3 4 5 3 2 1
1 3HintFor the second case, {3},{5,3,2},{4,5,3,2,1} are Bestcoder Sequence.
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include <iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include <stack> #include <map> #include <set> #define eps 1e-10 #define LL __int64 ///#define LL long long ///#define INF 0x7ffffff #define INF 0x3f3f3f3f #define PI 3.1415926535898 #define zero(x) ((fabs(x)<eps)?0:x) const int maxn = 101000; using namespace std; int num[maxn]; LL sum1[maxn]; LL sum2[maxn]; int main() { int n, m; while(cin >>n>>m) { memset(sum1, 0, sizeof(sum1)); memset(sum2, 0, sizeof(sum2)); int s; for(int i = 1; i <= n; i++) { scanf("%d",&num[i]); if(num[i] == m) s = i; } int cnt = 0; int pp = 40000; sum1[pp] = 1; for(int i = s-1; i >= 1; i--) { if(num[i] > m) cnt++; else if(num[i] < m) cnt--; sum1[cnt+pp]++; } cnt = 0; LL ans = 0; ans += sum1[pp]; for(int i = s+1; i <= n; i++) { if(num[i] > m) cnt++; else if(num[i] < m)cnt--; sum2[cnt+pp]++; ans += sum1[pp-cnt]; } cout<<ans<<endl; } return 0; }
BestCoder Round #3 A,B,布布扣,bubuko.com
标签:des style http color java os strong io
原文地址:http://blog.csdn.net/xu12110501127/article/details/38365127