답안 #265404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
265404 2020-08-14T18:22:30 Z TadijaSebez Nuclearia (CEOI15_nuclearia) C++11
30 / 100
1000 ms 85752 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200050;
int x[N],y[N],a[N],b[N],rng[N];
int xl[N],xr[N],yl[N],yr[N];
int dist(int x1,int y1,int x2,int y2){return max(abs(x1-x2),abs(y1-y2));}
int get(int i,int X,int Y){return max((ll)0,a[i]-(ll)b[i]*dist(x[i],y[i],X,Y));}
int main(){
	int H,W,n,q;
	scanf("%i %i %i",&H,&W,&n);
	for(int i=1;i<=n;++i)scanf("%i %i %i %i",&x[i],&y[i],&a[i],&b[i]),rng[i]=a[i]/b[i];
	scanf("%i",&q);
	for(int i=1;i<=q;++i)scanf("%i %i %i %i",&xl[i],&yl[i],&xr[i],&yr[i]);
	if(H>W){
		swap(H,W);
		for(int i=1;i<=n;++i)swap(x[i],y[i]);
		for(int i=1;i<=q;++i)swap(xl[i],yl[i]),swap(xr[i],yr[i]);
	}
	vector<ll> fir(W+2,0),add(W+2,0);
	vector<vector<ll>> cell(H,vector<ll>(W,0));
	for(int i=1;i<=n;++i){
		if(x[i]<=rng[i]){
			for(int j=1;j<=W;++j)fir[j]+=get(i,0,j);
		}
	}
	for(int i=1;i<=H;++i){
		for(int o=1;o<=n;++o){
			int t=i<=x[o]?x[o]-i:i-x[o]-1;
			if(t<=rng[o]){
				int dif=t==rng[o]?get(o,i,y[o])-get(o,i-1,y[o]):(i<=x[o]?b[o]:-b[o]);
				add[max(1,y[o]-t)]+=dif;
				add[min(W+1,y[o]+t+1)]-=dif;
			}
		}
		ll sum=0;
		for(int j=1;j<=W;++j){
			sum+=add[j];
			cell[i-1][j-1]=sum+fir[j];
			cell[i-1][j-1]+=(i!=1?cell[i-2][j-1]:0)+(j!=1?cell[i-1][j-2]:0)-(i!=1&&j!=1?cell[i-2][j-2]:0);
		}
	}
	for(int i=1;i<=q;++i){
		ll ans=cell[xr[i]-1][yr[i]-1]-(xl[i]!=1?cell[xl[i]-2][yr[i]-1]:0)-(yl[i]!=1?cell[xr[i]-1][yl[i]-2]:0)+(xl[i]!=1&&yl[i]!=1?cell[xl[i]-2][yl[i]-2]:0);
		ll sz=(xr[i]-xl[i]+1)*(yr[i]-yl[i]+1);
		ll out=ans/sz;
		if((ans%sz)*2>=sz)out++;
		printf("%lld\n",out);
	}
	return 0;
}

Compilation message

nuclearia.cpp:3: warning: ignoring #pragma comment  [-Wunknown-pragmas]
    3 | #pragma comment(linker, "/stack:200000000")
      | 
nuclearia.cpp: In function 'int main()':
nuclearia.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |  scanf("%i %i %i",&H,&W,&n);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:16:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  for(int i=1;i<=n;++i)scanf("%i %i %i %i",&x[i],&y[i],&a[i],&b[i]),rng[i]=a[i]/b[i];
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nuclearia.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%i",&q);
      |  ~~~~~^~~~~~~~~
nuclearia.cpp:18:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |  for(int i=1;i<=q;++i)scanf("%i %i %i %i",&xl[i],&yl[i],&xr[i],&yr[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 78584 KB Output is correct
2 Correct 113 ms 6008 KB Output is correct
3 Correct 85 ms 5496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 78584 KB Output is correct
2 Correct 104 ms 5844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 20096 KB Output is correct
2 Correct 93 ms 5936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 22912 KB Output is correct
2 Correct 110 ms 5904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 232 ms 81804 KB Output is correct
2 Correct 112 ms 6136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 312 ms 34808 KB Output is correct
2 Correct 99 ms 5976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 25592 KB Output is correct
2 Correct 103 ms 6136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 237 ms 23036 KB Output is correct
2 Correct 121 ms 5880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1102 ms 85752 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1096 ms 85624 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 845 ms 29036 KB Output is correct
2 Execution timed out 1058 ms 27000 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 27060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1084 ms 28024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1100 ms 27128 KB Time limit exceeded
2 Halted 0 ms 0 KB -