Submission #623581

#TimeUsernameProblemLanguageResultExecution timeMemory
623581ACGNDistributing Candies (IOI21_candies)C++17
8 / 100
156 ms18012 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define vs vector<signed> #define vi vector<int> #define pii pair<int,int> #define vii vector<pii> #define pb push_back #include "candies.h" struct st { int n; vi v; st(int x) { n=x; v.resize(4*n); } void _add(int i,int l,int r,int tg,int val) { v[i]+=val; if (r==l+1) return; int mid = (l+r)/2; if (tg<mid) _add(i*2,l,mid,tg,val); else _add(i*2+1,mid,r,tg,val); } void add(int p,int x) { _add(1,0,n,p,x); } int _sum(int i,int cl,int cr,int tl,int tr) { if (i==-1) return 0; if (cr<=tl) return 0; if (tr<=cl) return 0; if ((tl<=cl)&&(cr<=tr)) { return v[i]; } int mid = (cl+cr)/2; return _sum(i*2,cl,mid,tl,tr)+_sum(i*2+1,mid,cr,tl,tr); } int sum(int k) { return _sum(1,0,n,0,k); } }; vs distribute_candies(vs c,vs l,vs r,vs v) { int n = c.size(); st s(n+3); for (int i=0;i<l.size();i++) { s.add(l[i],v[i]); s.add(r[i]+1,-v[i]); } vs ans; for (int i=0;i<n;i++) { ans.pb(min((int)c[i],s.sum(i+1))); } return ans; }

Compilation message (stderr)

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:45:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i=0;i<l.size();i++) {
      |                  ~^~~~~~~~~
#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...