QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283154#7105. Pixel ArtzhouzizheTL 2ms9028kbC++142.0kb2023-12-13 22:34:242023-12-13 22:34:25

Judging History

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

  • [2023-12-13 22:34:25]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:9028kb
  • [2023-12-13 22:34:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,K;


vector<int> add[100005],del[100005];
pair<pair<int,int>,pair<int,int>> rec[100005];
int fa[100005];
int getfa(int x){return fa[x]==x?x:fa[x]=getfa(fa[x]);}
map<pair<int,int>,int> M;
int cnt1,cnt2;
void solve(){
	scanf("%d %d %d",&n,&m,&K);
	for(int i=1;i<=K;++i){
		scanf("%d %d %d %d",&rec[i].first.first,&rec[i].first.second,&rec[i].second.first,&rec[i].second.second);
		add[rec[i].first.first].push_back(i);
		del[rec[i].second.first+1].push_back(i);
		fa[i]=i;
	}
	for(int i=1,now=0;i<=n;++i){
		for(int it:add[i]){
			auto itt=M.lower_bound({rec[it].first.second,0});
			if(itt!=M.begin())itt=prev(itt);
			while(itt!=M.end() && itt->first.first<=rec[it].second.second){
				if(itt->first.second>=rec[it].first.second){
//					cerr<<it<<' '<<itt->second<<' '<<rec[it].second.second<<' '<<itt->first.first<<'\n';
					if(getfa(it)!=getfa(itt->second)){
						fa[getfa(it)]=getfa(itt->second);
						cnt2--;
					}
				}
				it++;
			}
		}
		for(int it:del[i]){
			now-=rec[it].second.second-rec[it].first.second+1;
			M.erase({rec[it].first.second,rec[it].second.second});
		}
		for(int it:add[i]){
			cnt2++;
			now+=rec[it].second.second-rec[it].first.second+1;
			M[{rec[it].first.second,rec[it].second.second}]=it;
			auto itt=M.find({rec[it].first.second,rec[it].second.second});
			if(itt!=M.begin() && prev(itt)->first.second==rec[it].first.second-1){
				if(getfa(it)!=getfa(prev(itt)->second)){
					fa[getfa(it)]=getfa(prev(itt)->second);
					cnt2--;
					
				}
			}
			if(itt!=prev(M.end()) && next(itt)->first.first==rec[it].second.second+1){
				if(getfa(it)!=getfa(next(itt)->second)){
					fa[getfa(it)]=getfa(next(itt)->second);
					cnt2--;
					
				}
			}
		}
		cnt1+=now;
		printf("%d %d\n",cnt1,cnt2);
	}
	for(int i=1;i<=n+1;++i)add[i].clear(),del[i].clear();
	cnt1=cnt2=0;
	M.clear();
}


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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Time Limit Exceeded

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 50
50 50
150 1
200 1
2 1
4 -97
6 -96
8 -95
10 -94
12 -93
14 -92
16 -91
18 -90
20 -89
22 -88
24 -87
26 -86
28 -85
30 -84
32 -83
34 -82
36 -81
38 -80
40 -79
42 -78
44 -77
46 -76
48 -75
50 -74
52 -73
54 -72
56 -71
58 -70
60 -69
62 -68
64 -67
66 -66
68 -65
70...

result: