답안 #217866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217866 2020-03-31T05:16:26 Z arnold518 Pyramid Base (IOI08_pyramid_base) C++14
51 / 100
5000 ms 111520 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e6;
const int MAXP = 4e5;
const ll INF = 1e18;

struct Rect
{
	int x1, y1, x2, y2, w;
};

struct Line
{
	int x, y1, y2, w;
	bool operator < (const Line &p) const { return x<p.x; }
};

int N, M, P;
ll B;
Rect A[MAXP+10];

struct SEG
{
	ll tree[MAXN*4+10], lazy[MAXN*4+10];
	void init()
	{
		memset(tree, 0, sizeof(tree));
		memset(lazy, 0, sizeof(lazy));
	}
	void busy(int node, int tl, int tr)
	{
		tree[node]+=lazy[node];
		if(tl!=tr) lazy[node*2]+=lazy[node], lazy[node*2+1]+=lazy[node];
		lazy[node]=0;
	}
	void update(int node, int tl, int tr, int l, int r, ll v)
	{
		busy(node, tl, tr);
		if(r<tl || tr<l) return;
		if(l<=tl && tr<=r)
		{
			lazy[node]+=v;
			busy(node, tl, tr);
			return;
		}
		int mid=tl+tr>>1;
		update(node*2, tl, mid, l, r, v);
		update(node*2+1, mid+1, tr, l, r, v);
		tree[node]=min(tree[node*2], tree[node*2+1]);
	}
}seg;

bool solve(int d)
{
	int i, j;
	vector<Line> V;
	ll val=INF;
	for(i=1; i<=P; i++)
	{
		V.push_back({A[i].x1, A[i].y1, A[i].y2+d-1, A[i].w});
		V.push_back({A[i].x2+d, A[i].y1, A[i].y2+d-1, -A[i].w});
	}
	sort(V.begin(), V.end());
	seg.init();

	for(i=0; i<V.size();)
	{
		int x=V[i].x;
		for(; i<V.size() && V[i].x==x; i++)
		{
			seg.update(1, d, N, V[i].y1, V[i].y2, V[i].w);
		}
		seg.busy(1, d, N);
		if(x>=d && x<=M) val=min(val, seg.tree[1]);
	}
	if(val<=B) return true;
	return false;
}

int main()
{
	int i, j;

	scanf("%d%d%lld%d", &M, &N, &B, &P);
	for(i=1; i<=P; i++) scanf("%d%d%d%d%d", &A[i].x1, &A[i].y1, &A[i].x2, &A[i].y2, &A[i].w);

	int lo=0, hi=min(N, M)+1;
	while(lo+1<hi)
	{
		int mid=lo+hi>>1;
		if(solve(mid)) lo=mid;
		else hi=mid;
	}
	printf("%d\n", lo);
}

Compilation message

pyramid_base.cpp: In member function 'void SEG::update(int, int, int, int, int, ll)':
pyramid_base.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid=tl+tr>>1;
           ~~^~~
pyramid_base.cpp: In function 'bool solve(int)':
pyramid_base.cpp:71:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<V.size();)
           ~^~~~~~~~~
pyramid_base.cpp:74:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(; i<V.size() && V[i].x==x; i++)
         ~^~~~~~~~~
pyramid_base.cpp:60:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:95:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid=lo+hi>>1;
           ~~^~~
pyramid_base.cpp:87:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
pyramid_base.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%lld%d", &M, &N, &B, &P);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:90:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=1; i<=P; i++) scanf("%d%d%d%d%d", &A[i].x1, &A[i].y1, &A[i].x2, &A[i].y2, &A[i].w);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 62968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 62976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 62848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 136 ms 63104 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 63096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 63096 KB Output is correct
2 Correct 217 ms 63096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 213 ms 63104 KB Output is correct
2 Correct 196 ms 63096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 161 ms 63864 KB Output is correct
2 Correct 185 ms 63768 KB Output is correct
3 Correct 190 ms 63624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 407 ms 64780 KB Output is correct
2 Correct 470 ms 64700 KB Output is correct
3 Correct 393 ms 64704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 568 ms 65736 KB Output is correct
2 Correct 124 ms 65432 KB Output is correct
3 Correct 396 ms 65428 KB Output is correct
4 Correct 924 ms 65936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 803 ms 66136 KB Output is correct
2 Correct 1014 ms 66064 KB Output is correct
3 Incorrect 390 ms 66092 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 648 ms 66640 KB Output is correct
2 Correct 1341 ms 66716 KB Output is correct
3 Correct 1317 ms 66600 KB Output is correct
4 Correct 1313 ms 66524 KB Output is correct
5 Correct 1343 ms 66652 KB Output is correct
6 Incorrect 358 ms 66540 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5070 ms 87792 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5054 ms 103688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5083 ms 111520 KB Time limit exceeded
2 Halted 0 ms 0 KB -