Submission #798164

# Submission time Handle Problem Language Result Execution time Memory
798164 2023-07-30T12:20:45 Z YassirSalama Distributing Candies (IOI21_candies) C++17
11 / 100
254 ms 26280 KB
#include "candies.h"
#include<bits/stdc++.h>
#include <vector>
using namespace std;
const int MAXN=2e5;
long long tree[4*MAXN+1];
long long lazy[4*MAXN+1];
vector<int> cc;
vector<int> ans;
void push(int node,int l,int r){
    if(lazy[node]!=0){
        tree[node]+=lazy[node];
        if(l!=r) lazy[node<<1]+=lazy[node],
                 lazy[node<<1|1]+=lazy[node];
        if(l==r) tree[node]=min(tree[node],(long long)cc[l]);
        lazy[node]=0;
    }
}
void update(int node,int l,int r,int ql,int qr,int v){
    push(node,l,r);
    if(l==r){
        tree[node]=min((long long)cc[l],tree[node]+v);
        return;
    }
    if(ql<=l&&r<=qr){
        lazy[node]+=v;
        push(node,l,r);
        return;
    }
    int mid=(l+r)/2;
    if(ql<=mid) update(node<<1,l,mid,ql,qr,v);
    if(qr>mid) update(node<<1|1,mid+1,r,ql,qr,v);
    push(node<<1,l,mid);
    push(node<<1|1,mid+1,r);
    tree[node]=min(tree[node<<1],tree[node<<1|1]);
}
void build(int node,int l,int r){
    push(node,l,r);
    if(l==r){
        push(node,l,r);
        ans[l]=(min(tree[node],(long long)cc[l]));
        return;
    }
    int mid=(l+r)/2;
    build(node<<1,l,mid);
    build(node<<1|1,mid+1,r);
}
vector<int> distribute_candies(vector<int> c, vector<int> l,
                                    vector<int> r, vector<int> v) {
    // memset(lazy,0,sizeof lazy);
    // memset(tree,0,sizeof tree);
    for(int i=0;i<4*MAXN;i++) tree[i]=0,lazy[i]=0;
    int n = c.size();
    int q = v.size();
    ans.resize(n,0);
    cc=c;
    if(n<=2000&&q<=2000){
        vector<long long> s(n);
        for(int j=0;j<q;j++){
            int lrr=l[j],rr=r[j],cc=v[j];
            for(int i=lrr;i<=rr;i++){
                s[i]=max(0LL,min((long long)c[i],s[i]+cc));
            }
        }
        for(int i=0;i<n;i++) ans[i]=(int)s[i];
    }else{
        for(int j=0;j<q;j++){
            int lrr=l[j],rr=r[j],cc=v[j];
            update(1,0,n-1,lrr,rr,cc);
        }
        build(1,0,n-1);
    }
    return ans;
}


#ifdef IOI

int main() {
    int n;
    assert(1 == scanf("%d", &n));
    std::vector<int> c(n);
    for(int i = 0; i < n; ++i) {
        assert(scanf("%d", &c[i]) == 1);
    }

    int q;
    assert(1 == scanf("%d", &q));
    std::vector<int> l(q), r(q), v(q);
    for(int i = 0; i < q; ++i) {
        assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
    }

    std::vector<int> ans = distribute_candies(c, l, r, v);

    for(int i = 0; i < n; ++i) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", ans[i]);
    }
    printf("\n");
    fclose(stdout);
    return 0;
}

#endif
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12756 KB Output is correct
2 Correct 4 ms 12756 KB Output is correct
3 Correct 5 ms 12884 KB Output is correct
4 Correct 5 ms 12884 KB Output is correct
5 Correct 6 ms 12864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 26280 KB Output is correct
2 Correct 254 ms 25440 KB Output is correct
3 Correct 223 ms 25340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 12756 KB Output is correct
2 Incorrect 137 ms 20580 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12756 KB Output is correct
2 Correct 5 ms 12756 KB Output is correct
3 Incorrect 49 ms 20192 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12756 KB Output is correct
2 Correct 4 ms 12756 KB Output is correct
3 Correct 5 ms 12884 KB Output is correct
4 Correct 5 ms 12884 KB Output is correct
5 Correct 6 ms 12864 KB Output is correct
6 Correct 246 ms 26280 KB Output is correct
7 Correct 254 ms 25440 KB Output is correct
8 Correct 223 ms 25340 KB Output is correct
9 Correct 5 ms 12756 KB Output is correct
10 Incorrect 137 ms 20580 KB Output isn't correct
11 Halted 0 ms 0 KB -