Submission #993405

# Submission time Handle Problem Language Result Execution time Memory
993405 2024-06-05T14:45:33 Z Kryptonchk Meteors (POI11_met) C++17
100 / 100
1129 ms 44096 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;


//#include <atcoder/all>
//using namespace atcoder;

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 clear() {
		fill(a.begin(), a.end(), 0);
	}
    
    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(m + 1);
	for(int i = 1; i <= m; i++) {
		int pos;
		cin >> pos;
		p[pos].push_back(i);
	}

	vector<int> tar(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> tar[i];
	}
	
	int t;
	cin >> t;

	vector<int> l(t + 1), r(t + 1), val(t + 1);
	for(int i = 1; i <= t; i++){
		cin >> l[i] >> r[i] >> val[i];
	}
	queue<tuple<int, int, vector<int>>> q;
	vector<int> ids;
	for(int i = 1; i <= n; i++){
		ids.push_back(i);
	}
	q.emplace(1, t + 1, ids);
	
	Fenwick<int64_t> f(m);
	
	vector<int> res(n + 1);
	int ptr = 0;
	while(q.size()) {
		auto [ll, rr, id] = q.front();
		q.pop();
		
		if(ll == rr) {
			for(auto x : id) {
				res[x] = ll;
			}
			continue;
		}
		
		int mm = ll + (rr - ll) / 2;
		if(ptr > mm){
			ptr = 0;
			f.clear();		
		}
		while(ptr < mm){
			ptr++;
			f.add(l[ptr], val[ptr]);
			f.add(r[ptr] + 1, -val[ptr]);
			if(l[ptr] > r[ptr]) {
				f.add(1, val[ptr]);
			}
		}

		vector<int> to_left, to_right;
		for(auto x : id) {
			int64_t cur = tar[x];
			for(auto y : p[x]) {
				cur -= f.sum(y);
				if(cur <= 0) {
					break;
				}
			}
			
			if(cur <= 0) {
				to_left.push_back(x);
			}else {
				to_right.push_back(x);
			}
		}

		if(to_left.size()) {
			q.emplace(ll, mm, to_left);
		}

		if(to_right.size()) {
			q.emplace(mm + 1, rr, to_right);
		}

	}

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

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

	while(t--){
		O_O();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 3932 KB Output is correct
2 Correct 75 ms 5248 KB Output is correct
3 Correct 71 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 4692 KB Output is correct
2 Correct 70 ms 4696 KB Output is correct
3 Correct 69 ms 5404 KB Output is correct
4 Correct 16 ms 3656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 4104 KB Output is correct
2 Correct 88 ms 5736 KB Output is correct
3 Correct 15 ms 1624 KB Output is correct
4 Correct 63 ms 5396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3932 KB Output is correct
2 Correct 74 ms 4948 KB Output is correct
3 Correct 54 ms 4180 KB Output is correct
4 Correct 78 ms 6092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 551 ms 29704 KB Output is correct
2 Correct 119 ms 24100 KB Output is correct
3 Correct 104 ms 5720 KB Output is correct
4 Correct 1022 ms 41332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 609 ms 28824 KB Output is correct
2 Correct 422 ms 22748 KB Output is correct
3 Correct 37 ms 6224 KB Output is correct
4 Correct 1129 ms 44096 KB Output is correct