巧用数组,貌似很牛逼,还需多多体会才能感觉其中的高深
nyoj-228
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int MOD = 10003;
int a[1000005]={0};
int main()
{
int n,c,q,Mi,Ni,Ai,x,y;
scanf("%d%d%d",&n,&c,&q);
for(int i = 1; i <= c; i++)
{
scanf("%d%d%d",&Mi,&Ni,&Ai);
a[Mi] += Ai;
a[Ni+1] -= Ai;
}
for(int i = 1;i <= n;i++)
a[i] += a[i-1];
for(int i = 1;i <= n;i++)
a[i] = (a[i-1] + a[i]) % MOD;
for(int i = 0;i < q;i++)
{
scanf("%d%d",&x,&y);
printf("%d\n",(a[y] - a[x-1] + MOD)%MOD);
}
}
hdu-1556
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int MOD = 10003;
int a[100005];
int main()
{
int n,x,y;
while(scanf("%d",&n),n)
{
memset(a,0,sizeof(a));
for(int i = 1; i <= n; i++)
{
scanf("%d%d",&x,&y);
a[x] += 1;
a[y+1] -= 1;
}
for(int i = 1; i <= n; i++)
a[i] += a[i-1];
printf("%d",a[1]);
for(int i = 2;i <= n;i++)
printf(" %d",a[i]);
printf("\n");
}
return 0;
}