Submission #623581

# Submission time Handle Problem Language Result Execution time Memory
623581 2022-08-06T02:18:34 Z ACGN Distributing Candies (IOI21_candies) C++17
8 / 100
156 ms 18012 KB
#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

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 156 ms 13916 KB Output is correct
2 Correct 150 ms 18012 KB Output is correct
3 Correct 148 ms 17872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -