Submission #870040

# Submission time Handle Problem Language Result Execution time Memory
870040 2023-11-06T17:44:06 Z LOLOLO Meteors (POI11_met) C++17
100 / 100
638 ms 34620 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 3e5 + 100;
ll f[N];
int L[N], R[N], a[N], p[N], ans[N];
vector <int> on[N];

void upd(int i, ll x) {
    for (; i < N; i += i & (-i))
        f[i] += x;
}

ll get(int i) {
    ll s = 0;
    for (; i; i -= i & (-i))
        s += f[i];

    return s;
}

int cur = 0;

void move(int m) {
    while (cur != m) {
        int x = 0, l, r;
        if (cur < m) {
            cur++;
            x = a[cur];
            l = L[cur], r = R[cur];
        } else {
            x = -a[cur];
            l = L[cur], r = R[cur];
            cur--;
        }

        if (l <= r) {
            upd(l, x);
            upd(r + 1, -x);
        } else {
            upd(1, x);
            upd(r + 1, -x);
            upd(l, x);
        }
    }
}

void dnc(int l, int r, vector <int>& lst) {
    if (l > r || lst.empty())
        return;

    vector <int> win, lose;
    int m = (l + r) / 2;
    move(m);   

    for (auto x : lst) {
        ll s = 0;
        for (auto t : on[x]) {
            s += get(t);
            if (s >= p[x])
                break;
        }

        if (s >= p[x]) {
            ans[x] = m;
            win.pb(x);
        } else {
            lose.pb(x);
        }
    }

    lst.clear();
    dnc(l, m - 1, win);
    dnc(m + 1, r, lose);
}

ll solve() {
    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= m; i++) {
        int x;
        cin >> x;
        on[x].pb(i);
    }

    for (int i = 1; i <= n; i++)
        cin >> p[i];

    int k;
    cin >> k;

    for (int i = 1; i <= k; i++) {
        cin >> L[i] >> R[i] >> a[i];
    }

    vector <int> lst;
    for (int i = 1; i <= n; i++)
        lst.pb(i);

    dnc(1, k, lst);
    for (int i = 1; i <= n; i++) {
        if (ans[i] == -1) {
            cout << "NIE\n";
        } else {
            cout << ans[i] << '\n';
        }
    }

    return 0;
}

int main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    mem(ans, -1);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        //cout << solve() << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 3 ms 14940 KB Output is correct
3 Correct 4 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 15544 KB Output is correct
2 Correct 52 ms 17252 KB Output is correct
3 Correct 51 ms 15704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 15588 KB Output is correct
2 Correct 56 ms 15452 KB Output is correct
3 Correct 43 ms 16732 KB Output is correct
4 Correct 18 ms 16064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 15472 KB Output is correct
2 Correct 78 ms 17036 KB Output is correct
3 Correct 24 ms 15008 KB Output is correct
4 Correct 51 ms 15936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 15196 KB Output is correct
2 Correct 54 ms 15452 KB Output is correct
3 Correct 31 ms 15352 KB Output is correct
4 Correct 64 ms 16724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 300 ms 24596 KB Output is correct
2 Correct 108 ms 16988 KB Output is correct
3 Correct 135 ms 16976 KB Output is correct
4 Correct 546 ms 32504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 277 ms 23188 KB Output is correct
2 Correct 143 ms 16316 KB Output is correct
3 Correct 57 ms 17748 KB Output is correct
4 Correct 638 ms 34620 KB Output is correct