BZOJ3208: 花神的秒题计划Ⅰ

Description

 
背景【backboard】:
 Memphis等一群蒟蒻出题中,花神凑过来秒题……
 
描述【discribe】:
 花花山峰峦起伏,峰顶常年被雪,Memphis打算帮花花山风景区的人员开发一个滑雪项目。
 
 我们可以把风景区看作一个n*n的地图,每个点有它的初始高度,滑雪只能从高处往低处滑【严格大于】。但是由于地势经常变动【比如雪崩、滑坡】,高度经常变化;同时,政府政策规定对于每个区域都要间歇地进行保护,防止环境破坏。现在,滑雪项目的要求是给出每个n*n个点的初始高度,并给出m个命令,C a b c表示坐标为a,b的点的高度改为c;S a b c d表示左上角为a,b右下角为c,d的矩形地区开始进行保护,即不能继续滑雪;B a b c d表示左上角为a b,右下角为c d的矩形地区取消保护,即可以开始滑雪;Q表示询问现在该风景区可以滑雪的最长路径为多少。对于每个Q要作一次回答。
 
 花神一看,这不是超简单!立刻秒出了标算~
 

Input

第一行n,第二行开始n*n的地图,意义如上;接下来一个m,然后是m个命令,如上
 

Output

对于每一个Q输出单独一行的回答
 

Sample Input

5
1 2 3 4 5
10 9 8 7 6
11 12 13 14 15
20 19 18 17 16
21 22 23 24 25
5
C 1 1 3
Q
S 1 3 5 5
S 3 1 5 5
Q

Sample Output

24
3

样例解释:
第一个Q路线为:25->24->23->22….->3->2
第二个Q的路线为:10->9->2

HINT

100%的数据:1<=n<=700;1<=m<=1000000;其中Q、S、B操作总和<=100;

题中所有数据不超过2*10^9

 
什么东西。。。
#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,BufferSize,stdin);
        tail=(head=buffer)+l;
    }
    return *head++;
}
inline int read() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
const int maxn=710;
const int INF=2147483647;
int n,A[maxn][maxn],B[maxn][maxn],f[maxn][maxn];
int dp(int x,int y) {
    if(x<1||y<1||x>n||y>n) return 0;
    if(B[x][y]) return 0;
    int& ans=f[x][y];
    if(ans) return ans;
    if(A[x][y]>A[x-1][y]) ans=max(ans,dp(x-1,y)+1);
    if(A[x][y]>A[x+1][y]) ans=max(ans,dp(x+1,y)+1);
    if(A[x][y]>A[x][y-1]) ans=max(ans,dp(x,y-1)+1);
    if(A[x][y]>A[x][y+1]) ans=max(ans,dp(x,y+1)+1);
    return ans=max(ans,1);
}
int main() {
    n=read();
    rep(i,1,n) rep(j,1,n) A[i][j]=read();
    dwn(i,read(),1) {
        char c=Getchar();while(!isalpha(c)) c=Getchar();
        if(c=='C') {
            int x=read(),y=read();
            A[x][y]=read();
        }
        else if(c=='S') {
            int a=read(),b=read(),c=read(),d=read();
            rep(i,a,c) rep(j,b,d) B[i][j]=1;
        }
        else if(c=='B') {
            int a=read(),b=read(),c=read(),d=read();
            rep(i,a,c) rep(j,b,d) B[i][j]=0;
        }
        else {
            int ans=0;memset(f,0,sizeof(f));
            rep(i,1,n) rep(j,1,n) if(A[i][j]!=INF) ans=max(ans,dp(i,j));
            printf("%d
",ans);
        }
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/wzj-is-a-juruo/p/5045879.html