QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#142471#4918. 染色heyangyang0 0ms0kbC++145.5kb2023-08-19 08:05:182023-08-19 08:05:21

Judging History

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

  • [2023-08-19 08:05:21]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-08-19 08:05:18]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define eb emplace_back
#define IN inline
using namespace std;
const int N = 3e5 + 5;
int n, m;

IN LL read() {
	LL t = 0,res = 0; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) t |= (ch == '-');
	for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
	return t ? -res : res;
}
#define UL unsigned long long
struct nd{int z, c;}mn[N << 2];
UL sum[N << 2], tag[2][N << 2];
set<int> f[N << 2];
void getplus(int l, int r, int k, UL z, int fl) {
	if (fl == 0) tag[0][k] += z, sum[k] += (UL)mn[k].c * z;
	else tag[1][k] += z, sum[k] += (UL)(r - l + 1) * z;
}
void pushdown(int k, int l, int r) {
//	if (tag[0][k] != 0 || tag[1][k] != 0) 
//		printf("%d %d %llu %llu\n", l, r, tag[0][k], tag[1][k]);
	if (tag[0][k] != 0) {
		int z = *(f[k].lower_bound(0));
//		printf("%d %d %d %d\n",z,mn[k].z,l,r);
		if (z == mn[k].z) tag[1][k] += tag[0][k];
		else {
			int mid = l + r >> 1;
//			printf("%d %d %d\n", z, mn[k << 1].z, mn[k << 1 | 1].z);
			if (mn[k << 1].z == mn[k].z) getplus(l, mid, k << 1, tag[0][k], 0);
			if (mn[k << 1 | 1].z == mn[k].z) getplus(mid + 1, r, k << 1 | 1, tag[0][k], 0);
		}
		tag[0][k] = 0;
	}
	if (tag[1][k] != 0) {
		int mid = l + r >> 1;
		getplus(l, mid, k << 1, tag[1][k], 1);
		getplus(mid + 1, r, k << 1 | 1, tag[1][k], 1);
		tag[1][k] = 0;
	}
}
nd Min(nd x, nd y) {
	if (x.z < y.z) return x;
	if (x.z == y.z) return nd{x.z, x.c + y.c};
	if (x.z > y.z) return y;
}
void pushup(int k, int l, int r, int fl) {
	mn[k] = nd{(int)1e9, 0};
	if (l ^ r) mn[k] = Min(mn[k], mn[k << 1]), mn[k] = Min(mn[k], mn[k << 1 | 1]);
	int z = *(f[k].lower_bound(0));
	if (mn[k].z > z) mn[k] = nd{z, r - l + 1};
	if (fl) sum[k] = sum[k << 1] + sum[k << 1 | 1];
}
void update(int l, int r, int k, int L, int R, int x, int fl) {
	if (L > R) return;
	if (L <= l && r <= R) {
		if (fl == 1) f[k].insert(x); else f[k].erase(x);
		pushup(k, l, r, 0);
		return;
	}
	int mid = l + r >> 1; pushdown(k, l, r);
	if (L <= mid) update(l, mid, k << 1, L, R, x, fl);
	if (R > mid) update(mid + 1, r, k << 1 | 1, L, R, x, fl);
	pushup(k, l, r, 1);
}
void addmn(int l, int r, int k, int L, int R, int z, UL v, int mz) {
	if (L <= l && r <= R) {
//		printf("%d %d %d %d\n", l, r, min(mz, mn[k].z), z);
		if (min(mz, mn[k].z) == z) getplus(l, r, k, v, 0);
		return;
	} 
	int mid = l + r >> 1, val = *(f[k].lower_bound(0)); pushdown(k, l, r);
	if (L <= mid) addmn(l, mid, k << 1, L, R, z, v, min(mz, val));
	if (R > mid) addmn(mid + 1, r, k << 1 | 1, L, R, z, v, min(mz, val));
	pushup(k, l, r, 1);
}
int getmn(int l, int r, int k, int L, int R) {
	if (L <= l && r <= R) return mn[k].z;
	int mid = l + r >> 1, res = *(f[k].lower_bound(0)); pushdown(k, l, r);
	if (L <= mid) res = min(res, getmn(l, mid, k << 1, L, R));
	if (R > mid) res = min(res, getmn(mid + 1, r, k << 1 | 1, L, R));
	return res;
}
UL query(int l, int r, int k, int L, int R) {
	if (L <= l && r <= R) return sum[k];
	int mid = l + r >> 1; UL res = 0; pushdown(k, l, r);
	if (L <= mid) res = query(l, mid, k << 1, L, R);
	if (R > mid) res += query(mid + 1, r, k << 1 | 1, L, R);
	return res;
}
struct odt{
	int l, r, z;
	friend bool operator < (odt x, odt y){return x.r < y.r;}
};
set<odt> T[N];
void split(int id, int x, int fl, int z) {
	auto it = T[id].lower_bound(odt{0, x, 0});
	int cor = it->z, l = it->l, r = it->r;
//	printf("ff %d %d %d %d\n", x, l, r, cor);
	
	if (cor == 0) {
		update(1, n, 1, l, r, id, -1);
		if (fl == 1) update(1, n, 1, x + 1, r, id, 1);
		else update(1, n, 1, l, x - 1, id, 1);
	}
	T[id].erase(it);
	if (fl == 1) {
		if (x < r) T[id].insert(odt{x + 1, r, cor});
		T[id].insert(odt{l, x, cor});
	}
	else {	
		if (l < x) T[id].insert(odt{l, x - 1, cor});
		T[id].insert(odt{x, r, cor});
	}
}
void prf(int l, int r, int k) {
//	printf("%d %d\n",l,r);
//	for (auto i = f[k].begin(); i != f[k].end(); i++)
//		printf("%d ", *i);
//	puts("");
	if (l == r) return;
	int mid = l + r >> 1;
	prf(l, mid, k << 1), prf(mid + 1, r, k << 1 | 1);
}
void change(int id, int l, int r, int z) {
	split(id, r, 1, z), split(id, l, 0, z);
//	puts("ff");
	auto itl = T[id].lower_bound(odt{0, l, 0}), itr = T[id].lower_bound(odt{0, r, 0});
//	printf("%d %d %d %d %d %d\n",itl->l,itl->r,itl->z,itr->l,itr->r,itr->z);
	for (auto i = itl; i != itr; i++) {
		if (i == itl || i == itr) continue;
		if (i->z == 0) update(1, n, 1, i->l, i->r, id, -1);
	}
	if (z == 0) update(1, n, 1, l, r, id, 1);
		puts("");
		prf(1, n, 1);
//	printf("%d %d %d\n",l,r,z); 
	itr++, T[id].erase(itl, itr);
	T[id].insert(odt{l, r, z});
//		puts("2set");
//		for (auto i = T[2].begin(); i != T[2].end(); i++)
//			printf("%d %d %d\n",i->l,i->r,i->z);
}
void build(int l, int r, int k) {
	mn[k] = nd{(int)1e9, r - l + 1}, f[k].insert((int)1e9);
	if (l == r) return; int mid = l + r >> 1;
	build(l, mid, k << 1), build(mid + 1, r, k << 1 | 1);
}
int main() {
	freopen("paint.in", "r", stdin);
//	freopen("paint.out", "w", stdout);
	n = read(), m = read(), build(1, n, 1), mn[1] = nd{1, n};
	for (int i = 1; i <= m; i++) f[1].insert(i), T[i].insert(odt{1, n, 0});
	for (int i = 1; i <= m; i++) {
		int opt = read(), l = read(), r = read(); LL x;
		if (opt == 1) x = read(), change(x, l, r, 1);
		if (opt == 2) x = read(), change(x, l, r, 0);
		if (opt == 3) {
			x = read();
			int z = getmn(1, n, 1, l, r);
//			printf("ff %d\n", z);
			addmn(1, n, 1, l, r, z, x, (int)1e9);
		}
		if (opt == 4) {
			UL ans = query(1, n, 1, l, r);
			printf("%llu\n", ans); 
		}
	}
}

