#include <bits/stdc++.h>
using namespace std;
// -------Macros---------
#define vi vector<int>
#define int long long
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define all(a) a.begin(), a.end()
#define endl "\n"
// ------------------------
// --------------------------Constants------------------------------
const int INF = 1e9;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
// -------------------------------------------------------------------
// ----------------------Pre Written Functions---------------------------
int sum(vector<int> a){ // Returns the sum of values in a vector<int>
int total = 0;
for (int x : a){
total += x;
total %= MOD;
}
return total;
}
int max_element(vector<int> a){
int m = -1e9;
for (auto x: a) m = max(m, x);
return m;
}
template<typename T>
void printVector(T a){
// cout << "[ ";
for (auto x: a) cout << x << " ";
cout << endl;
}
template<typename T>
void printMap(T a){
cout << "{ ";
for (auto x: a){
cout << x.first << ": " << x.second << " ";
}
cout << "}" << endl;
}
int lcm(int a, int b)
{
return (a / __gcd(a, b)) * b;
}
// ------------------------------------------------------------------------
void solve(){
int n, k; cin >> n >> k;
vector<int> a(n);
FOR(i,0,n) cin >> a[i];
vector<int> prefix(n);
prefix[0] = a[0];
FOR(i,1,n) prefix[i] = prefix[i-1]+a[i];
int q; cin >> q;
while (q--){
int t; cin >> t;
if (t == 1){
int l; cin >> l;
}else{
int l, r, m; cin >> l >> r >> m;
l--;r--;
int ans = 0;
while (l+m-1 <= r){
int r1 = l+m-1;
int o = prefix[r1];
if (l) o-= prefix[l-1];
ans += o;
l++;
}
cout << ans << endl;
}
}
}
int32_t main(){
// FastIO
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("specialist.in (1428))", "r", stdin);
// freopen("specialist.out (1500+))", "w", stdout);
int t = 1;
// cin >> t;
for (int tc = 1; tc <= t; ++tc){
// cout << "Case #" << tc << ": ";
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Correct |
4 ms |
600 KB |
Output is correct |
5 |
Correct |
6 ms |
604 KB |
Output is correct |
6 |
Correct |
9 ms |
604 KB |
Output is correct |
7 |
Correct |
12 ms |
604 KB |
Output is correct |
8 |
Correct |
16 ms |
604 KB |
Output is correct |
9 |
Correct |
31 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
896 KB |
Output is correct |
2 |
Correct |
256 ms |
2200 KB |
Output is correct |
3 |
Correct |
439 ms |
2384 KB |
Output is correct |
4 |
Correct |
1824 ms |
4676 KB |
Output is correct |
5 |
Execution timed out |
2032 ms |
4844 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
234 ms |
1368 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |