AOJ 801.热身之蘸酱吃

Time Limit: 1000 ms   Case Time Limit: 1000 ms   Memory Limit: 64 MB
Total Submission: 108   Submission Accepted: 50
 
Description
在ACM实验室里有n个草莓,编号依次为1到n,重量依次为w[1],w[2],...,w[n]。
由于某人比较喜欢蘸西瓜酱吃,在接下来的时间内,我会选择m个区间[l,r]并且随机选择一个数字k,使得标号在[l,r]区间内的每个草莓(包括端点)上面都加蘸了k重量的酱。
这时候会突然出现T个区间[L,R],对于每个区间,我们需要计算标号属于这个区间的草莓的重量和(包括上面的西瓜酱的重量,区间也包括端点)并输出。
Input
题目包括多组输入
第一行输入3个数n,m,T,空格分开,1<=n<=1000,1<=m<=1000,1<=T<=1000
第二行输入n个数,空格分开,w[1],w[2],...,w[n],1<=w[i]<=100
接下来m行,每行有三个数,空格分开,分别为l,r,k,1<=l<=r<=n, 0<=k<=100
接下来T行,每行有两个数,空格分开,分别为L,R, 1<=L<=R<=n
Output
输出公有T行,每行一个数字表示标号属于区间[L,R]的草莓加酱的重量
Sample Input
Original Transformed
4 1 2
1 2 3 4
1 2 1
1 2
2 4
Sample Output
Original Transformed
5
10
Hint
注意数据范围

http://icpc.ahu.edu.cn/OJ/ContestProblem.aspx?cid=151&id=801

直接强行模拟即可

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <string>
 6 #include <iostream>
 7 #include <vector>
 8 #include <list>
 9 #include <stack>
10 using namespace std;
11  
12 #define REP(n) for(int o=0;o<n;o++)
13  
14 const int maxn = 1005;
15 int w[maxn];
16  
17 bool Do() {
18     int n,m,T;
19     if(scanf("%d%d%d",&n,&m,&T) == EOF)
20         return false;
21     REP(n)
22         scanf("%d",&w[o+1]);
23     REP(m) {
24         int l,r,k;
25         scanf("%d%d%d",&l,&r,&k);
26         for(;l <= r;l++)
27             w[l] += k;
28     }
29     REP(T) {
30         int L,R;
31         int ans=0;
32         scanf("%d%d",&L,&R);
33         for(;L <= R;L++)
34             ans += w[L];
35         printf("%d
",ans);
36     }
37     return true;
38 }
39  
40 int main() {
41     while(Do());
42     return 0;
43 }
原文地址:https://www.cnblogs.com/ohyee/p/5313741.html