詳細信息

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

1000 1000
3 722 914 2141556875752121755
3 323 347 6433743606947304931
2 142 206 439
2 117 840 195
2 127 502 56
3 168 707 15142638115094015116
4 190 257
2 88 976 475
1 319 867 351
1 682 889 409
2 406 446 196
3 28 35 4899387534800369959
2 291 546 150
1 528 617 128
1 58 122 251
2 381 400 276
4 510 958
...

output:


result:


Subtask #2:

score: 0
Time Limit Exceeded

Test #11:

score: 0
Time Limit Exceeded

input:

300000 300000
1 237576 237663 1
3 16150 16208 9270412155482010138
2 175648 175692 1
4 190836 190849
4 199010 199097
1 73976 298801 1
3 89902 89939 6418828085116455990
3 55415 55461 12238963685511262676
3 119825 119875 8146944792877919309
3 135103 135158 218634681842812119
3 127261 127352 13291431184...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Time Limit Exceeded

Test #31:

score: 0
Time Limit Exceeded

input:

300000 300000
1 85444 86076 59
1 41150 41411 71
1 278698 279414 45
1 238445 239202 56
1 29965 29984 49
1 282953 283272 37
1 34668 35653 86
2 198587 198744 28
1 270855 271611 58
1 2130 2965 773
1 161601 162298 937
1 50299 50435 36
1 100759 101198 64
1 120208 120543 84
1 295293 295732 34
1 112185 1129...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%