码迷,mamicode.com
首页 > 其他好文 > 详细

LightOJ 1112--Curious Robin Hood

时间:2015-08-17 21:37:51      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %lld & %llu

 Status

Description

Robin Hood likes to loot rich people since he helps the poor people with this money. Instead of keeping all the money together he does another trick. He keeps n sacks where he keeps this money. The sacks are numbered from 0 to n-1.

Now each time he can he can do one of the three tasks.

1)                  Give all the money of the ith sack to the poor, leaving the sack empty.

2)                  Add new amount (given in input) in the ith sack.

3)                  Find the total amount of money from ith sack to jth sack.

Since he is not a programmer, he seeks your help.

Input

Input starts with an integer T (≤ 5), denoting the number of test cases.

Each case contains two integers n (1 ≤ n ≤ 105) and q (1 ≤ q ≤ 50000). The next line contains nspace separated integers in the range [0, 1000]. The ith integer denotes the initial amount of money in the ith sack (0 ≤ i < n).

Each of the next q lines contains a task in one of the following form:

1 i        Give all the money of the ith(0 ≤ i < n) sack to the poor.

2 i v     Add money v (1 ≤ v ≤ 1000) to the ith(0 ≤ i < n) sack.

3 i j      Find the total amount of money from ith sack to jth sack (0 ≤ i ≤ j < n).

Output

For each test case, print the case number first. If the query type is 1, then print the amount of money given to the poor. If the query type is 3, print the total amount from ith to jth sack.

Sample Input

1

5 6

3 2 1 4 5

1 4

2 3 4

3 0 3

1 2

3 0 4

1 1

Sample Output

Case 1:

5

14

1

13

2

Source

Problem Setter: Jane Alam Jan
一道比较简单的模拟题吧, 只要耐心读题, 今天水友赛不比不知道, 一比总算是看到了差距。 不多说。 Fighting, 也正好借这个机会和队友好好磨合磨合。
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 using namespace std;
 5 int num[100100];
 6 int main()
 7 {
 8     int t, temp = 1;
 9     scanf("%d", &t);
10     while(t--)
11     {
12         printf("Case %d:\n", temp++);
13         int n, m;
14         scanf("%d %d", &n, &m);
15         for(int i = 0; i < n; i++)
16             scanf("%d", &num[i]);
17         for(int i = 0; i < m; i++)
18         {
19             int q;
20             scanf("%d", &q);
21             if(q == 1)
22             {
23                 int p;
24                 scanf("%d", &p);
25                 printf("%d\n",num[p]);
26                 num[p] = 0;
27             }
28             if(q == 2)
29             {
30                 int a, b;
31                 scanf("%d %d", &a, &b);
32                 num[a] += b; 
33             } 
34             if(q == 3)
35             {
36                 int k, l, sum = 0;
37                 scanf("%d %d", &k, &l);
38                 for(int i = k; i <= l; i++)
39                     sum += num[i];
40                 printf("%d\n", sum);
41             }
42         }
43     }
44     return 0;
45 }

 

 

LightOJ 1112--Curious Robin Hood

标签:

原文地址:http://www.cnblogs.com/fengshun/p/4737507.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!