QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#166789#7105. Pixel Artucup-team139AC ✓427ms19736kbC++232.1kb2023-09-06 18:11:022023-09-06 18:11:02

Judging History

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

  • [2023-09-06 18:11:02]
  • 评测
  • 测评结果:AC
  • 用时:427ms
  • 内存:19736kb
  • [2023-09-06 18:11:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int MAXN = 100'005;
int ds[MAXN], comp;
void reset() {
	comp = 0;
}
void create(int x) {
	ds[x] = x;
	comp++;
}
int f(int x) {
	if (ds[x] != x)return ds[x] = f(ds[x]);
	return x;
}
void add(int x, int y) {
	int a = f(x), b = f(y);
	if (a == b)return;
	ds[a] = b;
	comp--;
}

void solve(int t) {
	int n, m, k;
	cin >> n >> m >> k;
	reset();
	long long sum = 0, curropen = 0;
	vector<set<array<int, 3>>> opz(n + 2);
	set<array<int, 3>> ds;

	for (int i = 1; i <= k; i++) {
		int r1, c1, r2, c2;
		cin >> r1 >> c1 >> r2 >> c2;

		opz[r1].insert({c1, c2 + 1, i});
		opz[r2 + 1].insert({c1, c2 + 1, -i});
	}

	for (int i = 1; i <= n; i++) {
		int prevr = -1, previd = -1;
		for (auto [l, r, id] : opz[i]) {
			if (id > 0) {
                auto it = ds.lower_bound({l,0,0});
                create(id);
                if(prevr==l)add(previd,id);
                
                if(it != ds.begin()){
                    it--;
                    auto pre = *it;
                    
                    if(pre[1]>l || (pre[1]==l && opz[i].find({pre[0],pre[1],-pre[2]})==opz[i].end())){
                        add(id,pre[2]);
                    }
                    it++;
                }
                
                while(it != ds.end() && (*it)[0]<r){
                    add(id,(*it)[2]);
                    it++;
                }
                
                if(it!=ds.end() && (*it)[0]==r && opz[i].find({(*it)[0],(*it)[1],-(*it)[2]})==opz[i].end()){
                    add(id,(*it)[2]);
                }
                
                prevr = r;
                previd = id;
			}
		}

		for (auto [l, r, id] : opz[i]) {
			if (id > 0) {
				curropen += (r - l);
				ds.insert({l, r, id});
			} else {
				curropen -= (r - l);
				ds.erase({l, r, -id});
			}
		}
		sum += curropen;
		cout << sum << " " << comp << "\n";
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	cin >> t;
	for (int i = 1; i <= t; i++)solve(i);

	return 0;
}

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

詳細信息

Test #1:

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

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: 427ms
memory: 19736kb

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