답안 #39671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39671 2018-01-17T03:39:35 Z farmersrice Nuclearia (CEOI15_nuclearia) C++14
15 / 100
1000 ms 241244 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

ll sum[4 * 2500013];
ll lazy[4 * 2500013];
ll lazy_ap[4 * 2500013];

//struct segment_tree_ap {
	//node_ap tr[4 * 2500013];

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

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

			lazy[idx] = 0;
		}	

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

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

			lazy_ap[idx] = 0;
		}
	}
	
	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) {
			lazy[idx] += val + (l - qL) * prog;
			lazy_ap[idx] += prog;
			update(l, r, idx);
			return;
		}

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

		sum[idx] = sum[2 * idx] + sum[2 * idx + 1];
	}

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

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

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

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

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

	scanf("%d%d", &w, &h);
	scanf("%d", &n);
	//cin >> w >> h;
	assert(h == 1);
	//cin >> n;

	for (int i = 0; i < n; i++) {
		//cin >> x[i] >> y[i] >> a[i] >> b[i];
		scanf("%d%d%lld%lld", &x[i], &y[i], &a[i], &b[i]);
	}

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

		if (possible == 0) {
			update(x[i], x[i], a[i], 0, 0, w + 1, 1);
			continue;
		}

		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] - (ll)start) * b[i]);
		//cout << "startval is " << startval << endl;

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

	scanf("%d", &q);//cin >> q;
	for (int i = 0; i < q; i++) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);//cin >> x1 >> y1 >> x2 >> y2;

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

		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)) {
			printf("%lld\n", 1 + sum / cells);//cout << 1 + sum / cells << endl; 
		} else {
			printf("%lld\n", sum / cells);//cout << sum / cells << endl;
		}
	}
	return 0;
}

Compilation message

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:102:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &w, &h);
                       ^
nuclearia.cpp:103:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
nuclearia.cpp:110:52: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%lld%lld", &x[i], &y[i], &a[i], &b[i]);
                                                    ^
nuclearia.cpp:134:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);//cin >> q;
                 ^
nuclearia.cpp:137:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &x1, &y1, &x2, &y2);//cin >> x1 >> y1 >> x2 >> y2;
                                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 241240 KB Output is correct
2 Correct 156 ms 241240 KB Output is correct
3 Correct 99 ms 241240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 241240 KB Output is correct
2 Correct 189 ms 241240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 241244 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 241244 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 803 ms 241240 KB Output is correct
2 Correct 223 ms 241240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 616 ms 241240 KB Output is correct
2 Correct 159 ms 241240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 241244 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 241244 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 241240 KB Execution timed out
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1000 ms 241240 KB Execution timed out
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 241244 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 241244 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 241244 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 241244 KB Execution killed because of forbidden syscall gettid (186)
2 Halted 0 ms 0 KB -