Submission #1348624

#TimeUsernameProblemLanguageResultExecution timeMemory
1348624baodatMeteors (POI11_met)C++20
24 / 100
6095 ms7764 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define FOR(i, l, r) for(int i = l; i <= r; i++)
#define FORD(i, l, r) for(int i = l; i >= r; i--)
#define db double
#define ldb long double
#define all_1(x) (x).begin() + 1, (x).end()
#define all(x) (x).begin(), (x).end()
#define ins insert
#define pb push_back
template<typename T>void debug_var(const T& var, const string& name){
    cerr << name << ": " << var << "\n";
}
template<typename T>void debug_1d(const T& vt, const string& name){
    if(vt.empty()){
        cerr << name << " is empty!\n";
        return;
    }
    FOR(i, 0, (int)vt.size() - 1){
        cerr << name << "[" << i << "]: " << vt[i] << "\n";
    }
}
template<typename T> struct BIT{
    int _n;
    vector<T> _bit;
    BIT(int n = 0){
        init(n);
    }
    void init(int n){
        _n = n;
        _bit.assign(_n + 1, 0);
    }
    void update(int i, T v){
        while(i <= _n){
            _bit[i] += v;
            i += i & -i;
        }
    }
    void update(int l, int r, T v){
        update(l, v);
        if(r + 1 <= _n) update(r + 1, -v);
    }
    T query(int i){
        T ans = 0;
        while(i > 0){
            ans += _bit[i];
            i -= i &-i;
        }
        return ans;
    }
    T query(int l, int r){
        return query(r) - query(l - 1);
    }
};
const int N = 3e5 + 5;
int n, m, k, o[N], need[N], L[N], R[N], A[N];

void solve(){
    cin >> n >> m;
    FOR(i, 1, m) cin >> o[i];
    FOR(i, 1, n) cin >> need[i];
    cin >> k;
    FOR(i, 1, k) cin >> L[i] >> R[i] >> A[i];
    auto check = [&](int x, int which){
        BIT<ll> bit(m + 1);
        FOR(i, 1, x){
            if(L[i] > R[i]){
                bit.update(L[i], m, A[i]);
                bit.update(1, R[i], A[i]);
            }
            else bit.update(L[i], R[i], A[i]);
        }
        ll sum = 0;
        FOR(i, 1, m){
            if(o[i] == which) sum += bit.query(i);
        }
        return sum >= need[which];
    };
    FOR(i, 1, n){
        int l = 1, r = k, ans = -1;
        while(l <= r){
            int mid = (l + r) >> 1;
            if(check(mid, i)){
                ans = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        if(ans == -1) cout << "NIE\n";
        else cout << ans << "\n";
    }
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...