H-fishfloss and cat's food
fishfloss and cats food
https://ac.nowcoder.com/acm/contest/32992/H
H-fishfloss and cat's food
利用前缀和
#include <iostream> #include <cstring> using namespace std; const int N = 1e5+10; double ans[N]; //记录到0-i的总价值 long long n,k,l,r; double x; int main() { ans[0]=0; scanf("%lld%lld",&n,&k); for(long long i=1;i<=n;i++) { scanf("%lf",&x); ans[i]=ans[i-1]+x; } while(k--) { scanf("%lld%lld",&l,&r); double s=ans[r]-ans[l-1]; //l-r的总价值为 ans[r]-ans[l-1] printf("%.0lf\n",s); //我当时以为某些食物的价值可能不是整数 } return 0; }