Submission #614353

# Submission time Handle Problem Language Result Execution time Memory
614353 2022-07-31T02:12:31 Z serize Distributing Candies (IOI21_candies) C++17
3 / 100
103 ms 8140 KB
#include <candies.h>
#include <bits/stdc++.h>
#include <cassert>
#include <cstdio>
#include <vector>

using namespace std;
const int MAX = 2e5+10;

std::vector<int> abi(MAX);

inline void add(int k, int v){
    if(k <= 0) return;
    while(k < MAX){
        abi[k]+=v;
        k += k&(-k);
    }
}

inline int read(int k){
    int sum = 0;
    while(k > 0){
        sum += abi[k];
        k -= k&(-k);
    }
    return sum;
}

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    
    int n = c.size();
    int q = l.size();
    std::vector<int> s(n);
    if(q <= 2000){
        for(int i = 0; i < q; i++){
            for(int j = l[i]; j <= r[i]; j++){
                if(v[i] < 0){
                    s[j] = max(0,s[j]+v[i]);
                }
                else{
                    s[j] = min(c[j],s[j]+v[i]);
                }
            }
        }
        return s;
    }
    for(int i = 0; i < q; i++){
        add(l[i]+1,v[i]);
        add(r[i]+2,-v[i]);
    }
    for(int i = 0; i < n; i++){
        s[i] = min(c[i],read(i+1));
    }
    return s;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 3 ms 1164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 103 ms 8140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Incorrect 66 ms 6860 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Incorrect 59 ms 6948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 3 ms 1164 KB Output is correct
6 Incorrect 103 ms 8140 KB Output isn't correct
7 Halted 0 ms 0 KB -