#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 <cstring>
#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;
}
}
inline ll read() {
char c = getchar();
ll x = 0, s = 1;
while (c < '0' || c > '9') {
if (c == '-')
s = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * s;
}
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;
}
const int N = 2.5e6 + 90;
ll dif[N];
ll n,m;
void Call_Me_When_You_Want(int l,int r,ll cur,ll add)
{
if(r<l)
{
return;
}
dif[l]+=cur;
dif[l+1]-=cur;;
dif[l+1]+=add;;
dif[r+1]-=add;;
ll xc=-1*(cur+(r-l)*add);
dif[r+1]+=xc;;
dif[r+2]-=xc;;
}
void solve1()
{
ll p=read();
for(int asp=0;asp<p;asp++)
{
ll j=read(),i=read(),final=read(),add=read();
ll l=max(1ll,j-(final/add));
ll cur=final-(add*(j-l));
Call_Me_When_You_Want(l,j-1,cur,add);
ll r=min(m,j+(final/add));
Call_Me_When_You_Want(j,r,final,-add);
}
vll pre={0};
for(int i=1;i<=m;i++)
{
pre.pb(pre.back()+dif[i]);
}
for(int j=0;j<2;j++)
{
for(int i=1;i<=m;i++)
{
pre[i]+=pre[i-1];
}
}
ll q=read();
while(q--)
{
ll y1=read(),x1=read(),y2=read(),x2=read();
ll sum=0,cell=(y2-y1+1)*(x2-x1+1);
sum=pre[y2]-pre[y1-1];
ld cur=((ld)sum/(ld)cell);
cur+=0.5;
cout<<(ll)cur<<'\n';
}
}
void solve()
{
m=read(),n=read();
if(n==1)
{
solve1();
return;
}
ll p=read();
vector<vll> grid(n+2,vll(m+2));
auto pre=grid;
for(int i=0;i<p;i++)
{
ll y=read(),x=read(),a=read(),b=read();
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=read();
while(q--)
{
ll y1=read(),x1=read(),y2=read(),x2=read();
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;
}
Compilation message
nuclearia.cpp: In function 'void solve1()':
nuclearia.cpp:87:21: warning: unused variable 'i' [-Wunused-variable]
87 | ll j=read(),i=read(),final=read(),add=read();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
43056 KB |
Output is correct |
2 |
Correct |
20 ms |
2740 KB |
Output is correct |
3 |
Correct |
18 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
37832 KB |
Output is correct |
2 |
Correct |
20 ms |
2704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
39812 KB |
Output is correct |
2 |
Correct |
24 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
53072 KB |
Output is correct |
2 |
Correct |
23 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
37576 KB |
Output is correct |
2 |
Correct |
22 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
15548 KB |
Output is correct |
2 |
Correct |
20 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
42456 KB |
Output is correct |
2 |
Correct |
24 ms |
2896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
220 ms |
34068 KB |
Output is correct |
2 |
Correct |
31 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
54436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
53912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1051 ms |
39772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1084 ms |
39772 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1095 ms |
41304 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1050 ms |
39732 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |