Submission #381218

# Submission time Handle Problem Language Result Execution time Memory
381218 2021-03-24T18:57:19 Z aryan12 Meteors (POI11_met) C++17
74 / 100
1474 ms 39308 KB
#include <bits/stdc++.h>
#pragma GCC optimize "trapv"
 
using namespace std;
 
vector<int64_t> req;
vector<vector<int64_t>> land;
vector<array<int64_t, 3>> D;
vector<int64_t> ans;
 
int64_t n, m;
 
struct BIT{
	vector<int64_t> tree;
	int64_t n;
 
	void init(int64_t _n){
		n = _n;
		tree.resize(n+1);
	}
 
	void upd(int64_t idx, int64_t val){
		for(; idx <= n; idx += (idx&(-idx)))
			tree[idx] += val;
	}
 
	void upd(int64_t l, int64_t r, int64_t val){
		upd(l, val);
		upd(r+1, -val);
	}
 
	int64_t query(int64_t idx){
		int64_t sum = 0;
		for(; idx > 0; idx -= (idx&(-idx)))
			sum += tree[idx];
		return sum;
	}
 
}bit;
 
void PBS(int64_t l, int64_t r, vector<int64_t> active){
	if(active.size() == 0)
		return;
 
	if(r - l == 1){
		for(int64_t i : active)
			ans[i] = l;
		return;
	}
 
	int64_t mid = (l + r) >> 1;
	
	for(int64_t i = l; i < mid; i++){
		if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], int64_t(D[i][2]));
		else{
			bit.upd(D[i][0], m, int64_t(D[i][2]));
			bit.upd(1, D[i][1], int64_t(D[i][2]));
		}
	}
	
	vector<int64_t> nq[2];
	
	for(int64_t i : active){
		int64_t sum = 0;
		for(int64_t v : land[i]) sum += bit.query(v);
		if(sum >= req[i]) nq[0].push_back(i);
		else{
			req[i] -= sum;
			nq[1].push_back(i);
		}
	}
 
	for(int64_t i = l; i < mid; i++){
		if(D[i][0] <= D[i][1]) bit.upd(D[i][0], D[i][1], int64_t(-D[i][2]));
		else{
			bit.upd(D[i][0], m, int64_t(-D[i][2]));
			bit.upd(1, D[i][1], int64_t(-D[i][2]));
		}
	}
 
	PBS(l, mid, nq[0]);
	PBS(mid, r, nq[1]);
}
 
int32_t main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
 
	cin >> n >> m;
	land.resize(n+1), req.resize(n+1);
	ans.resize(n+1);
 
	bit.init(m);
 
	for(int64_t i = 1; i <= m; i++){
		int64_t x;
		cin >> x;
		land[x].push_back(i);
	}
 
	for(int64_t i = 1; i <= n; i++)
		cin >> req[i];
 
	int64_t k;
	cin >> k;
 
	D.resize(k+1);
	for(int64_t i = 1; i <= k; i++){
		auto& [l, r, upd] = D[i];
		cin >> l >> r >> upd;
	}
 
	vector<int64_t> cur(n);
	iota(cur.begin(), cur.end(), 1);
	PBS(1, k+2, cur);
 
	for(int64_t i = 1; i <= n; i++)
		if(ans[i] == k+1) cout << "NIE\n";
		else cout << ans[i] << '\n';
 
	return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 4 ms 492 KB Output is correct
3 Correct 4 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
3 Correct 4 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 4204 KB Output is correct
2 Correct 238 ms 10696 KB Output is correct
3 Correct 247 ms 3988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 3664 KB Output is correct
2 Correct 259 ms 3564 KB Output is correct
3 Correct 164 ms 7656 KB Output is correct
4 Correct 76 ms 4588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 3432 KB Output is correct
2 Correct 253 ms 8588 KB Output is correct
3 Correct 51 ms 1644 KB Output is correct
4 Correct 228 ms 4460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 2408 KB Output is correct
2 Correct 263 ms 3780 KB Output is correct
3 Correct 153 ms 2796 KB Output is correct
4 Correct 282 ms 6508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1474 ms 39308 KB Output is correct
2 Runtime error 192 ms 24564 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1355 ms 32480 KB Output is correct
2 Runtime error 182 ms 24676 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -