답안 #39486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39486 2018-01-15T20:13:29 Z farmersrice Nuclearia (CEOI15_nuclearia) C++14
0 / 100
1000 ms 241260 KB
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#pragma GCC target ("avx,tune=native")
//Use above if bruteforcing with lots of small operations. Or just use it anytime, there's no downside. AVX is better slightly
/*
TASK: hidden
LANG: C++11
*/
using namespace std;
typedef long long ll;
typedef pair<int, int> pair2;
typedef pair<int, pair<int, int> > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 200013
#define INF 1000000000000000000LL
#define mp make_pair
#define add push_back
#define remove pop

//only works for H = 1 case

int n;
int w, h, q;
int x[MAXN], y[MAXN];
ll a[MAXN], b[MAXN];

//copy from radoslav11 coding library
struct node_ap
{
	ll sum, lazy, lazy_ap;
	
	node_ap() {sum = 0; lazy = 0; lazy_ap = 0;}
	node_ap(ll val)
	{
		sum = val;
		lazy = 0;
		lazy_ap = 0;
	}
};

node_ap temp, broken;

node_ap merge(node_ap l, node_ap r)
{
	temp.sum = l.sum + r.sum;
	temp.lazy = 0;
	temp.lazy_ap = 0;
	return temp;
}

struct segment_tree_ap
{
	node_ap tr[4 * 2500013];

	void update(int l, int r, int idx)
	{
		if(tr[idx].lazy)
		{
			tr[idx].sum += (r - l + 1) * tr[idx].lazy;

			if(l != r)
			{
				tr[2 * idx + 1].lazy += tr[idx].lazy;
				tr[2 * idx + 2].lazy += tr[idx].lazy;
			}

			tr[idx].lazy = 0;
		}	

		if(tr[idx].lazy_ap)
		{
			int mid = (l + r) >> 1;
			tr[idx].sum += ((r - l + 1) * (r - l + 2) / 2) * tr[idx].lazy_ap;

			if(l != r)
			{
				tr[2 * idx + 1].lazy_ap += tr[idx].lazy_ap;
				tr[2 * idx + 2].lazy_ap += tr[idx].lazy_ap;
				tr[2 * idx + 2].lazy += tr[idx].lazy_ap * (mid - l + 1);
			}

			tr[idx].lazy_ap = 0;
		}
	}

	void init(int l, int r, int idx)
	{
		if(l == r)
		{
			tr[idx] = node_ap();
			return;
		}

		int mid = (l + r) >> 1;
		init(l, mid, 2 * idx + 1);
		init(mid + 1, r, 2 * idx + 2);

		tr[idx] = merge(tr[2 * idx + 1], tr[2 * idx + 2]);
	}	
	
	void update(int qL, int qR, ll val, ll prog, int l, int r, int idx)
	{
		update(l, r, idx);

		if(qL > r || l > qR)
			return;

		if(qL <= l && r <= qR)
		{
			tr[idx].lazy += val + (l - qL) * prog;
			tr[idx].lazy_ap += prog;
			update(l, r, idx);
			return;
		}

		int mid = (l + r) >> 1;
		update(qL, qR, val, prog, l, mid, 2 * idx + 1);
		update(qL, qR, val, prog, mid + 1, r, 2 * idx + 2);

		tr[idx] = merge(tr[2 * idx + 1], tr[2 * idx + 2]);
	}

	node_ap query(int qL, int qR, int l, int r, int idx)
	{
		update(l, r, idx);

		if(l > qR || r < qL)
			return broken;

		if(qL <= l && r <= qR)
			return tr[idx];

		int mid = (l + r) >> 1;
		return merge(query(qL, qR, l, mid, 2 * idx + 1), query(qL, qR, mid + 1, r, 2 * idx + 2));
	}                 
};
segment_tree_ap t;

int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);

	cin >> w >> h;
	assert(h == 1);
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> a[i] >> b[i];
	}

	t.init(0, w, 0); //lol

	for (int i = 0; i < n; i++) {
		ll possible = (a[i] - 1) / b[i];

		if (possible == 0) {
			t.update(x[i], x[i], a[i], 0, 0, w, 0);
		}

		int start = max(1, (int) (x[i] - possible));
		int end = min(w, (int) (x[i] + possible));

		//cout << "plant " << i << " found start, end " << start << ' ' << end << endl;

		ll startval = a[i] - ((x[i] - start) * b[i]);
		//cout << "startval is " << startval << endl;

		t.update(start, x[i], startval - b[i], b[i], 0, w, 0);
		if (x[i] + 1 <= end) t.update(x[i] + 1, end, a[i], -b[i], 0, w, 0);
	}

	cin >> q;
	for (int i = 0; i < q; i++) {
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;

		//cout << "boudns are " <<  x1 << ' ' << x2 << endl;
		ll sum = t.query(x1, x2, 0, w, 0).sum;

		ll cells = x2 - x1 + 1;

		//cout << "query " << i << " found sum " << sum << " cells " << cells << endl;

		ll remainder = sum % cells;
		if ((cells % 2 == 0 && remainder >= cells / 2) || (cells % 2 == 1 && remainder > cells / 2)) {
			cout << 1 + sum / cells << endl;
		} else {
			cout << sum / cells << endl;
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 123 ms 241256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 106 ms 241256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 29 ms 241260 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 241260 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 443 ms 241256 KB Execution timed out (wall clock limit exceeded)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 326 ms 241256 KB Execution timed out (wall clock limit exceeded)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 36 ms 241260 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 241260 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 241256 KB Execution timed out
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 241256 KB Execution timed out
# 결과 실행 시간 메모리 Grader output
1 Runtime error 39 ms 241260 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 39 ms 241260 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 49 ms 241260 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 39 ms 241260 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -