답안 #922362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922362 2024-02-05T12:38:06 Z Onur_Ilgaz Meteors (POI11_met) C++17
74 / 100
459 ms 45440 KB
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
const int N = 300005;
vector <int> station[N];
int from[N], to[N], add[N], need[N], ans[N];
int point;

struct BIT {
	int n;
	vector <int> t;
	void init(int size) {
		n = size;
		t.resize(n + 1);
	}
	void update(int till, int val) {
		while(till) {
			t[till] += val;
			till = till - (till & (-till));
		}
	}
	int query(int ind) {
		int res = 0;
		while(ind <= n) {
			res += t[ind];
			ind = ind + (ind & (-ind));
		}
		return res;
	}
}t;

void f(int l, int r, vector<int>&owner) {
	if(owner.empty()) return;
	if(l == r) {
		for(auto it:owner) {
			ans[it] = l;
		}
		return;
	}
	int m = (l + r) / 2;
	while(point < m) {
		point++;
		int ul = from[point], ur = to[point], val = add[point];
		t.update(ul-1, -val);
		t.update(ur, val);
		if(ur < ul) {
			t.update(t.n, val);
		}
	}
	while(point > m) {
		int ul = from[point], ur = to[point], val = -add[point];
		t.update(ul-1, -val);
		t.update(ur, val);
		if(ur < ul) {
			t.update(t.n, val);
		}
		point--;
	}
	// now point is at m
	vector <int> left, right;
	for(int it : owner) {
		int sum = 0;
		for(int itt : station[it]) {
			sum += t.query(itt);
		}
		if(sum >= need[it]) {
			left.push_back(it);
		}
		else {
			right.push_back(it);
		}
	}
	owner.clear();
	f(l, m, left);
	f(m + 1, r, right);
}

int32_t main() {
	fast
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int in;
		cin >> in;
		station[in].push_back(i+1);
	}
	for(int i = 1; i <= n; i++) {
		cin >> need[i];
	}
	int q;
	cin >> q;
	for(int i = 1; i <= q; i++) {
		cin >> from[i] >> to[i] >> add[i];
	}
	vector <int> owner(n);
	for(int i = 0; i < n; i++) owner[i] = i+1;
	t.init(m);
	f(1, q + 1, owner);
	for(int i = 1; i <= n; i++) {
		if(ans[i] > q) cout << "NIE\n";
		else cout << ans[i] << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16988 KB Output is correct
2 Correct 5 ms 17040 KB Output is correct
3 Correct 5 ms 17064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 16988 KB Output is correct
2 Correct 4 ms 16984 KB Output is correct
3 Correct 5 ms 16984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 19536 KB Output is correct
2 Correct 50 ms 24836 KB Output is correct
3 Correct 49 ms 19692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 19548 KB Output is correct
2 Correct 48 ms 19568 KB Output is correct
3 Correct 52 ms 23672 KB Output is correct
4 Correct 21 ms 19792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 19196 KB Output is correct
2 Correct 39 ms 23944 KB Output is correct
3 Correct 15 ms 17500 KB Output is correct
4 Correct 50 ms 19988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 18904 KB Output is correct
2 Correct 49 ms 19868 KB Output is correct
3 Correct 31 ms 19032 KB Output is correct
4 Correct 56 ms 23124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 45440 KB Output is correct
2 Incorrect 146 ms 29520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 377 ms 42128 KB Output is correct
2 Incorrect 119 ms 28380 KB Output isn't correct
3 Halted 0 ms 0 KB -