Submission #120981

# Submission time Handle Problem Language Result Execution time Memory
120981 2019-06-25T20:58:55 Z TadijaSebez Pyramid Base (IOI08_pyramid_base) C++11
70 / 100
5000 ms 67060 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=1000050;
const int M=2*N;
const int P=400050;
int root,tsz,mn[M],lzy[M],ls[M],rs[M];
void Set(int &c, int ss, int se, int qs, int qe, int f)
{
	if(qs>qe || qs>se || ss>qe) return;
	if(!c) c=++tsz;
	if(qs<=ss && qe>=se){ lzy[c]+=f;mn[c]+=f;return;}
	int mid=ss+se>>1;
	Set(ls[c],ss,mid,qs,qe,f);
	Set(rs[c],mid+1,se,qs,qe,f);
	mn[c]=min(mn[ls[c]],mn[rs[c]])+lzy[c];
}
void Clear(){ for(int i=1;i<=tsz;i++) ls[i]=rs[i]=mn[i]=lzy[i]=0;tsz=root=0;}
struct Event
{
	int tme,l,r,f;
	Event(int a, int b, int c, int d):tme(a),l(b),r(c),f(d){}
	bool operator < (Event b) const { return tme<b.tme;}
};
int X1[P],X2[P],Y1[P],Y2[P],cost[P],p,n,m,B;
bool Check(int sz)
{
	Clear();
	vector<Event> evs;
	for(int i=1;i<=p;i++)
	{
		evs.pb(Event(X1[i]-sz+1,Y1[i]-sz+1,Y2[i],cost[i]));
		evs.pb(Event(X2[i]+1,Y1[i]-sz+1,Y2[i],-cost[i]));
	}
	sort(evs.begin(),evs.end());
	int lst=0;
	for(int i=0;i<evs.size();i++)
	{
		int t=evs[i].tme-lst;
		lst=evs[i].tme;
		if(t>0 && lst>1 && mn[root]<=B) return 1;
		Set(root,1,m-sz+1,evs[i].l,evs[i].r,evs[i].f);
		if(lst>n-sz+1) break;
	}
	return 0;
}
int main()
{
	scanf("%i %i %i %i",&n,&m,&B,&p);
	for(int i=1;i<=p;i++) scanf("%i %i %i %i %i",&X1[i],&Y1[i],&X2[i],&Y2[i],&cost[i]);
	int top=min(n,m),bot=1,mid,ans=0;
	while(top>=bot)
	{
		mid=top+bot>>1;
		if(Check(mid)) ans=mid,bot=mid+1;
		else top=mid-1;
	}
	printf("%i\n",ans);
	return 0;
}

Compilation message

pyramid_base.cpp: In function 'void Set(int&, int, int, int, int, int)':
pyramid_base.cpp:13:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
pyramid_base.cpp: In function 'bool Check(int)':
pyramid_base.cpp:37:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<evs.size();i++)
              ~^~~~~~~~~~~
pyramid_base.cpp: In function 'int main()':
pyramid_base.cpp:54:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid=top+bot>>1;
       ~~~^~~~
pyramid_base.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i %i %i",&n,&m,&B,&p);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
pyramid_base.cpp:50:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=p;i++) scanf("%i %i %i %i %i",&X1[i],&Y1[i],&X2[i],&Y2[i],&cost[i]);
                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 512 KB Output is correct
2 Correct 19 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 848 KB Output is correct
2 Correct 9 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1148 KB Output is correct
2 Correct 48 ms 1356 KB Output is correct
3 Correct 40 ms 1316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 2988 KB Output is correct
2 Correct 286 ms 3508 KB Output is correct
3 Correct 234 ms 3276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 4536 KB Output is correct
2 Correct 38 ms 2984 KB Output is correct
3 Correct 146 ms 6844 KB Output is correct
4 Correct 451 ms 6444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 344 ms 5820 KB Output is correct
2 Correct 622 ms 7368 KB Output is correct
3 Correct 150 ms 4736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 290 ms 5496 KB Output is correct
2 Correct 860 ms 8792 KB Output is correct
3 Correct 829 ms 8700 KB Output is correct
4 Correct 917 ms 8864 KB Output is correct
5 Correct 930 ms 8604 KB Output is correct
6 Correct 139 ms 5296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5019 ms 39172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5023 ms 57724 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5098 ms 67060 KB Time limit exceeded
2 Halted 0 ms 0 KB -