QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#163531#7105. Pixel ArtoscaryangWA 3ms27640kbC++142.5kb2023-09-04 10:15:332023-09-04 10:15:34

Judging History

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

  • [2023-09-04 10:15:34]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:27640kb
  • [2023-09-04 10:15:33]
  • 提交

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<=m;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<=q;i++) {
		for(auto u:ad[i]) {
			auto [l,r,id] = u; ++tot;
			for(auto it = S.lower_bound(node{l,0,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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 27640kb

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 1
3 1
6 1
3 1
4 1
6 2

result:

wrong answer 2nd lines differ - expected: '5 2', found: '5 1'