#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#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;
}
const int N = 2.5e6 + 90;
struct ST {
#define lc (n << 1)
#define rc ((n << 1) | 1)
long long t[4 * N], lazy[4 * N];
ST() {
memset(t, 0, sizeof t);
memset(lazy, 0, sizeof lazy);
}
inline void push(int n, int b, int e) {
if (lazy[n] == 0) return;
t[n] = t[n] + lazy[n] * (e - b + 1);
if (b != e) {
lazy[lc] = lazy[lc] + lazy[n];
lazy[rc] = lazy[rc] + lazy[n];
}
lazy[n] = 0;
}
inline long long combine(long long a,long long b) {
return a + b;
}
inline void pull(int n) {
t[n] = t[lc] + t[rc];
}
void upd(int n, int b, int e, int i, int j, long long v) {
push(n, b, e);
if (j < b || e < i) return;
if (i <= b && e <= j) {
lazy[n] = v; //set lazy
push(n, b, e);
return;
}
int mid = (b + e) >> 1;
upd(lc, b, mid, i, j, v);
upd(rc, mid + 1, e, i, j, v);
pull(n);
}
long long query(int n, int b, int e, int i, int j) {
push(n, b, e);
if (i > e || b > j) return 0; //return null
if (i <= b && e <= j) return t[n];
int mid = (b + e) >> 1;
return combine(query(lc, b, mid, i, j), query(rc, mid + 1, e, i, j));
}
};
ST dif;
ll n,m;
void Call_Me_When_You_Want(int l,int r,int cur,int add)
{
if(r<l)
{
return;
}
dif.upd(1,1,m+1,l,l,cur);
dif.upd(1,1,m+1,l+1,r,add);
dif.upd(1,1,m+1,r+1,r+1,-1*(cur+(r-l)*add));
}
void solve()
{
cin>>m>>n;
ll p;
cin>>p;
for(int asp=0;asp<p;asp++)
{
ll i,j,final,add;
cin>>j>>i>>final>>add;
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.query(1,1,m+1,1,i));
}
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[y2]-pre[y1-1];
ld cur=((ld)sum/(ld)cell);
cur+=0.5;
cout<<(ll)cur<<'\n';
}
}
signed 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 |
320 ms |
190892 KB |
Output is correct |
2 |
Correct |
64 ms |
159632 KB |
Output is correct |
3 |
Correct |
75 ms |
159068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
363 ms |
191672 KB |
Output is correct |
2 |
Correct |
77 ms |
159256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
157016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
156764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
398 ms |
190580 KB |
Output is correct |
2 |
Correct |
67 ms |
159548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
199 ms |
167352 KB |
Output is correct |
2 |
Correct |
62 ms |
159412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
73 ms |
158736 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
151 ms |
163264 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
874 ms |
190580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
904 ms |
191000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
285 ms |
158788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
271 ms |
158648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
175 ms |
158764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
311 ms |
158924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |