I have this code:
#include <iostream>
using namespace std;
int tc; int tv;
int array[1000000];
void Input(){
scanf("%d\n",&tc);
for (int i = 0;i<tc;i++){
scanf("%d",&array[i]);
}
scanf("\n");
scanf("%d\n",&tv);
}
void XuLi(){
Input();
int a,b;
for (int i = 0;i<tv;i++){
scanf("%d %d\n",&a,&b);
a--; b--;
int sum = 0;
for (int i = a;i<=b;i++){
sum+=array[i];
}
printf("%d\n",sum);
}
}
int main(){
freopen("doanlt.inp","r",stdin); freopen("doanlt.out","w",stdout);
XuLi(); return 0;
}
How can I optimize it?
The testcases are about 10^6 tries.