子矩阵的和_java
import java.util.*; public class Main{ private static int N=100010; private static int[] res=new int[N]; public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int m=in.nextInt(); for(int i=1;i<=n;i++){ res[i]=res[i-1]+in.nextInt(); } while(m-->0){ int i=in.nextInt(); int j=in.nextInt(); System.out.println(res[j]-res[i-1]); } } }