0
点赞
收藏
分享

微信扫一扫

UESTC 1269 ZhangYu Speech


Description


as we all know, ZhangYu(Octopus vulgaris) brother has a very famous speech - “Keep some distance from me”. 

ZhangYu brother is so rich that everyone want to contact he, and scfkcf is one of them. 

One day , ZhangYu brother agreed with scfkcf to contact him if scfkcf could beat him. 

There are 

 digits(lets give them indices from 

 to 

 and name them 

) and some queries.

for each query:

  1. ZhangYu brother choose an index  from  to .
  2. For all indices  (  < ) calculate the difference .
  3. Then ZhangYu brother calculate  ,the sum of all by which are greater than  , and scfkcf calculate  , the sum of all by which are less than .

if 

 , ZhangYu brother won and did not agree with scfkcf to contact him; 

else if 

 is equals to 

 , ZhangYu brother would ignore the result; 

else if 

 < 


Input

The first line contains two integers 


 

 denoting the number of digits and number of queries. The second line contains 

 digits (without spaces) 

.

 

Each of next 

 lines contains single integer 

 


Output

For each of 

 queries print “Keep some distance from me” if ZhangYu won, else print “Next time” if ZhangYu brother ignored the result, else print “I agree” if ZhangYu brother lost in a line - answer of the query.

Sample Input


10 3 
0324152397 


7


Sample Output


Next time 
Keep some distance from me 
I agree


Hint


It's better to use “scanf” instead of “cin” in your code.


没什么好说的,直接预处理一下每种数字的前缀和就好了。

#include<iostream>  
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;
int T, n, m, f[maxn][10], x, b1, b2;
char s[maxn];


int main(){
//scanf("%d", &T);
while (~scanf("%d%d", &n, &m))
{
memset(f[0], 0, sizeof(f[0]));
scanf("%s", s + 1);
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < 10; j++) f[i][j] = f[i - 1][j];
f[i][s[i] - '0']++;
}
while (m--)
{
scanf("%d", &x);
b1 = 0; b2 = 0;
for (int i = 0; i < s[x] - '0'; i++) b1 += f[x][i] * (s[x] - '0' - i);
for (int i = s[x] - '0' + 1; i < 10; i++) b2 += f[x][i] * (i - s[x] + '0');
if (b1 > b2) printf("Keep some distance from me\n");
if (b1==b2) printf("Next time\n");
if (b1 < b2) printf("I agree\n");
}
}
return 0;
}



举报

相关推荐

0 条评论