답안 #964275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964275 2024-04-16T14:21:21 Z Pekiban Meteors (POI11_met) C++17
74 / 100
524 ms 34968 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 = -1;
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 supd(int l, int r, int x) {
    upd(l, x);
    upd(r+1, -x);
}
int n, m;
void solve(int l, int r, vector<int> &b) {
    int mid = (l + r)/2;
    while (c < mid) {
        ++c;
        if (e[c][0] <= e[c][1]) {
            supd(e[c][0], e[c][1], e[c][2]);
        }
        else {
            supd(e[c][0], m-1, e[c][2]);
            supd(0, e[c][1], e[c][2]);
        }
    }
    while (c > mid) {
        if (e[c][0] <= e[c][1]) {
            supd(e[c][0], e[c][1], -e[c][2]);
        }
        else {
            supd(e[c][0], m-1, -e[c][2]);
            supd(0, 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]) {
            ans[x] = mid;
            L.push_back(x);
        }
        else {
            R.push_back(x);
        }
    }
    b.clear();
    if (l < r) {
        solve(l, mid-1, L);
        solve(mid+1, r, R);
    }
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    fill(ans, ans+n, -1);
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        --x;
        a[x].push_back(i);
    }
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
        cin >> e[i][0] >> e[i][1] >> e[i][2];
        --e[i][0], --e[i][1];
    }
    vector<int> b(n);
    iota(b.begin(), b.end(), 0);
    solve(0, k-1, b);
    for (int i = 0; i < n; ++i) {
        cout << (ans[i] == -1 ? "NIE" : to_string(ans[i] + 1)) << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 13656 KB Output is correct
2 Correct 4 ms 13656 KB Output is correct
3 Correct 4 ms 13660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 13660 KB Output is correct
2 Correct 4 ms 13656 KB Output is correct
3 Correct 5 ms 13660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 15188 KB Output is correct
2 Correct 94 ms 19552 KB Output is correct
3 Correct 62 ms 15648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 15520 KB Output is correct
2 Correct 74 ms 15376 KB Output is correct
3 Correct 95 ms 19024 KB Output is correct
4 Correct 23 ms 15660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 15188 KB Output is correct
2 Correct 75 ms 19204 KB Output is correct
3 Correct 64 ms 14368 KB Output is correct
4 Correct 59 ms 15856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 15120 KB Output is correct
2 Correct 85 ms 15660 KB Output is correct
3 Correct 45 ms 15184 KB Output is correct
4 Correct 82 ms 18772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 524 ms 34968 KB Output is correct
2 Incorrect 359 ms 25064 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 509 ms 33040 KB Output is correct
2 Incorrect 420 ms 23484 KB Output isn't correct
3 Halted 0 ms 0 KB -