acm练习-day1_2

“麻雀”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内的奇数的个数;

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]);
		}
	}
}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值