Submission #848412

#TimeUsernameProblemLanguageResultExecution timeMemory
848412KK_1729Addk (eJOI21_addk)C++14
36 / 100
2032 ms4844 KiB
#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(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...