Submission #461218

#TimeUsernameProblemLanguageResultExecution timeMemory
461218vanicNuclearia (CEOI15_nuclearia)C++14
0 / 100
1097 ms266784 KiB
#include <iostream> #include <cmath> #include <cstdio> #include <algorithm> #include <vector> #include <cassert> using namespace std; typedef long long ll; const int Log=22, pot=(1<<Log); struct tournament{ ll t[pot*2]; pair < ll, ll > prop[pot*2]; void propagate(int &x, int &range){ if(!prop[x].first && !prop[x].second){ return; } t[x]+=prop[x].first*range+prop[x].second*(range*(range-1)/2); if(x<pot){ prop[x*2].first+=prop[x].first; prop[x*2].second+=prop[x].second; prop[x*2+1].first+=prop[x].first+prop[x].second*range/2; prop[x*2+1].second+=prop[x].second; } prop[x].first=0; prop[x].second=0; } void update(int x, ll val){ for(; x>0; x/=2){ t[x]+=val; } } void update2(int L, int D, int x, int l, int d, pair < ll, ll > val){ int range=D-L+1; propagate(x, range); if(L>=l && D<=d){ update(x, val.first*range+val.second*(range*(range-1)/2)); if(x<pot){ prop[x*2].first+=val.first; prop[x*2].second+=val.second; prop[x*2+1].first+=val.first+val.second*range/2; prop[x*2+1].second+=val.second; } return; } if((L+D)/2>=l){ update2(L, (L+D)/2, x*2, l, min(d, (L+D)/2), val); val.first+=val.second*(min((L+D)/2, d)-l+1); } if((L+D)/2+1<=d){ update2((L+D)/2+1, D, x*2+1, max(l, (L+D)/2+1), d, val); } } ll query(int L, int D, int x, int l, int d){ int range=D-L+1; propagate(x, range); if(L>=l && D<=d){ return t[x]; } ll lijeva=0, desna=0; if((L+D)/2>=l){ lijeva=query(L, (L+D)/2, x*2, l, d); } if((L+D)/2+1<=d){ desna=query((L+D)/2+1, D, x*2+1, l, d); } return lijeva+desna; } }; tournament T; int main(){ int h, w; scanf("%d%d", &w, &h); bool p=0; if(h>w){ swap(h, w); } assert(h==1); int n, q; scanf("%d", &n); int a, b, c, d; int kol; int l, r; pair < int, int > val; for(int i=0; i<n; i++){ scanf("%d%d%d%d", &a, &b, &c, &d); a--; b--; if(!p){ swap(a, b); } kol=c/d; l=b-kol; r=b; if(l>-1){ val={c%d, d}; } else{ val={c%d+d*-l, d}; l=0; } T.update2(0, pot-1, 1, l, r, val); l=b+1; r=b+kol; r=min(r, w-1); val={c-d, -d}; if(l<=r){ T.update2(0, pot-1, 1, l, r, val); } } scanf("%d", &q); for(int i=0; i<q; i++){ scanf("%d%d%d%d", &a, &b, &c, &d); a--; b--; c--; d--; if(!p){ swap(a, b); swap(c, d); } printf("%lld\n", (ll)round((double)T.query(0, pot-1, 1, b, d)/(d-b+1))); // printf("%lld\n", (ll)T.query(0, pot-1, 1, b, d)); } return 0; }

Compilation message (stderr)

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |  scanf("%d%d", &w, &h);
      |  ~~~~~^~~~~~~~~~~~~~~~
nuclearia.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
nuclearia.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   scanf("%d%d%d%d", &a, &b, &c, &d);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:117:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
nuclearia.cpp:119:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |   scanf("%d%d%d%d", &a, &b, &c, &d);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...