QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#377815#5052. Rectangle Flip 2InfinityNS#WA 2ms5776kbC++171.8kb2024-04-05 18:16:192024-04-05 18:16:20

Judging History

你现在查看的是最新测评结果

  • [2024-04-05 18:16:20]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5776kb
  • [2024-04-05 18:16:19]
  • 提交

answer

#include<bits/stdc++.h>

#define f first
#define s second
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;

const int N=501;
ll sm[N*N];
vector<pair<int,int>> st[N];
int mn[N];
int lb[N],rb[N];
int main(){
    int n,m;
    scanf("%i %i",&n,&m);
    for(int i=0;i<n;i++){
        st[i].reserve(m);
    }
    vector<pair<int,int>> ord;
    for(int i=0;i<n*m;i++){
        int x,y;
        scanf("%i %i",&x,&y);
        x--;y--;
        ord.pb({x,y});
    }
    for(int l=0;l<n;l++){
        for(int r=0;r<m;r++)mn[r]=n;
        for(int r=l;r<n;r++)st[r].clear();
        for(int i=0;i<n*m;i++){
            auto p=ord[i];
            if(p.f<l)continue;
            if(mn[p.s]<p.f)continue;
            //printf("%i %i\n",p.f,p.s);
            for(int r=p.f;r<mn[p.s];r++){
                st[r].pb({i,p.s});
            }
            mn[p.s]=p.f;
        }
        for(int r=l;r<n;r++){
            for(int i=0;i<m;i++)lb[i]=rb[i]=-1;
            assert(sz(st[r])==m);
            for(int j=m-1;j>=0;j--){
                auto p=st[r][j];
                int y=p.s;
                int ind=p.f;
                lb[y]=y;
                rb[y]=y;
                //printf("%i %i: %i %i\n",l,r,p.f,p.s);
                if(y&&lb[y-1]!=-1){
                    lb[y]=lb[y-1];
                }
                if(y!=m-1&&rb[y+1]!=-1){
                    rb[y]=rb[y+1];
                }
                rb[lb[y]]=rb[y];
                lb[rb[y]]=lb[y];
                int cc=rb[y]-lb[y]+1;
                if(ind)sm[ind-1]+=cc;
            }
        }
    }
    for(int i=N*N-2;i>=0;i--){
        sm[i]+=sm[i+1];
    }
    for(int i=0;i<n*m;i++){
        printf("%lld\n",sm[i]);
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 5736kb

input:

2 2
1 1
2 1
1 2
2 2

output:

5
3
1
0

result:

ok 4 number(s): "5 3 1 0"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 5776kb

input:

5 5
3 2
2 5
4 3
5 5
2 1
3 5
1 5
3 3
3 4
3 1
4 2
1 4
2 2
4 1
2 3
1 3
5 1
2 4
5 2
4 5
1 1
5 3
4 4
5 4
1 2

output:

145
117
93
84
70
65
60
54
45
42
38
31
26
24
21
18
14
13
10
8
6
4
2
1
0

result:

wrong answer 1st numbers differ - expected: '153', found: '145'