您的位置:首页 > 其它

NYOJ 228 士兵杀敌(五)

2012-09-05 12:17 253 查看
http://acm.nyist.net/JudgeOnline/problem.php?pid=228

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

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

View Code

#include <iostream>
#include <stdio.h>
using namespace std;
const int maxn = 1000005;
const int M = 10003;
int ans[maxn];
int main()
{
int n, m, q, a, b, c, i;
scanf("%d%d%d",&n,&m,&q);
while(m--)
{
scanf("%d%d%d",&a,&b,&c);
ans[a]+=c;
ans[b+1]-=c;
}
for(i=1; i<=n; i++)
ans[i] += ans[i-1];
for(i=1; i<=n; i++)
ans[i]=(ans[i-1]+ans[i])%M;
while(q--)
{
scanf("%d%d",&a,&b);
printf("%d\n",(ans[b]-ans[a-1]+M)%M);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: