QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#166496#7105. Pixel ArtCryingTL 1ms22092kbC++144.7kb2023-09-06 13:54:002023-09-06 13:54:00

Judging History

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

  • [2023-09-06 13:54:00]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:22092kb
  • [2023-09-06 13:54:00]
  • 提交

answer

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define SZ(x) (x.size())
typedef long long ll;
using namespace std;
#define int ll
const int MAXN = 1e5+10,MAXM = 1.5e6+10,px[5] = {0,1,0,-1,0},py[5] = {1,0,-1,0,0};
typedef array<int,2> pr;

namespace io {
    const int __SIZE = (1 << 21) + 1;
    char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
    #define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
    inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
    inline void gc (char &x) { x = Gc(); }
    inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
    inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
    inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
        for(; __c > 31 && __c < 127 && __c != ' ' && __c != '\n' && __c != '\r'; ++s, __c = Gc()) *s = __c; *s = 0; }
    template <class I> inline bool gi (I &x) { _eof = 0;
        for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
        for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
    template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
        while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
    struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

int T,n,m,k,r1[MAXN],r2[MAXN],c1[MAXN],c2[MAXN];
int s[MAXN],c[MAXN],pre[MAXN];

int chk(int x,int y){return x>=1 && x<=n && y>=1 && y<=m;}
struct D{
	vector<int>b;
	int sz;
	void clr(){b.clear();b.shrink_to_fit();}
	void add(int x){b.push_back(x);}
	void pr(){
		sort(b.begin(),b.end());
		b.erase(unique(b.begin(),b.end()),b.end());
		sz = b.size();
	}
	int qry(int x){return lower_bound(b.begin(),b.end(),x)-b.begin()+1;}
}dy,rx[MAXN],ry[MAXN];
vector<pr>all;
vector<int>o[MAXN];

int R(int x){return x;}
int C(int x){return dy.qry(x);}
int I(int x,int y){return pre[x-1] + rx[R(x)].qry(y);} 

int fa[MAXM],tag[MAXM],ans;

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;
	ans -= (tag[x] && tag[y]);
	fa[y] = x,tag[x] |= tag[y];
}

void add(int x,int y,int s=5){
	//s=5;
	rep(k,0,4)if(k^s){
		int cx = x + px[k],cy = y + py[k];
		if(chk(cx,cy)){
			dy.add(cy);
			all.push_back({cx,cy});
		}
	}
}
void sadd(int x,int y,int s=5,int t=5){
	//s=t=5;
	int now = I(x,y);
	rep(k,0,4)if((k^s) && (k^t)){
		int cx = x + px[k],cy = y + py[k];
		if(chk(cx,cy)){
			int id = find(I(cx,cy));
			if(tag[id]){
				merge(now,id);
			}
		}
	}
}

void solve(){
	gi(n);gi(m);gi(k);

	rep(i,0,n+1)s[i] = c[i] = pre[i] = 0,o[i].clear();
	all.clear();

	rep(i,1,k){
		gi(r1[i]);gi(c1[i]);gi(r2[i]);gi(c2[i]);
		if(r1[i] == r2[i]){ //row 
			int len = c2[i]-c1[i]+1;
			s[r1[i]]+=len;
			s[r2[i]+1]-=len;
		}else{ //column
			s[r1[i]]++;
			s[r2[i]+1]--;
		}
		o[r1[i]].push_back(i);
	}
	rep(i,1,n)s[i] += s[i-1];
	rep(i,1,n)s[i] += s[i-1];
	//

	dy.clr();
	rep(i,1,k){
		if(r1[i]==r2[i])add(r1[i],c1[i],0),add(r1[i],c2[i],2);
		else add(r1[i],c1[i],1),add(r2[i],c2[i],3);
	}
	dy.pr();
	sort(all.begin(),all.end());all.erase(unique(all.begin(),all.end()),all.end());
	
	rep(i,1,n)rx[i].clr();
	rep(i,1,dy.sz)ry[i].clr();

	for(auto [x,y] : all){
		rx[R(x)].add(y);
		ry[C(y)].add(x);
		pre[x]++;
	}
	
	rep(i,1,dy.sz)ry[i].pr();
	rep(i,1,n)pre[i] += pre[i-1];

	rep(i,1,SZ(all)+k)fa[i] = i,tag[i] = (i>SZ(all));
	ans = 0;
	
	rep(i,1,n){
		ans += o[i].size();

		for(auto id : o[i]){
			if(r1[id] == r2[id]){
				int r = r1[id],ri = R(r);
				int L = rx[ri].qry(c1[id]),R = rx[ri].qry(c2[id]);
				rep(p,L,R){
					merge(I(r,rx[ri].b[p-1]),SZ(all) + id);
					sadd(r,rx[ri].b[p-1],0,2);
				}
			}else{
				int c = c1[id],ci = C(c);
				int L = ry[ci].qry(r1[id]),R = ry[ci].qry(r2[id]);
				rep(p,L,R){
					merge(I(ry[ci].b[p-1],c),SZ(all) + id);
					sadd(ry[ci].b[p-1],c,1,3);
				}
			}
		}

		c[i] = ans;
	}
	

	//output
	rep(i,1,n){
		print(s[i]);pc(' ');print(c[i]);pc('\n');
	}
}

signed main(){
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);

	gi(T);
	while(T--)solve();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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 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: