답안 #870037

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870037 2023-11-06T17:29:09 Z LOLOLO Meteors (POI11_met) C++14
0 / 100
296 ms 24796 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;
        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])
                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] == 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);

    mem(ans, 0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        //cout << solve() << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 14940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 14940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 15708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 15452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 15440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 15192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 296 ms 24796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 270 ms 23104 KB Output isn't correct
2 Halted 0 ms 0 KB -