Submission #944251

# Submission time Handle Problem Language Result Execution time Memory
944251 2024-03-12T12:51:15 Z Zero_OP Meteors (POI11_met) C++14
100 / 100
1430 ms 65536 KB
#include<bits/stdc++.h>

using namespace std;
using int64 = int64_t;

#define     REP(i, n) for(int i = 0, _n = n; i < _n; ++i)
#define    REPD(i, n) for(int i = n - 1; i >= 0; --i)
#define  FOR(i, l, r) for(int i = l, _r = r; i <= _r; ++i)
#define FORD(i, r, l) for(int i = r, _l = l; i >= _l; --i)
#define          left __left
#define         right __right
#define          prev __prev
#define          next __next
#define           div __div
#define            pb push_back
#define            pf push_front
#define         sz(v) (int)v.size()
#define      range(v) begin(v), end(v)
#define    compact(v) v.erase(unique(range(v)), end(v))
#define      debug(v) "[" #v " = " << (v) << "]"

template<typename T>
    bool minimize(T& a, const T& b){
        if(a > b){
            a = b;
            return true;
        }
        return false;
    }

template<typename T>
    bool maximize(T& a, const T& b){
        if(a < b){
            a = b;
            return true;
        }
        return false;
    }

template<int dimension, class T>
struct vec : public vector<vec<dimension - 1, T>> {
    static_assert(dimension > 0, "Dimension must be positive !\n");
    template<typename... Args>
    vec(int n = 0, Args... args) : vector<vec<dimension - 1, T>>(n, vec<dimension - 1, T>(args...)) {}
};

template<class T>
struct vec<1, T> : public vector<T> {
    vec(int n = 0, T val = T()) : vector<T>(n, val) {}
};

void init(void);
void process(void);

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

    #define task "antuvu"
    if(fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }

    int T = 1; //cin >> T;
    while(T--) {
        init();
        process();
    }

    return 0;
}

struct FenwickTree{
    vector<int64> bit;
    FenwickTree(int n) : bit(n + 1, 0) {}

    void update(int id, int64 val){
        for(; id < sz(bit); id += id & (-id)){
            bit[id] += val;
        }
    }

    int64 query(int id){
        int64 sum = 0;
        for(; id > 0; id -= id & (-id)){
            sum += bit[id];
        }
        return sum;
    }

    void update_range(int l, int r, int64 val){
        if(l <= r){
            update(l, val);
            update(r + 1, -val);
        }
        else{
            swap(l, r);
            update(1, val);
            update(l + 1, -val);
            update(r, val);
        }
    }
};

const int MAX = 3e5 + 5;

int n, m, k, o[MAX], p[MAX], u[MAX], v[MAX], c[MAX], l[MAX], r[MAX], mid[MAX], ans[MAX];
vector<int> owned_sections[MAX], indices[MAX];

void init(){
    cin >> n >> m;
    FOR(i, 1, m){
        cin >> o[i];
        owned_sections[o[i]].pb(i);
    }

    FOR(i, 1, n){
        cin >> p[i];
    }

    cin >> k;
    FOR(i, 1, k){
        cin >> u[i] >> v[i] >> c[i];
    }
}

void parallel_binary_search(){
    FOR(i, 1, n){
        l[i] = 1;
        r[i] = k;
        ans[i] = -1;
    }

    while(true){
        bool found = false;
        FOR(i, 1, n){
            if(l[i] <= r[i]){
                indices[(l[i] + r[i]) >> 1].pb(i);
                found = true;
            }
        }

        if(!found) break;
        FenwickTree BIT(m);

        int j = 1;
        FOR(i, 1, k){
            BIT.update_range(u[i], v[i], c[i]);
            for(int id : indices[i]){
                int64 sum = 0;
                for(int location : owned_sections[id]){
                    sum += BIT.query(location);
                    if(sum >= p[id]) break;
                }

                if(sum >= p[id]){
                    ans[id] = i;
                    r[id] = i - 1;
                }
                else l[id] = i + 1;
            }
            indices[i].clear();
        }
    }
}

void process(){
    parallel_binary_search();
    FOR(i, 1, n){
        if(ans[i] < 1 or ans[i] > k) cout << "NIE\n";
        else cout << ans[i] << '\n';
    }
}

Compilation message

met.cpp: In function 'void parallel_binary_search()':
met.cpp:146:13: warning: unused variable 'j' [-Wunused-variable]
  146 |         int j = 1;
      |             ^
met.cpp: In function 'int main()':
met.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 23128 KB Output is correct
2 Correct 5 ms 23132 KB Output is correct
3 Correct 6 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23128 KB Output is correct
2 Correct 5 ms 23132 KB Output is correct
3 Correct 5 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 24520 KB Output is correct
2 Correct 80 ms 26608 KB Output is correct
3 Correct 70 ms 26048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 25456 KB Output is correct
2 Correct 73 ms 25532 KB Output is correct
3 Correct 76 ms 26608 KB Output is correct
4 Correct 23 ms 25300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 24784 KB Output is correct
2 Correct 71 ms 27324 KB Output is correct
3 Correct 37 ms 23132 KB Output is correct
4 Correct 71 ms 26396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 24020 KB Output is correct
2 Correct 71 ms 25516 KB Output is correct
3 Correct 52 ms 24268 KB Output is correct
4 Correct 83 ms 27680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 710 ms 40684 KB Output is correct
2 Correct 528 ms 27996 KB Output is correct
3 Correct 174 ms 26020 KB Output is correct
4 Correct 1194 ms 65536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 738 ms 39632 KB Output is correct
2 Correct 597 ms 28076 KB Output is correct
3 Correct 144 ms 26664 KB Output is correct
4 Correct 1430 ms 65536 KB Output is correct