Submission #482186

#TimeUsernameProblemLanguageResultExecution timeMemory
482186aris12345678Addk (eJOI21_addk)C++14
0 / 100
33 ms3480 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mxN = 1e5+5; int a[mxN]; ll pref1[mxN], pref2[mxN]; int main() { int n, k, q; scanf("%d %d", &n, &k); for(int i = 1; i <= n; i++) { scanf("%d", &a[i]); pref1[i] = 1LL*pref1[i-1]+a[i]; pref2[i] = 1LL*pref2[i-1]+i*a[i]; } scanf("%d", &q); while(q--) { int type, l, r, m; scanf("%d", &type); if(type == 1) scanf("%d", &l); else { scanf("%d %d %d", &l, &r, &m); ll ans = 0; m = min(r-l-m+2, m); ll a = (pref2[l+m-1]-pref2[l-1])-(pref1[l+m-1]-pref1[l-1])*(l-1); ll b = (pref1[r-m]-pref1[l+m-1])*m; ll c = (pref1[r]-pref1[r-m])*(r+1)-(pref2[r]-pref2[r-m]); printf("%lld\n", a+b+c); } } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:26:16: warning: unused variable 'ans' [-Wunused-variable]
   26 |             ll ans = 0;
      |                ^~~
Main.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
Main.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d", &type);
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:23:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |             scanf("%d", &l);
      |             ~~~~~^~~~~~~~~~
Main.cpp:25:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |             scanf("%d %d %d", &l, &r, &m);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...