Submission #56004

# Submission time Handle Problem Language Result Execution time Memory
56004 2018-07-09T10:02:17 Z moonrabbit2 None (KOI17_shell) C++11
100 / 100
563 ms 27324 KB
#include <bits/stdc++.h>
#define N 1505
using namespace std;
typedef long long ll;
int n,x,y,d,a[N][N],ddp[N][N],tree[N][N],s[N],e[N];
ll ans;
char c;
// [s,e] add v
void add(int x,int s,int e,int v)
{
    for(;s<=n;s+=s&-s)
        tree[x][s]+=v;
    for(;e<=n;e+=e&-e)
        tree[x][e]-=v;
}
int dp(int x,int y)
{
    int res=ddp[x][y];
    for(;y;y-=y&-y)
        res+=tree[x][y];
    return res;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
            ddp[i][j]=a[i][j]+max(ddp[i-1][j],ddp[i][j-1]);
            ans+=ddp[i][j];
        }
    }
    cout<<ans<<'\n';
    for(int q=1;q<=n;q++){
        cin>>c>>x>>y;
        d=(c=='U'?1:-1);
        for(int i=1;i<=n;i++)
            s[i]=n+1,e[i]=0;
        s[x]=e[x]=y;
        for(int xx=x,yy=y;;){
            if(yy<n&&max(dp(xx-1,yy+1),dp(xx,yy))+d==max(dp(xx-1,yy+1),dp(xx,yy)+d))
                yy++;
            else
                xx++;
            if(xx>n)
                break;
            e[xx]=yy;
        }
        for(int xx=x,yy=y;;){
            if(xx<n&&max(dp(xx+1,yy-1),dp(xx,yy))+d==max(dp(xx+1,yy-1),dp(xx,yy)+d)){
                xx++;
            }
            else
                yy++;
            if(yy>n||e[xx]<yy)
                break;
            s[xx]=min(s[xx],yy);
        }
        for(int i=x;i<=n;i++){
            if(s[i]<=e[i]){
                ans+=(e[i]-s[i]+1)*d;
                add(i,s[i],e[i]+1,d);
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1656 KB Output is correct
2 Correct 5 ms 1656 KB Output is correct
3 Correct 5 ms 1688 KB Output is correct
4 Correct 4 ms 1688 KB Output is correct
5 Correct 4 ms 1744 KB Output is correct
6 Correct 4 ms 1748 KB Output is correct
7 Correct 4 ms 1764 KB Output is correct
8 Correct 4 ms 1764 KB Output is correct
9 Correct 4 ms 1820 KB Output is correct
10 Correct 4 ms 1824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 20436 KB Output is correct
2 Correct 197 ms 20512 KB Output is correct
3 Correct 238 ms 27028 KB Output is correct
4 Correct 308 ms 27028 KB Output is correct
5 Correct 338 ms 27028 KB Output is correct
6 Correct 181 ms 27028 KB Output is correct
7 Correct 185 ms 27028 KB Output is correct
8 Correct 377 ms 27028 KB Output is correct
9 Correct 289 ms 27028 KB Output is correct
10 Correct 223 ms 27028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1656 KB Output is correct
2 Correct 5 ms 1656 KB Output is correct
3 Correct 5 ms 1688 KB Output is correct
4 Correct 4 ms 1688 KB Output is correct
5 Correct 4 ms 1744 KB Output is correct
6 Correct 4 ms 1748 KB Output is correct
7 Correct 4 ms 1764 KB Output is correct
8 Correct 4 ms 1764 KB Output is correct
9 Correct 4 ms 1820 KB Output is correct
10 Correct 180 ms 20436 KB Output is correct
11 Correct 197 ms 20512 KB Output is correct
12 Correct 238 ms 27028 KB Output is correct
13 Correct 308 ms 27028 KB Output is correct
14 Correct 338 ms 27028 KB Output is correct
15 Correct 181 ms 27028 KB Output is correct
16 Correct 185 ms 27028 KB Output is correct
17 Correct 377 ms 27028 KB Output is correct
18 Correct 289 ms 27028 KB Output is correct
19 Correct 223 ms 27028 KB Output is correct
20 Correct 298 ms 27108 KB Output is correct
21 Correct 304 ms 27200 KB Output is correct
22 Correct 334 ms 27280 KB Output is correct
23 Correct 563 ms 27316 KB Output is correct
24 Correct 523 ms 27316 KB Output is correct
25 Correct 510 ms 27316 KB Output is correct
26 Correct 213 ms 27316 KB Output is correct
27 Correct 211 ms 27316 KB Output is correct
28 Correct 303 ms 27316 KB Output is correct
29 Correct 283 ms 27316 KB Output is correct
30 Correct 540 ms 27316 KB Output is correct
31 Correct 560 ms 27324 KB Output is correct
32 Correct 226 ms 27324 KB Output is correct
33 Correct 233 ms 27324 KB Output is correct
34 Correct 4 ms 1824 KB Output is correct