#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <fstream>
using namespace std;
#define vll vector<ll>
#define sll set<ll>
#define vstr vector<string>
#define ll long long
#define ld long double
#define supra main
#define pb push_back
#define add insert
#define rall(x) rbegin(x),rend(x)
#define all(x) (x).begin(),(x).end()
#define I ios_base::sync_with_stdio(false);
#define Hear cin.tie(NULL);
#define Shots cout.tie(NULL);
#define Ratatatata
ll powmod(ll a,ll b,ll modulo)
{
if(b==0){
return 1;
}
ll temp=powmod(a,b/2,modulo);
if(b%2==0){
return (temp*temp)%modulo;
}
else{
return (a*((temp*temp)%modulo))%modulo;
}
}
bool Prime(ll n){
if (n <= 1)
return false;
for (ll i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
void solve()
{
ll n,m;
cin>>m>>n;
ll p;
cin>>p;
ll grid[n+2][m+2]={};
auto pre=grid;
for(int i=0;i<p;i++)
{
ll x,y,a,b;
cin>>y>>x>>a>>b;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
grid[i][j]+=max(0ll,a-b*(max(abs(i-x),abs(j-y))));
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
pre[i][j]=(pre[i][j-1]+pre[i-1][j]+grid[i][j]-pre[i-1][j-1]);
}
}
ll q;
cin>>q;
while(q--)
{
ll y1,x1,y2,x2;
cin>>y1>>x1>>y2>>x2;
ll sum=0,cell=(y2-y1+1)*(x2-x1+1);
sum=pre[x2][y2]-pre[x1-1][y2]-pre[x2][y1-1]+pre[x1-1][y1-1];
ld cur=((ld)sum/(ld)cell);
cur+=0.5;
cout<<(ll)cur<<'\n';
}
}
int supra(){
I Hear Shots Ratatatata
cout<<setprecision(1000);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll tqwertyuiop=1;
// cin>>tqwertyuiop;
for(int tp=1;tp<=tqwertyuiop;tp++)
{
// cout<<"Case #"<<tp<<": ";
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
59132 KB |
Output is correct |
2 |
Correct |
49 ms |
2788 KB |
Output is correct |
3 |
Correct |
45 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
59128 KB |
Output is correct |
2 |
Correct |
52 ms |
3024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
20076 KB |
Output is correct |
2 |
Correct |
46 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
21852 KB |
Output is correct |
2 |
Correct |
55 ms |
2764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
147 ms |
61196 KB |
Output is correct |
2 |
Correct |
52 ms |
2896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
178 ms |
26428 KB |
Output is correct |
2 |
Correct |
49 ms |
2644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
188 ms |
22380 KB |
Output is correct |
2 |
Correct |
50 ms |
2900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
18392 KB |
Output is correct |
2 |
Correct |
47 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1030 ms |
59136 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1034 ms |
59136 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1052 ms |
20088 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1087 ms |
20056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1055 ms |
20316 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1060 ms |
20084 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |