Submission #474785

#TimeUsernameProblemLanguageResultExecution timeMemory
474785fuad27Addk (eJOI21_addk)C++17
0 / 100
150 ms2308 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int32_t main () { int n, k; cin >> n >> k; int arr[n+1], prefix1[n+1] = {0}, prefix2[n+1] = {0}; for(int i = 1;i<=n;i++) { cin >> arr[i]; prefix1[i] = prefix1[i-1] + arr[i]; prefix2[i] = prefix2[i-1] + arr[i]*i; } int q; cin >> q; while(q--) { int k; cin >> k; if(k == 1) { } else { int ans = 0; int l, r, m; cin >> l >> r >> m; m = min(r-l-m + 2, m); int a = (prefix2[l+m-1] - prefix2[l-1])-(prefix1[l+m-1] - prefix1[l-1])*(l-1); int b = (prefix1[r-m] - prefix1[l+m-1])*m; int c = (prefix1[r] - prefix1[r-m])*(r+1) - (prefix2[r] - prefix2[r-m]); cout<<a+b+c<<endl; } } }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:22:8: warning: unused variable 'ans' [-Wunused-variable]
   22 |    int ans = 0;
      |        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...