QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#83597#1872. Gamewoxiangbaile#AC ✓502ms12468kbC++145.8kb2023-03-02 17:32:492023-03-02 17:32:53

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-02 17:32:53]
  • 评测
  • 测评结果:AC
  • 用时:502ms
  • 内存:12468kb
  • [2023-03-02 17:32:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i, d, u) for(int i = d; i <= u; ++i)
#define dep(i, u, d) for(int i = u; i >= d; --i)
#define cep(n) while(n--)
#define gep(i, a) for(int i = firs[a]; i; i = neig[i])
int ured() {
	int re = 0;
	char ch;
	do {
		ch = getchar();
	} while('9' < ch || ch < '0');
	do {
		re = re * 10 + (ch ^ '0');
	} while('0' <= (ch = getchar()) && ch <= '9');
	return re;
}
void uwit(int da) {
	int ch[21], cn = 0;
	do {
		ch[++cn] = da - da / 10 * 10;
	} while(da /= 10);
	do {
		putchar('0' ^ ch[cn]);
	} while(--cn);
}
const int _maxn = 100011, _zinf = 1000000001;
struct dats {
	int po, ln, ma, mi, va, ls, rs, lz;
} tree[_maxn * 151];
void push(int at) {
	if(tree[at] . lz) {
		if(tree[at] . ls) {
			tree[tree[at] . ls] . lz += tree[at] . lz;
		}
		if(tree[at] . rs) {
			tree[tree[at] . rs] . lz += tree[at] . lz;
		}
		tree[at] . ln += tree[at] . lz, tree[at] . mi += tree[at] . lz, tree[at] . lz = 0;
	}
}
void upda(int at) {
	tree[at] . mi = tree[at] . ln, tree[at] . ma = tree[at] . po;
	if(tree[at] . ls) {
		push(tree[at] . ls);
		if(tree[tree[at] . ls] . mi < tree[at] . mi) {
			tree[at] . mi = tree[tree[at] . ls] . mi, tree[at] . ma = tree[tree[at] . ls] . ma;
		}
	}
	if(tree[at] . rs) {
		push(tree[at] . rs);
		if(tree[tree[at] . rs] . mi < tree[at] . mi) {
			tree[at] . mi = tree[tree[at] . rs] . mi, tree[at] . ma = tree[tree[at] . rs] . ma;
		}
	}
}
void merg(int le, int ri, int &at) {
	if(!le || !ri) {
		at = le + ri;
		return;
	}
	if(tree[le] . va < tree[ri] . va) {
		at = le, push(le), merg(tree[le] . rs, ri, tree[at] . rs);
	} else {
		at = ri, push(ri), merg(le, tree[ri] . ls, tree[at] . ls);
	}
	upda(at);
}
void spil(int &le, int &ri, int at, int po) {
	if(!at) {
		le = ri = 0;
		return;
	}
	push(at);
	if(tree[at] . po < po) {
		le = at, spil(tree[le] . rs, ri, tree[at] . rs, po), upda(le);
	} else {
		ri = at, spil(le, tree[ri] . ls, tree[at] . ls, po), upda(ri);
	}
}
int lens;
int finl(int at, int po) {
	if(!at) {
		return -_zinf;
	}
	push(at);
	if(tree[at] . po <= po && po <= tree[at] . po + tree[at] . ln - 1) {
		lens += tree[at] . ln;
		return tree[at] . po;
	} else if(po < tree[at] . po) {
		return finl(tree[at] . ls, po);
	} else {
		return finl(tree[at] . rs, po);
	}
}
int finr(int at, int po) {
	if(!at) {
		return -_zinf;
	}
	push(at);
	if(tree[at] . po - tree[at] . ln + 1 <= po && po <= tree[at] . po) {
		lens += tree[at] . ln;
		return tree[at] . po;
	} else if(po < tree[at] . po) {
		return finr(tree[at] . ls, po);
	} else {
		return finr(tree[at] . rs, po);
	}
}
mt19937 tran(1);
int lrot, rrot, latp, matp, ratp, cnts, latc, ratc;
void insp(int &at, int po, int ln = 1) {
	++cnts, tree[cnts] . po = tree[cnts] . ma = po, tree[cnts] . mi = tree[cnts] . ln = ln;
	tree[cnts] . ls = tree[cnts] . rs = tree[cnts] . lz = 0, tree[cnts] . va = tran();
	spil(latp, ratp, at, po), merg(latp, cnts, latp), merg(latp, ratp, at);
}
void mant();
void eras(int &at, int po, int da = -_zinf, bool st = 0) {
	spil(latc, at, at, po), spil(at, ratc, at, po + 1);
	if(da != -_zinf) {
		if(st) {
			insp(latc, tree[at] . po, da - tree[at] . po), insp(ratc, da + 1, tree[at] . po + tree[at] . ln - da - 1);
		} else {
			insp(latc, da - 1, da - tree[at] . po + tree[at] . ln - 1), insp(ratc, tree[at] . po, tree[at] . po - da);
		}
	}
	merg(latc, ratc, at);
	if(da != -_zinf) {
		mant();
	}
}
void mant() {
	int la, ra, ln;
	while(lrot) {
		push(lrot);
		if(tree[lrot] . mi) {
			break;
		} else {
			lens = 0, la = finr(rrot, tree[lrot] . ma - 1), ra = finr(rrot, tree[lrot] . ma);
			eras(rrot, la), eras(rrot, ra), insp(rrot, ra, lens), eras(lrot, tree[lrot] . ma);
		}
	}
	while(rrot) {
		push(rrot);
		if(tree[rrot] . mi) {
			break;
		} else {
			lens = 0, la = finl(lrot, tree[rrot] . ma), ra = finl(lrot, tree[rrot] . ma + 1);
			eras(lrot, la), eras(lrot, ra), insp(lrot, la, lens), eras(rrot, tree[rrot] . ma);
		}
	}
}
int atti, atpo;
void inse(int po, bool da) {
	int re;
	if(atti & 1 ^ da) {
		if((re = finr(rrot, po)) != -_zinf) {
			insp(lrot, po), eras(rrot, re, po, 0);
		}
	} else {
		if((re = finl(lrot, po)) != -_zinf) {
			insp(rrot, po), eras(lrot, re, po, 1);
		}
	}
}
int t, n, q, l[_maxn], r[_maxn], z[_maxn], aran[_maxn], a[_maxn], b[_maxn], bran[_maxn], frti;
bool rans[_maxn];
int main() {
	t = ured();
	cep(t) {
		n = ured(), q = ured();
		rep(i, 1, n) {
			l[aran[i] = i] = ured(), r[i] = ured(), z[i] = ured();
		}
		rep(i, 1, q) {
			a[bran[i] = i] = ured(), b[i] = ured();
		}
		sort(aran + 1, aran + n + 1, [](int le, int ri) {
			return r[le] - l[le] < r[ri] - l[ri];
		}), sort(bran + 1, bran + q + 1, [](int le, int ri) {
			return b[le] - a[le] < b[ri] - a[ri];
		}), atti = -1, atpo = lrot = rrot = cnts = 0, insp(rrot, _zinf + 10, _zinf << 1);
		rep(i, 1, q) {
			while(atti < b[bran[i]] - a[bran[i]]) {
				push(lrot), push(rrot), frti = atti;
				if(tree[lrot] . mi + (((atti & 1) << 1) - 1) && tree[rrot] . mi + (((atti & 1 ^ 1) << 1) - 1)) {
					atti = min(b[bran[i]] - a[bran[i]], atpo == n ? _zinf : r[aran[atpo + 1]] - l[aran[atpo + 1]]);
				} else {
					++atti;
				}
				if((frti ^ atti) & 1) {
					if(atti & 1) {
						if(lrot) {
							--tree[lrot] . lz;
						}
						if(rrot) {
							++tree[rrot] . lz;
						}
					} else {
						if(lrot) {
							++tree[lrot] . lz;
						}
						if(rrot) {
							--tree[rrot] . lz;
						}
					}
				}
				mant();
				while(atpo + 1 <= n && r[aran[atpo + 1]] - l[aran[atpo + 1]] == atti) {
					++atpo, inse(l[aran[atpo]] + r[aran[atpo]] >> 1, z[aran[atpo]]);
				}
			}
			rans[bran[i]] = (finl(lrot, a[bran[i]] + b[bran[i]] >> 1) != -_zinf) ^ (atti & 1);
		}
		rep(i, 1, q) {
			putchar('0' ^ rans[i]);
		}
		putchar('\n');
	}
	return 0;
}

详细

Test #1:

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

input:

1
5 10
1 2 0
3 3 1
3 4 1
2 4 1
1 3 0
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

output:

0010111101

result:

ok single line: '0010111101'

Test #2:

score: 0
Accepted
time: 502ms
memory: 12468kb

input:

1004
100000 100000
500000000 500000000 1
500000000 500000002 1
500000000 500000004 1
500000000 500000006 0
500000000 500000008 1
500000000 500000010 0
500000000 500000012 0
500000000 500000014 1
500000000 500000016 0
500000000 500000018 1
500000000 500000020 0
500000000 500000022 1
500000000 5000000...

output:

000001100000000111001010000111001111110010000101100101101000101010101010000100100100101010011011110110001100000000100101000000000000000101000000000010100110110101000001000111110000100010110000100111110101101010011000000100000000001001011011101000100000011000111111100010001111010001000010001110001110...

result:

ok 1004 lines