Submission #1154408

#TimeUsernameProblemLanguageResultExecution timeMemory
1154408Pichon5새로운 문제 (POI11_met)C++20
0 / 100
1439 ms31704 KiB
#include <bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
#define mp make_pair
using namespace std;
const int tam = 300030;
const ll INF = 1e16;
unsigned long long T[2 * tam];
ll n, m, k;
vector<vll> G;
ll E[tam];
ll res[tam];
vector<pair<pair<ll, ll>, ll>> Q;

void update(int pos, int val) {
    while (pos <= m) {
        T[pos] += val;
        pos += (pos & -pos);
    }
}

ll query(ll pos) {
    unsigned long long res = 0;
    while (pos > 0) {
        res += T[pos];
        pos -= (pos & -pos);
    }
    return res;
}

void parallel_iterative() {
    vector<vll> query_indices(k + 1);
    vll aux;
    for (int i = 1; i <= n; i++) aux.pb(i);
    query_indices[0] = aux;

    stack<tuple<ll, ll, ll>> st;
    st.push({0, k - 1, 0});

    while (!st.empty()) {
        auto [b, e, depth] = st.top();
        st.pop();
        if (query_indices[depth].empty() || e < b) continue;

        ll mid = (b + e) / 2;
        
        memset(T, 0, sizeof T);
        for (int i = b; i <= mid; i++) {
            ll l = Q[i].F.F, r = Q[i].F.S, val = Q[i].S;
            update(l, val);
            if (r < l) {
                update(1, val);
                update(m + 1, -val);
            }
            update(r + 1, -val);
        }
        
        vll A, B;
        for (ll i : query_indices[depth]) {
            ll sum = 0;
            for (auto it : G[i]) {
                sum += query(it);
                if (sum >= 1e10) break;
            }
            if (sum >= E[i]) {
                A.pb(i);
                res[i] = min(res[i], mid + 1);
            } else {
                B.pb(i);
            }
        }

        if (!B.empty()) st.push({mid + 1, e, depth + 1});
        for (int i = b; i <= mid; i++) {
            int l = Q[i].F.F, r = Q[i].F.S, val = -Q[i].S;
            update(l, val);
            if (r < l) {
                update(1, val);
                update(m + 1, -val);
            }
            update(r + 1, -val);
        }
        if (!A.empty()) st.push({b, mid - 1, depth + 1});
        query_indices[depth + 1] = B;
        query_indices[depth + 1] = A;
    }
}

int main() {
    fast
    ll x;
    cin >> n >> m;
    G.assign(n + 1, vll());
    for (int i = 1; i <= m; i++) {
        cin >> x;
        G[x].pb(i);
    }
    for (int i = 1; i <= n; i++) {
        cin >> E[i];
    }
    ll l, r, val;
    cin >> k;
    for (int i = 0; i < k; i++) {
        cin >> l >> r >> val;
        Q.pb({{l, r}, val});
    }
    fill(res, res + n + 1, k + 1);
    parallel_iterative();
    for (int i = 1; i <= n; i++) {
        if (res[i] == k + 1) {
            cout << "NIE" << "\n";
        } else {
            cout << res[i] << "\n";
        }
    }
    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...