Submission #622270

# Submission time Handle Problem Language Result Execution time Memory
622270 2022-08-04T05:32:03 Z jame0313 Meteors (POI11_met) C++17
74 / 100
1798 ms 32568 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ld = long double;
using pll = pair<ll, ll>;
using tii = tuple<int, int, int>;
// and so on
int arr[300001];
int goal[300001];
vector<vector<int> > lst, listeners;
vector<tii> Event, query;
struct bit {
    ll tree[1 << 21], siz;
    void init(int x) {
        for (siz = 1; siz < x; siz <<= 1)
            ;
    }
    void clear() {
        for (int i = 0; i <= siz; i++) tree[i] = 0;
    }
    void add(int pos, ll x) {
        while (pos <= siz) {
            tree[pos] += x;
            pos += (pos & -pos);
        }
    }
    ll sum(int pos) {
        ll ret = 0;
        while (pos) {
            ret += tree[pos];
            pos &= (pos - 1);
        }
        return ret;
    }
} Tree;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int Q, N, M;
    cin >> Q >> N;
    lst.resize(Q + 1);
    Tree.init(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> arr[i];
        lst[arr[i]].push_back(i);
    }
    for (int i = 1; i <= Q; i++) {
        cin >> goal[i];
    }
    cin >> M;
    listeners.resize(M + 1);
    for (int i = 0; i < M; i++) {
        int l, r, c;
        cin >> l >> r >> c;
        Event.push_back({l, r, c});
    }
    for (int i = 0; i <= Q; i++) {
        query.push_back({0, M-1, 0});
    }
    for (int t = 0; t < 32; t++) {
        Tree.clear();
        for (int i = 1; i <= Q; i++) {
            auto& [l, r, m] = query[i];
            if (l <= r) {
                m = (l + r) >> 1;
                listeners[m].push_back(i);
            }
        }
        for (int i = 0; i < M; i++) {
            auto [l, r, c] = Event[i];
            if(l<=r){
                Tree.add(l, c);
                Tree.add(r+1, -c);
            }
            else{
                Tree.add(l, c);
                Tree.add(N+1, -c);
                Tree.add(1, c);
                Tree.add(r+1, -c);
            }
            for (int j : listeners[i]) {
                auto& [l, r, m] = query[j];
                ll sum = 0;
                for (int k : lst[j]) sum += Tree.sum(k);
                if (sum < goal[j]) {
                    l = m + 1;
                } else
                    r = m - 1;
            }
            listeners[i].clear();
        }
    }
    for (int i = 1; i <= Q; i++) {
        auto [l,r,m] = query[i];
        if(l == M) cout<<"NIE\n";
        else cout<<l+1<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 440 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 3768 KB Output is correct
2 Correct 179 ms 7536 KB Output is correct
3 Correct 119 ms 6668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 4920 KB Output is correct
2 Correct 177 ms 6040 KB Output is correct
3 Correct 193 ms 7696 KB Output is correct
4 Correct 37 ms 3788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 4200 KB Output is correct
2 Correct 185 ms 8060 KB Output is correct
3 Correct 76 ms 2956 KB Output is correct
4 Correct 160 ms 7236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 3196 KB Output is correct
2 Correct 152 ms 6056 KB Output is correct
3 Correct 110 ms 4564 KB Output is correct
4 Correct 160 ms 8848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1765 ms 32568 KB Output is correct
2 Incorrect 1798 ms 25560 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1647 ms 31132 KB Output is correct
2 Incorrect 1159 ms 24044 KB Output isn't correct
3 Halted 0 ms 0 KB -