QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797775#7105. Pixel Artlichenyu_acAC ✓352ms16548kbC++141.6kb2024-12-03 18:04:462024-12-03 18:04:47

Judging History

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

  • [2024-12-03 18:04:47]
  • 评测
  • 测评结果:AC
  • 用时:352ms
  • 内存:16548kb
  • [2024-12-03 18:04:46]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
const int N=1e5+10;

int n,m,ans,cnt;
int R1[N],C1[N],R2[N],C2[N],fa[N];
vector<int> add[N],del[N];

int find(int x){
    return fa[x]==x?x:fa[x]=find(fa[x]);
}

void merge(int x,int y){
    x=find(x),y=find(y);
    if(x==y)return;
    fa[y]=x;
    cnt--;
}

void solve(){
    scanf("%d%*d%d",&n,&m);
    for(int i=1;i<=n+1;i++)add[i].clear(),del[i].clear();
    for(int i=1;i<=m;i++){
        scanf("%d%d%d%d",&R1[i],&C1[i],&R2[i],&C2[i]);
        add[R1[i]].emplace_back(i),del[R2[i]+1].emplace_back(i);
    }
    for(int i=1;i<=m;i++)fa[i]=i;
    ans=cnt=0;
    int tot=0;
    map<pair<int,int>,int> mp;
    for(int i=1;i<=n;i++){
        for(auto x:add[i]){
            auto it=mp.lower_bound(make_pair(C1[x],0));
            if(it!=mp.begin())it=prev(it);
            while(it!=mp.end()&&it->fi.fi<=C2[x]){
                if(it->fi.se>=C1[x])merge(it->se,x);
                it++;
            }
        }
        for(auto x:del[i])tot-=C2[x]-C1[x]+1,mp.erase(make_pair(C1[x],C2[x]));
        for(auto x:add[i]){
            tot+=C2[x]-C1[x]+1;
            mp[make_pair(C1[x],C2[x])]=x;
            auto it=mp.find(make_pair(C1[x],C2[x]));
            if(it!=mp.begin()&&prev(it)->fi.se==C1[x]-1)merge(prev(it)->se,x);
            if(next(it)!=mp.end()&&next(it)->fi.fi==C2[x]+1)merge(next(it)->se,x);
        }
        ans+=tot,cnt+=add[i].size();
        printf("%d %d\n",ans,cnt);
    }
}

int main(){
    int T;scanf("%d",&T);
    while(T--)solve();
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10284kb

input:

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

output:

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

result:

ok 7 lines

Test #2:

score: 0
Accepted
time: 352ms
memory: 16548kb

input:

2130
2 5 2
1 1 1 2
2 3 2 5
2 5 2
1 1 1 3
2 3 2 5
3 3 3
1 1 1 2
3 1 3 2
1 3 2 3
3 100 51
1 2 2 2
1 4 2 4
1 6 2 6
1 8 2 8
1 10 2 10
1 12 2 12
1 14 2 14
1 16 2 16
1 18 2 18
1 20 2 20
1 22 2 22
1 24 2 24
1 26 2 26
1 28 2 28
1 30 2 30
1 32 2 32
1 34 2 34
1 36 2 36
1 38 2 38
1 40 2 40
1 42 2 42
1 44 2 44
...

output:

2 1
5 2
3 1
6 1
3 1
4 1
6 2
50 50
100 50
200 1
50 50
150 1
200 1
2 1
4 1
6 1
8 1
10 1
12 1
14 1
16 1
18 1
20 1
22 1
24 1
26 1
28 1
30 1
32 1
34 1
36 1
38 1
40 1
42 1
44 1
46 1
48 1
50 1
52 1
54 1
56 1
58 1
60 1
62 1
64 1
66 1
68 1
70 1
72 1
74 1
76 1
78 1
80 1
82 1
84 1
86 1
88 1
90 1
92 1
94 1
96 1...

result:

ok 355756 lines

Extra Test:

score: 0
Extra Test Passed