답안 #1034888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034888 2024-07-25T20:46:52 Z xnqs Meteors (POI11_met) C++17
74 / 100
486 ms 65536 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>
 
struct Operation {
	int64_t l, r, amt;
	Operation():
		l(0), r(0), amt(0) {}
	Operation(int64_t l, int64_t r, int64_t amt):
		l(l), r(r), amt(amt) {}
};
 
struct ParallelBSQuery {
	int64_t color;
	int64_t l, r, m;
	ParallelBSQuery():
		color(0), l(0), r(0), m(0) {}
	ParallelBSQuery(int64_t color, int64_t l, int64_t r):
		color(color), l(l), r(r), m((l+r)>>1) {}
};
 
int64_t x, q, ops;
int64_t color[600005];
int64_t target[600005];
int64_t ans[600005];
int64_t tree[2400005];
int64_t lazy[2400005];
std::vector<Operation> operations;
std::vector<ParallelBSQuery> queries;
std::vector<int64_t> owned_by[600005];
 
void push(int64_t node, int64_t l, int64_t r) {
	tree[node] += lazy[node];
	if (l!=r) {
		lazy[node<<1] += lazy[node];
		lazy[node<<1|1] += lazy[node];
	}
	lazy[node] = 0;
}
 
void update(int64_t node, int64_t l, int64_t r, int64_t st, int64_t fi, int64_t val) {
	push(node,l,r);
	if (l>fi||r<st) {
		return;
	}
	if (st<=l&&r<=fi) {
		lazy[node] += val;
		push(node,l,r);
		return;
	}
 
	int64_t m = (l+r)>>1;
	update(node<<1,l,m,st,fi,val);
	update(node<<1|1,m+1,r,st,fi,val);
	tree[node] = tree[node<<1] + tree[node<<1|1];
}
 
int64_t query(int64_t node, int64_t l, int64_t r, int64_t st, int64_t fi) {
	push(node,l,r);
	if (l>fi||r<st) {
		return 0;
	}
	if (st<=l&&r<=fi) {
		return tree[node];
	}
 
	int64_t m = (l+r)>>1;
	return query(node<<1,l,m,st,fi) + query(node<<1|1,m+1,r,st,fi);
}
 
int64_t get_sum(int64_t color) {
	int64_t ret = 0;
	for (const auto& i : owned_by[color]) {
		ret += query(1,1,x,i,i);
	}
	return ret;
}
 
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
 
	std::cin >> q >> x;
	for (int64_t i = 1; i <= x; i++) {
		std::cin >> color[i];
		owned_by[color[i]].emplace_back(i);
	}
 
	for (int64_t i = 1; i <= q; i++) {
		std::cin >> target[i];
	}
 
	std::cin >> ops;
	operations.reserve(ops);
	for (int64_t i = 0, l, r, amt; i < ops; i++) {
		std::cin >> l >> r >> amt;
		operations.emplace_back(l,r,amt);
	}
 
	for (int64_t i = 0; i < q; i++) {
		ans[i+1] = -1;
		queries.emplace_back(i+1,0,ops-1);
	}
 
	for (int64_t iterations = 0; iterations < 19; iterations++) {
		memset(tree,0,sizeof(tree));
		memset(lazy,0,sizeof(lazy));
		std::sort(queries.begin(),queries.end(),[](const ParallelBSQuery& a, const ParallelBSQuery& b) {
			return a.m < b.m;
		});
 
		int64_t scanline = 0;
		for (auto& [color, l, r, m] : queries) {
			if (l>r) {
				continue;
			}
 
			while (scanline<=m) {
				auto [i, j, amt] = operations[scanline];
				if (i>j) {
					update(1,1,x,1,j,amt);
					update(1,1,x,i,x,amt);
				}
				else {
					update(1,1,x,i,j,amt);
				}
				++scanline;
			}
 
			int64_t cand = get_sum(color);
			if (cand>=target[color]) {
				ans[color] = m;
				r = m-1;
			}
			else {
				l = m+1;
			}
 
			m = (l+r)>>1;
		}
	}
 
	for (int64_t i = 1; i <= q; i++) {
		if (ans[i]==-1) std::cout << "NIE\n";
		else std::cout << ans[i]+1 << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 57948 KB Output is correct
2 Correct 60 ms 57948 KB Output is correct
3 Correct 51 ms 57948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 58156 KB Output is correct
2 Correct 42 ms 57948 KB Output is correct
3 Correct 42 ms 58204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 402 ms 60876 KB Output is correct
2 Correct 471 ms 62260 KB Output is correct
3 Correct 435 ms 61564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 420 ms 61416 KB Output is correct
2 Correct 412 ms 61480 KB Output is correct
3 Correct 486 ms 62156 KB Output is correct
4 Correct 165 ms 59860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 256 ms 60876 KB Output is correct
2 Correct 379 ms 62156 KB Output is correct
3 Correct 107 ms 59740 KB Output is correct
4 Correct 454 ms 61820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 238 ms 60780 KB Output is correct
2 Correct 413 ms 61648 KB Output is correct
3 Correct 409 ms 61028 KB Output is correct
4 Correct 446 ms 62408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 98 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 99 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -