답안 #462296

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
462296 2021-08-10T10:31:18 Z kingfran1907 Nuclearia (CEOI15_nuclearia) C++14
15 / 100
1000 ms 212876 KB
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long llint;

const int maxn = 3e6+10;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 18;
const int off = 1 << logo;
const int treesiz = off << 1;

int n, q;
int w, h;
vector< llint > niz[maxn];
vector< llint > pref[maxn];
llint ac[maxn];
llint pr[maxn];

int main() {
	scanf("%d%d", &w, &h);
	if (h == 1) {
		scanf("%d", &n);
		for (int i = 0; i < n; i++) {
			int x, y;
			llint a, b;
			scanf("%d%d%lld%lld", &x, &y, &a, &b);
			
			llint dis = a / b;
			int l = max(1LL, x - dis);
			int r = min((llint)w, x + dis);
			
			pr[l - 1] += a - b * (x - l);
			pr[l] -= a - b * (x - l);
			pr[l] += b;
			
			pr[x] -= b + b;
			
			pr[r] -= a - b * (r - x); 
			pr[r] += b;
			pr[r + 1] += a - b * (r - x);
		}
		
		llint tren = pr[0];
		for (int i = 1; i <= w; i++) {
			ac[i] = ac[i - 1] + tren;
			tren += pr[i];
		}
		for (int i = 1; i <= w; i++) printf("%lld ", ac[i]);
		printf("\n");
		
		for (int i = 1; i <= w; i++) ac[i] += ac[i - 1];
		
		scanf("%d", &q);
		while (q--) {
			int x1, y1, x2, y2;
			scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
			
			llint sum = ac[x2] - ac[x1 - 1];
			llint cnt = x2 - x1 + 1;
			
			llint sol = sum / cnt;
			llint rem = sum % cnt;
			
			if (rem * 2 >= cnt) printf("%lld\n", sol + 1);
			else printf("%lld\n", sol);
		}
		return 0;
	}
	
	for (int i = 0; i < w; i++) 
		for (int j = 0; j < h; j++)
			niz[i].push_back(0);
			
	scanf("%d", &n);
	while (n--) {
		int x, y;
		llint a, b;
		scanf("%d%d%lld%lld", &x, &y, &a, &b); x--, y--;
		
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < h; j++) {
				int dis = max(abs(i - x), abs(j - y));
				llint kol = max(0LL, a - b * dis);
				niz[i][j] += kol;
			}
		}
	}
	
	for (int i = 0; i <= w; i++) {
		for (int j = 0; j <= h; j++) {
			pref[i].push_back(0);
		}
	}
	
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			pref[i + 1][j + 1] = niz[i][j];
			pref[i + 1][j + 1] += pref[i + 1][j];
		}
	}
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			pref[i + 1][j + 1] += pref[i][j + 1];
		}
	}
	
	scanf("%d", &q);
	while (q--) {
		int x1, y1, x2, y2;
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2); x1--, y1--;
		
		llint sum = pref[x2][y2] - pref[x1][y2] - pref[x2][y1] + pref[x1][y1];
		llint cnt = (llint)(x2 - x1) * (y2 - y1);
		
		llint sol = sum / cnt;
		llint rem = sum % cnt;
		
		if (rem * 2 >= cnt) printf("%lld\n", sol + 1);
		else printf("%lld\n", sol);
	}
	return 0;
}

Compilation message

nuclearia.cpp: In function 'int main()':
nuclearia.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d%d", &w, &h);
      |  ~~~~~^~~~~~~~~~~~~~~~
nuclearia.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
nuclearia.cpp:30:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |    scanf("%d%d%lld%lld", &x, &y, &a, &b);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d", &q);
      |   ~~~~~^~~~~~~~~~
nuclearia.cpp:60:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
nuclearia.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |   scanf("%d%d%lld%lld", &x, &y, &a, &b); x--, y--;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:111:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
nuclearia.cpp:114:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |   scanf("%d%d%d%d", &x1, &y1, &x2, &y2); x1--, y1--;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 432 ms 191060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 412 ms 190432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 338 ms 181352 KB Output is correct
2 Correct 176 ms 143564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 329 ms 182028 KB Output is correct
2 Correct 176 ms 143472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 529 ms 190664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 335 ms 164068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 470 ms 186780 KB Output is correct
2 Correct 177 ms 143700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 635 ms 182728 KB Output is correct
2 Correct 163 ms 143556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 693 ms 212876 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 652 ms 212848 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 161336 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 161156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 161456 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 161172 KB Time limit exceeded
2 Halted 0 ms 0 KB -