“麻雀”lengdan用随机数生成了后台数据,但是笨笨的他被妹纸的问题给难住了。。。
已知lengdan生成了N(1=<N<=10005)个随机整数,妹子对这些数可能有以下几种操作或询问:
1,A a b c 表示给区间a到b内每个数都加上c;
2,S a b 表示输出区间a到b内的和;
已知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内的奇数的个数;
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]);
}
}
}
}