Submission #1004765

# Submission time Handle Problem Language Result Execution time Memory
1004765 2024-06-21T14:13:39 Z Kryptonchk Meteors (POI11_met) C++17
74 / 100
901 ms 24604 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
using LL = long long;


template <typename T>
struct Fenwick {
    int n;
	int bit_num;
    vector<T> a;
    
    Fenwick(int n_ = 0) {
        init(n_);
    }
    
    void init(int n_) {
        n = n_;
		bit_num = __lg(n_) + 1;
        a.assign((1 << bit_num) + 1, T{});
    }
    
    void add(int x, const T &v) {
        for (int i = x; !(i >> bit_num); i += i & -i) {
            a[i] = a[i] + v;
        }
    }
    
    T sum(int x) {
        T ans{};
        for (int i = x; i > 0; i -= i & -i) {
            ans = ans + a[i];
        }
        return ans;
    }
    
    T rangeSum(int l, int r) {
        return sum(r) - sum(l);
    }
    
    int select(T k) {
        int x = 0;
        for (int i = bit_num - 1; i >= 0; i--) {
            if (a[x + (1 << i)] < k) {
                k -= a[x + (1 << i)];
                x = x + (1 << i);
            }
        }
        return x + 1;
    }
};

void O_o() {
	int n, m;
	cin >> n >> m;
	
	vector<vector<int>> p(n + 1);
	for (int i = 0; i < m; i++) {
		int pos;
		cin >> pos;
		p[pos].push_back(i + 1);
	}
	
	vector<int> need(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> need[i];
	}

	int Q;
	cin >> Q;
	
	vector<int> l(Q + 1), r(Q + 1), val(Q + 1);
	for (int i = 1; i <= Q; i++) {
		cin >> l[i] >> r[i] >> val[i];
	}
	queue<tuple<int, int, vector<int>>> q;
	{
		vector<int> id;
		for (int i = 0; i < n; i++) {
			id.push_back(i + 1);
		}
		q.emplace(1, Q + 1, id);
	}
	
	Fenwick<LL> f(m + 1);
	vector<int> res(n + 1);
	int ptr = 0;
	while (q.size()) {
		auto [L, R, id] = q.front();
		q.pop();

		int M = L + (R - L) / 2;
		if (R == L) {
			for (auto x : id) {
				res[x] = M;
			}
			continue;
		}

		while (M < ptr) {
			f.init(m + 1);
			ptr = 0;
		}
		while (ptr < M) {
			ptr++;
			f.add(l[ptr], val[ptr]);
			f.add(r[ptr] + 1, -val[ptr]);
			if (r[ptr] < l[ptr]) {
				f.add(1, val[ptr]);	
			}
		}

		vector<int> ok, neg;
		for (auto x : id) {
			LL now = need[x];
			for(auto pos : p[x]) {
				now -= f.sum(pos);
			}
			
			if (now <= 0) {
				ok.push_back(x);
			} else {
				neg.push_back(x);
			}
		}

		if (ok.size()) {
			q.emplace(L, M, ok);	
		}
		if (neg.size()) {
			q.emplace(M + 1, R, neg);	
		}
	}

	for (int i = 1; i <= n; i++) {
		if (res[i] > Q) {
			cout << "NIE\n";
		} else {
			cout << res[i] << '\n';
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t = 1;
	while (t--) {
		O_o();
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 412 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 2908 KB Output is correct
2 Correct 77 ms 4560 KB Output is correct
3 Correct 71 ms 4228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 3668 KB Output is correct
2 Correct 72 ms 3716 KB Output is correct
3 Correct 79 ms 4660 KB Output is correct
4 Correct 17 ms 3124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 3176 KB Output is correct
2 Correct 88 ms 5048 KB Output is correct
3 Correct 15 ms 1624 KB Output is correct
4 Correct 65 ms 4580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2876 KB Output is correct
2 Correct 81 ms 3920 KB Output is correct
3 Correct 52 ms 2908 KB Output is correct
4 Correct 82 ms 5500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 573 ms 24604 KB Output is correct
2 Incorrect 901 ms 16992 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 641 ms 23360 KB Output is correct
2 Incorrect 541 ms 15724 KB Output isn't correct
3 Halted 0 ms 0 KB -