codeforces 522 A. Vanya and Table

http://codeforces.com/problemset/problem/552/A 题意:一个100*100的网格。然后给n个矩形。每个格子中填上包含这个格子的矩形的个数。最后问所有格子的和。 思路:树状数组搞得...然而..直接求所有矩形面积的和就可以啊喂。。o(n)。。。111qqz你个炒鸡大菜鸡。

/* ***********************************************
Author :111qqz
Created Time :2015年12月14日 星期一 14时01分14秒
File Name :code/cf/problem/552A.cpp
************************************************ */
 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
 1using namespace std;
 2const double eps = 1E-8;
 3const int dx4[4]={1,0,0,-1};
 4const int dy4[4]={0,-1,1,0};
 5const int inf = 0x3f3f3f3f;
 6const int N=1E2+7;
 7int n;
 8int c[N][N];
 9struct Point
10{
11    int x1,y1,x2,y2;
1    void input()
2    {
3	scanf("%d %d",&x1,&y1);
4	scanf("%d %d",&x2,&y2);
5    }
6}p[N];
 1int lowbit( int x)
 2{
 3    return x&(-x);
 4}
 5void update( int x,int y,int delta)
 6{
 7    for ( int i = x ; i <= 105 ; i += lowbit(i))
 8    {
 9	for ( int j =  y ; j <= 105 ; j +=lowbit(j))
10	{
11	    c[i][j] +=delta;
12	}
13    }
14}
 1int sum ( int x,int y)
 2{
 3    int res = 0 ;
 4    for ( int i =  x;  i>= 1 ; i-=lowbit(i))
 5    {
 6	for ( int j = y ; j >= 1 ; j-=lowbit(j))
 7	{
 8	    res += c[i][j];
 9	   // cout<<"res:"<<res<<endl;
10	}
11    }
 1    return res;
 2}
 3int main()
 4{
 5	#ifndef  ONLINE_JUDGE 
 6	freopen("code/in.txt","r",stdin);
 7  #endif
 8	ms(c,0);
 9	cin>>n;
10	for ( int i = 0 ; i < n; i++) p[i].input();
 1//	puts("aahhhhhh");
 2	for ( int i = 0 ; i <n ; i++)
 3	{
 4	    update(p[i].x2+1,p[i].y2+1,1);
 5	   // cout<<"www?"<<endl;
 6	    update(p[i].x2+1,p[i].y1,-1);
 7	    update(p[i].x1,p[i].y2+1,-1);
 8	    update(p[i].x1,p[i].y1,1);
 9	//    puts("yyyyepppppp");
10	}
11	int ans = 0;
12	for ( int i = 1 ; i <= 101 ; i ++)
13	    for ( int j = 1 ; j <= 101;  j++)
		ans += sum(i,j);
	cout<<ans<<endl;
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}