bzoj 1176

时间:2023-03-09 01:10:47
bzoj 1176

收获:

  1、min, max, sum, 属于判定,等询问是”对象对答案贡献独立“,即不需要其他对象就了能更新答案,并保证只要所有对象更新过答案,那么该答案就是正确的。大概这就是所谓的”修改独立“。

  2、处理”先把所有修改给你,再询问“问题时,这道题要用到降维思想,就是处理的顺序也是一维,并且这维可以差分。那么就将二维问题变成了一维问题。(最值不满足差分性)。

 /**************************************************************
Problem: 1176
User: idy002
Language: C++
Result: Accepted
Time:6896 ms
Memory:42684 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#define N 2000010
#define M 340010
using namespace std; typedef long long dnt; struct Proc {
int opt, tim;
int id;
int x, y, v;
int t, b;
Proc(){}
Proc( int opt, int tim, int x, int y, int v ):opt(opt),tim(tim),id(),x(x),y(y),v(v),t(),b() {}
Proc( int opt, int tim, int id, int y, int t, int b ):opt(opt),tim(tim),id(id),x(),y(y),v(),t(t),b(b) {}
bool operator<( const Proc &o ) const {
return y<o.y || (y==o.y && opt<o.opt);
}
}; int n, m, s;
Proc proc[M]; int idp;
dnt bit[N];
dnt ans[N]; int ida; void modify( int x, int v ) {
for( int i=x; i<=n; i+=i&-i )
bit[i] += v;
}
dnt query( int x ) {
dnt rt=0LL;
for( int i=x; i; i-=i&-i )
rt += bit[i];
return rt;
}
dnt query( int t, int b ) {
return query(b)-query(t-);
}
void cdq( int lf, int rg ) {
if( lf==rg ) return;
int mid=(lf+rg)>>;
cdq(lf,mid);
cdq(mid+,rg);
sort( proc+lf, proc+rg+ );
for( int i=lf; i<=rg; i++ ) {
Proc &p = proc[i];
if( p.opt== && p.tim<=mid ) {
modify( p.x, p.v );
} else if( p.opt== && p.tim>mid ) {
ans[p.id] -= query( p.t, p.b );
} else if( p.opt== && p.tim>mid ) {
ans[p.id] += query( p.t, p.b );
}
}
for( int i=lf; i<=rg; i++ ) {
Proc &p = proc[i];
if( p.opt== && p.tim<=mid )
modify( p.x, -p.v );
}
}
int main() {
scanf( "%d%d", &s, &n );
for( int i=; ; i++ ) {
int opt;
scanf( "%d", &opt );
if( opt== ) break;
if( opt== ) {
int x, y, v;
scanf( "%d%d%d", &x, &y, &v );
idp++;
proc[idp] = Proc( opt, idp, x, y, v );
} else {
int x0, y0, x1, y1;
scanf( "%d%d%d%d", &x0, &y0, &x1, &y1 );
ida++;
ans[ida] += (dnt) (y1-y0+)*(x1-x0+)*s;
idp++;
proc[idp] = Proc( , idp, ida, y0-, x0, x1 );
idp++;
proc[idp] = Proc( , idp, ida, y1, x0, x1 );
}
}
cdq( , idp );
for( int i=; i<=ida; i++ )
printf( "%lld\n", ans[i] );
}