NYOJ 228 士兵杀敌(五)

http://acm.nyist.net/JudgeOnline/problem.php?pid=228

本想用树状数组的, 结果有点囧...........

然后看了别的大牛的做法....  离线查询的可以有o(n)的算法...

View Code
 1  
 2 #include <iostream>
 3 #include <stdio.h>
 4 using namespace std;
 5 const int maxn = 1000005;
 6 const int M = 10003;
 7 int ans[maxn];
 8 int main()
 9 {
10     int n, m, q, a, b, c, i;
11     scanf("%d%d%d",&n,&m,&q);
12     while(m--)
13     {
14         scanf("%d%d%d",&a,&b,&c);
15         ans[a]+=c;
16         ans[b+1]-=c;
17     }
18     for(i=1; i<=n; i++)
19     ans[i] += ans[i-1];
20     for(i=1; i<=n; i++)
21     ans[i]=(ans[i-1]+ans[i])%M;
22     while(q--)
23     {
24         scanf("%d%d",&a,&b);
25         printf("%d\n",(ans[b]-ans[a-1]+M)%M);
26     }
27     return 0;
28 }        
posted @ 2012-09-05 12:17  YORU  阅读(202)  评论(0编辑  收藏  举报