-
“麻雀”lengdan用随机数生成了后台数据,但是笨笨的他被妹纸的问题给难住了。。。
已知lengdan生成了N(1=<N<=10005)个随机整数,妹子对这些数可能有以下几种操作或询问:
1,A a b c 表示给区间a到b内每个数都加上c;
2,S a b 表示输出区间a到b内的和;
3,Q a b 表示区间a到b内的奇数的个数;
为了使妹纸不口渴,所以我们决定妹纸的询问次数少一点,即(1=<M<=10000,M为询问次数)。
唉,你说妹纸一直进行操作1该多好啊,嘎嘎。。。

- 输入
- 多组测试数据。
每组测试数据第一行包含两个数N,M,表示N个整数,执行M次询问或操作。
紧接着一行输入N个整数,输入数据保证在int范围内。
接下来M行,每行输入一种操作。 - 输出
- 每次对于操作2和3,输出结果。
- 样例输入
-
5 5 1 2 3 4 5 Q 1 4 S 1 5 A 1 4 1 S 1 5 Q 2 5
- 样例输出
-
2 15 19 3
public class Main {
static String data;
public static int jud(String data1,String cz){
String[] s = data1.split(" ");
String[] c = cz.split(" ");
int res = 0;
if (c.length==4) {
for (int i = Integer.parseInt(c[1])-1; i <= Integer.parseInt(c[2])-1; i++) {
s[i] = (Integer.parseInt(s[i])+Integer.parseInt(c[3]))+"";
}
data = Integer.parseInt(s[0])+" ";
for (int i = 1; i < s.length; i++) {
data = data+Integer.parseInt(s[i])+" ";
}
res=-1;
}
else{
if (c[0].equals("Q")) {
int num=0;
for (int i = Integer.parseInt(c[1])-1; i <= Integer.parseInt(c[2])-1; i++) {
if (Integer.parseInt(s[i])%2==1) {
num++;
}
}
res=num;
}
if (c[0].equals("S")){
int num=0;
for (int i = Integer.parseInt(c[1])-1; i <= Integer.parseInt(c[2])-1; i++) {
num+=Integer.parseInt(s[i]);
}
res=num;
}
}
return res;
}
public static void main(String[] args) throws Exception {
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
int m;
String al = buf.readLine();
String[] s = al.split(" ");
m = Integer.parseInt(s[1]);
data = buf.readLine();
String r = "";
for (int i = 0; i < m; i++) {
if (i==0) {
r = jud(data,buf.readLine())+"";
}
else {
r = r+"@"+jud(data,buf.readLine());
}
}
String[] sc = r.split("@");
for (int i = 0; i < sc.length; i++) {
if (!sc[i].equals("-1")) {
System.out.println(sc[i]);
}
}
}
}