QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142307#4918. 染色heyangyang0 2437ms188912kbC++145.2kb2023-08-18 22:24:372023-08-18 22:24:39

Judging History

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

  • [2023-08-18 22:24:39]
  • 评测
  • 测评结果:0
  • 用时:2437ms
  • 内存:188912kb
  • [2023-08-18 22:24:37]
  • 提交

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, mn[k].z, z);
		if (min(mz, mn[k].z) == z) getplus(l, r, k, v, 0);
		return;
	} 
	int mid = l + r >> 1; pushdown(k, l, r);
	if (L <= mid) addmn(l, mid, k << 1, L, R, z, v, min(mz, mn[k].z));
	if (R > mid) addmn(mid + 1, r, k << 1 | 1, L, R, z, v, min(mz, mn[k].z));
	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 = mn[k].z; 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("%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);
	T[id].erase(itl, itr), T[id].insert(odt{l, r, 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() {
	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) {
//		puts("");
//		prf(1, n, 1);
			UL ans = query(1, n, 1, l, r);
			printf("%llu\n", ans); 
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 11ms
memory: 78796kb

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:

15128467772367689008
17361914246216994339
5483226026482017320
3033562207293358603
2081407883485577238
7431958406282818646
4664359672511637691
8517692808398202534
17884251128335023776
3389445997760709607
15161173652136060523
6125991716693019221
5538564701002316303
12944181649352512781
105912025118031...

result:

wrong answer 12th words differ - expected: '17246899135664170339', found: '6125991716693019221'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 1425ms
memory: 169860kb

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:

0
0
0
0
0
0
12272376591028786218
0
0
0
0
0
0
0
0
0
0
0
0
0
0
954290611784159519
11933011047389299715
3778617232493240005
16090278095350766495
4074535568592888792
16938285947326957203
0
0
14783754218831034862
7601682967357904165
0
9546408837911439772
1922461247513984739
14899789459322003663
0
1431961...

result:

wrong answer 23rd words differ - expected: '0', found: '11933011047389299715'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 2437ms
memory: 188912kb

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:

0
0
2447070918471921670
2766076061752051808
11334973856018620450
0
10310440710243485426
12798030081335994435
0
7066425141425110893
4267825007721372713
0
0
11728279343985309580
11917196698575719908
11197982942017938036
12389254927403710188
0
0
0
2155420403674811693
6359253237460991224
180023584334496...

result:

wrong answer 3rd words differ - expected: '16968625150574630951', found: '2447070918471921670'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%