Submission #1195602

#TimeUsernameProblemLanguageResultExecution timeMemory
1195602AmrDistributing Candies (IOI21_candies)C++20
8 / 100
68 ms9800 KiB
#include "candies.h"
#include <vector>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define sz size()
const int N = 200005;
vector<int> a;
ll bit[N];
ll n , q;
ll get(ll x)
{
    ll res = 0;
    while(x>0)
    {
        res+=bit[x];
        x -= (x&(-x));
    }
    return res;
}
void upd(ll x, ll val)
{
    while(x<n+2)
    {
        bit[x] += val;
        x += (x&(-x));
    }

}
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
     n = c.size();
     q = l.size();
     a.resize(n);
     for(int i = 0; i < q; i++)
     {
         ll L = l[i], R = r[i], val = v[i];
         upd(L+1,val);
         upd(R+2,-val);
     }
     for(int i = 0; i < n; i++)
     {
         ll x = get(i+1);
         if(x>c[i]) a[i] = c[i]; else a[i] = x;
     }
    return a;
}
#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...