Submission #839680

#TimeUsernameProblemLanguageResultExecution timeMemory
839680konberAddk (eJOI21_addk)C++14
36 / 100
2059 ms3064 KiB
#include <iostream> #include <vector> using namespace std; typedef long long ll; vector<ll> pref1, pref2; ll prefix_sum1(int a, int b){ return pref1[b] - pref1[a-1]; } ll prefix_sum2(int a, int b){ return pref2[b] - pref2[a-1] - (a-1)*prefix_sum1(a, b); } int main() { int N, K; scanf("%d%d", &N, &K); if(K!=1) return 0; vector<int> a(N+1); pref1.resize(N+1, 0); pref2.resize(N+1, 0); for(int i=1; i <= N; i++){ scanf("%d", &a[i]); } for(int i=1; i <= N; i++){ pref1[i] = pref1[i-1] + a[i]; pref2[i] = pref2[i-1] + i*a[i]; } int Q; scanf("%d", &Q); while(Q--){ int q; scanf("%d", &q); if(q==1){ int ig; scanf("%d", &ig); continue; } int l, r, m; scanf("%d%d%d", &l, &r, &m); ll ans=0; for(int i=l; i <= r-m+1; i++){ ans += prefix_sum1(i, i+m-1); } printf("%lld\n", ans); /*if(m==1){ printf("%lld\n", prefix_sum1(l, r)); continue; } int ind1=l+m-1, ind2=r-m+1; if(ind1 <= ind2){ ll ans = m*prefix_sum1(ind1, ind2); ans += prefix_sum2(l, ind1-1); ans += m*prefix_sum1(ind2+1, r) - prefix_sum2(ind2+1, r); printf("%lld\n", ans); } else{ m = ind2-l+1; swap(ind1, ind2); ll ans; if(m==1) ans=prefix_sum1(ind1, ind2); else{ ans = m*prefix_sum1(ind1, ind2); ans += prefix_sum2(l, ind1-1); ans += m*prefix_sum1(ind2+1, r) - prefix_sum2(ind2+1, r); } printf("%lld\n", ans); }*/ } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d%d", &N, &K);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d", &Q);
      |     ~~~~~^~~~~~~~~~
Main.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
Main.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |             scanf("%d", &ig);
      |             ~~~~~^~~~~~~~~~~
Main.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         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...