답안 #964316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964316 2024-04-16T15:58:02 Z Pekiban Meteors (POI11_met) C++17
74 / 100
308 ms 34736 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int mxN = 3e5+3;
vector<int> a[mxN];
array<int, 3> e[mxN];
ll bit[mxN], p[mxN], ans[mxN], c;
void upd(int idx, int x) {
    while (idx < mxN) {
        bit[idx] += x;
        idx |= (idx + 1);
    }
}
ll sum(ll idx) {
    ll s = 0;
    while (idx >= 0) {
        s += bit[idx];
        idx &= (idx + 1);
        --idx;
    }
    return s;
}
void upd(int l, int r, int x) {
    upd(l, x);
    upd(r+1, -x);
}
int n, m, k;
void solve(int l, int r, vector<int> &b) {
    if (b.empty()) return;
    if (l == r) {
        if (l == k+1) {
            for (auto u : b) {
                ans[u] = -1;
            }
        }
        else {
            for (auto u : b) {
                ans[u] = l;
            }
        }
        return;
    }
    int mid = (l + r)/2;
    while (c < mid) {
        ++c;
        if (e[c][0] <= e[c][1]) {
            upd(e[c][0], e[c][1], e[c][2]);
        }
        else {
            upd(e[c][0], m, e[c][2]);
            upd(1, e[c][1], e[c][2]);
        }
    }
    while (c > mid) {
        if (e[c][0] <= e[c][1]) {
            upd(e[c][0], e[c][1], -e[c][2]);
        }
        else {
            upd(e[c][0], m, -e[c][2]);
            upd(1, e[c][1], -e[c][2]);
        }
        --c;
    }
    vector<int> L, R;
    for (auto x : b) {
        ll s = 0;
        for (auto i : a[x]) {
            s += sum(i);
        }
        if (s >= p[x]) {
            L.push_back(x);
        }
        else {
            R.push_back(x);
        }
    }
    b.clear();
    if (!L.empty()) solve(l, mid, L);
    if (!R.empty()) solve(mid+1, r, R);
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int x;
        cin >> x;
        a[x].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
    }
    cin >> k;
    for (int i = 1; i <= k; ++i) {
        cin >> e[i][0] >> e[i][1] >> e[i][2];
    }
    vector<int> b;
    for (int i = 1; i <= n; ++i)    b.push_back(i);
    solve(1, k+1, b);
    for (int i = 1; i <= n; ++i) {
        if (ans[i] == -1) {
            cout << "NIE" << '\n';
        }
        else {
            cout << ans[i] << '\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 13660 KB Output is correct
2 Correct 4 ms 13660 KB Output is correct
3 Correct 4 ms 13660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 13968 KB Output is correct
2 Correct 3 ms 13660 KB Output is correct
3 Correct 4 ms 13836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 15340 KB Output is correct
2 Correct 63 ms 19540 KB Output is correct
3 Correct 62 ms 15696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 15520 KB Output is correct
2 Correct 67 ms 15528 KB Output is correct
3 Correct 56 ms 19040 KB Output is correct
4 Correct 20 ms 15452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 15188 KB Output is correct
2 Correct 63 ms 19024 KB Output is correct
3 Correct 33 ms 14364 KB Output is correct
4 Correct 63 ms 16052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 15112 KB Output is correct
2 Correct 76 ms 15640 KB Output is correct
3 Correct 35 ms 15136 KB Output is correct
4 Correct 79 ms 18636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 296 ms 34736 KB Output is correct
2 Incorrect 171 ms 24956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 308 ms 32944 KB Output is correct
2 Incorrect 178 ms 23328 KB Output isn't correct
3 Halted 0 ms 0 KB -