█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 6768

Problema 0x25 - Suma de un subarreglo grande

  • Autor: danidiaztech
  • Fecha: 2022-11-15 01:29:08 UTC (Hace alrededor de 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.005 s 1 KBi
#2
Correcto
0.006 s 1 KBi
#3
Correcto
0.006 s 1 KBi
#4
Correcto
0.004 s 1 KBi
#5
Correcto
0.004 s 1 KBi
#6
Correcto
0.004 s 1 KBi
#7
Correcto
0.005 s 1 KBi
#8
Correcto
0.008 s 1 KBi
#9
Correcto
0.019 s 2 KBi
#10
Correcto
0.017 s 2 KBi
#11
Correcto
0.016 s 2 KBi
#12
Correcto
0.019 s 2 KBi
#13
Correcto
0.02 s 2 KBi
#14
Correcto
0.02 s 2 KBi
Puntos totales: 100 / 100

Código

// Made by Daniel Diaz (@Danidiaztech)
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define forn(i, n) for (int i = 0; i < n; i++) // for in range in python
#define FOR(i, a, b) for (int i = a; i < b; i++) // for in range in python
#define int long long int
#define double long double
#define pb push_back
#define ff first
#define ss second
#define mk make_pair

typedef pair<int, int> pii;

const int MAX = 1e6;
const int MIN = -MAX;
const int INF = LLONG_MAX;
const int MINF = LLONG_MIN;
const int MOD = 1e9 + 7;

// int arr[MAX];
void naive(){
  int n;
  cin >> n;
  int a[n];
  forn(i, n) cin >> a[i];

  int q; cin >> q;
  while (q--){
    int i, j;
    cin >> i >> j;
    // Naive solution
    int sum = 0;
    for (int k = i; k <= j; k++){
      sum += a[k];
    }
    cout << sum << endl;
  }

}

void solve(){
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++){
    int x; cin >> x;
    a[i] = x + a[i - 1];
  }

  int q; cin >> q;
  while (q--){
    int i, j;
    cin >> i >> j;
    i++, j++;
    // Prefix sum solution
    cout << (a[j]) - (a[i - 1]) << endl;
  }


}
int32_t main() {
  fastInp;
  #if LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif

  int tc = 1;
  // cin >> tc;

  for (int t = 1; t <= tc; t++){
    // cout << "Case #" << t << ": ";
    // naive();
    solve();
  }
  return 0;
}