QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#163540#7105. Pixel ArtoscaryangAC ✓246ms37000kbC++142.5kb2023-09-04 10:28:362023-09-04 10:28:37

Judging History

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

  • [2023-09-04 10:28:37]
  • 评测
  • 测评结果:AC
  • 用时:246ms
  • 内存:37000kb
  • [2023-09-04 10:28:36]
  • 提交

answer

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

#define ll long long
#define ull unsigned long long
#define db double
#define mkp make_pair
#define pii pair<int,int>
#define vc vector
#define pb emplace_back
#define mem(a) memset(a,0,sizeof(a))
//#define int long long

const int N = 5e5+5, P = 1e9+7;
const int inf = 0x3f3f3f3f;
//const ll inf = 0x3f3f3f3f3f3f3f3f;
mt19937 gen(time(0));

//in&out
inline int read() {
	int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch=='-'), ch = getchar();
	while(isdigit(ch)) x = (x*10)+(ch^48), ch=getchar(); return w?-x:x;
}
inline void write(int x) { if(x<0) putchar('-'), x = -x; if(x>9) write(x/10); putchar(x%10+'0'); }
inline void writec(int x) { write(x); putchar(32); }
inline void writee(int x) { write(x); putchar(10); }

//calc
inline void inc(int &x,int y) { x += y-P; x += (x>>31)&P; }
inline void dec(int &x,int y) { x -= y; x += (x>>31)&P; }
inline int pls(int x,int y) { x += y-P; x += (x>>31)&P; return x; }
inline void Max(int &x,int y) { if(x<y) x = y; }
inline void Min(int &x,int y) { if(x>y) x = y; }
inline int power(int a,int b) { int res = 1; for(;b;b >>= 1,a = 1ll*a*a%P) if(b&1) res = 1ll*res*a%P; return res; }

int n, m, q, tot;
ll sum, SUM;
struct node { int l, r, id; bool friend operator<(node A,node B) { return A.r<B.r; } };
vc<node> ad[N], dl[N];
set<node> S;

namespace dsu {
	int fa[N];
	inline int get(int x) { return x==fa[x]?x:fa[x] = get(fa[x]); }
	inline void merge(int x,int y) { x = get(x); y = get(y); if(x!=y) fa[x] = y, --tot; }
}
using namespace dsu;

inline void solve() {
	n = read(); m = read(); q = read(); 
	S.clear(); tot = sum = 0; SUM = 0;
	for(int i=1;i<=q;i++) fa[i] = i;
	for(int i=1;i<=n;i++) ad[i].clear(), dl[i].clear();
	for(int i=1;i<=q;i++) {
		int r1 = read(), c1 = read(), r2 = read(), c2 = read();
		ad[r1].pb(node{c1,c2,i}), dl[r2+1].pb(node{c1,c2,i});
	}
	S.insert(node{-1,-1,0}); S.insert(node{m+2,m+2,0});
	for(int i=1;i<=n;i++) {
		for(auto u:ad[i]) {
			auto [l,r,id] = u; ++tot;
			for(auto it = S.lower_bound(node{0,l,0});it!=S.end() && (*it).l<=r;++it) 
				merge(id,(*it).id);
		}
		for(auto u:dl[i]) S.erase(u), SUM -= u.r-u.l+1;
		for(auto u:ad[i]) S.insert(u), SUM += u.r-u.l+1;
		for(auto u:ad[i]) {
			auto it = S.lower_bound(u); --it;
			if((*it).r==u.l-1) merge((*it).id,u.id);
			++it; ++it;
			if((*it).l==u.r+1) merge((*it).id,u.id);
		}
		sum += SUM; 
		printf("%lld %d\n",sum,tot);
	}	
}

signed main() {
	//freopen("a.in","r",stdin);
	int t = read(); while(t--) solve();
	return 0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 28636kb

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: 246ms
memory: 37000kb

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