#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;
}
struct SegmentTree
{
int sum=0,lazy=0;
bool do_lazy=0;
SegmentTree* next[2];
int s,e;
SegmentTree(int l,int r)
{
s=l;
e=r;
if(s!=e)
{
int mid=(s+e)/2;
next[0]=new SegmentTree(s,mid);
next[1]=new SegmentTree(mid+1,e);
}
}
void push()
{
if(!do_lazy)
return;
sum+=(e-s+1)*lazy;
if(s!=e)
{
next[0]->lazy+=lazy;
next[1]->lazy+=lazy;
next[0]->do_lazy=1;
next[1]->do_lazy=1;
}
lazy=0;
do_lazy=0;
}
void Update(int l,int r,int val)
{
push();
if(e<l or r<s)
return;
// if(val==-2)
// {
// cout<<"We are at "<<s<<' '<<e<<' '<<l<<' '<<r<<' '<<sum<<endl;
// }
if(l<=s and e<=r)
{
lazy+=val;
do_lazy=1;
// cout<<"Getting lazy "<<lazy<<' '<<do_lazy<<endl;
push();
// cout<<"Sum now "<<sum<<endl;
return;
}
next[0]->Update(l,r,val);
next[1]->Update(l,r,val);
sum=next[0]->sum+next[1]->sum;
}
int get(int l,int r)
{
push();
if(e<l or r<s)
{
return 0;
}
if(l<=s and e<=r)
{
return sum;
}
int ans=next[0]->get(l,r)+next[1]->get(l,r);
sum=next[0]->sum+next[1]->sum;
return ans;
}
};
SegmentTree* dif;
ll n,m;
void Call_Me_When_You_Want(int l,int r,int cur,int add)
{
if(r<l)
{
return;
}
// dif[l]+=cur;
// dif[l+1]+=add;
// dif[r]+=add;
// dif[r+1]-=(cur+(add*(r-l)))
// a[l]+=cur;
// a[l+1]+=cur+add;
// | += |
// a[r]+=cur+(add*(r-l))
// cout<<"Adding "<<cur<<" To range "<<l<<' '<<l<<endl;
dif->Update(l,l,cur);
// for(int i=1;i<=m;i++)
// {
// cout<<dif->get(i,i)<<' ';;
// }
// cout<<endl;
// cout<<"Adding "<<add<<" To range "<<l+1<<' '<<r<<endl;
dif->Update(l+1,r,add);
// for(int i=1;i<=m;i++)
// {
// cout<<dif->get(i,i)<<' ';;
// }
// cout<<endl;
// cout<<"Adding "<<-1*(cur+(r-l)*add)<<" To range "<<r+1<<' '<<r+1<<endl;
dif->Update(r+1,r+1,-1*(cur+(r-l)*add));
// for(int i=1;i<=m;i++)
// {
// cout<<dif->get(i,i)<<' ';;
// }
// cout<<endl;
}
void solve()
{
cin>>m>>n;
ll p;
cin>>p;
dif=new SegmentTree(0,m+3);
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->get(0,i));
// cout<<dif->get(0,i)<<' ';;
}
// cout<<endl;
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);
if(n==1)
{
sum=pre[y2]-pre[y1-1];
}
ld cur=((ld)sum/(ld)cell);
cur+=0.5;
cout<<(ll)cur<<endl;
}
}
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 |
Incorrect |
497 ms |
270244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
460 ms |
268816 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
751 ms |
269764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
467 ms |
104336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
276 ms |
848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
350 ms |
52424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1038 ms |
249284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1064 ms |
255596 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
498 ms |
4432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
481 ms |
4176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
377 ms |
3924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
495 ms |
4496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |