Submission #870029

# Submission time Handle Problem Language Result Execution time Memory
870029 2023-11-06T16:40:18 Z LOLOLO Meteors (POI11_met) C++14
0 / 100
326 ms 24716 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, int 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;

        if (cur < m) {
            cur++;
            x = a[cur];
        } else {
            x = -a[cur];
            cur--;
        }

        if (L[cur] <= R[cur]) {
            upd(L[cur], x);
            upd(R[cur] + 1, -x);
        } else {
            upd(L[cur], x);
            upd(1, x);
            upd(R[cur] + 1, -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]) {
            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] == 0) {
            cout << "NIE\n";
        } else {
            cout << ans[i] << '\n';
        }
    }

    return 0;
}

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

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        //cout << solve() << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 14940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 14940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 15636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 15452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 15492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 15320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 326 ms 24716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 260 ms 22944 KB Output isn't correct
2 Halted 0 ms 0 KB -