QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#143972#4918. 染色heyangyang0 747ms167856kbC++144.5kb2023-08-21 15:11:252023-08-21 15:11:30

Judging History

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

  • [2023-08-21 15:11:30]
  • 评测
  • 测评结果:0
  • 用时:747ms
  • 内存:167856kb
  • [2023-08-21 15:11:25]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define eb emplace_back
#define IN inline
#define UL unsigned long long
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;
}
struct heap{
	priority_queue<int, vector<int>, greater<int> > A,B;
	void Insert(int x){A.push(x);}
	void Del(int x){B.push(x);}
	int Top() {
		while (!A.empty() && !B.empty() && A.top() == B.top()) A.pop(), B.pop();
		return A.top();
	}
}f[N << 2]; 
struct nd{int z, c;}mn[N << 2];
UL sum[N << 2], tag[2][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) {
	int mid = l + r >> 1;
	if (tag[0][k] != 0) {
		int z = f[k].Top();
		if (z == mn[k].z) tag[1][k] += tag[0][k];
		else {
			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) {
		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].Top();
	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;
	pushdown(k, l, r);
	if (L <= l && r <= R) {
		if (fl == 1) f[k].Insert(x); else f[k].Del(x);
		pushup(k, l, r, 0);
		return;
	}
	int mid = l + r >> 1; 
	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) {
		if (mz == z) getplus(l, r, k, v, 1);
		else if (mn[k].z == z) getplus(l, r, k, v, 0);
		return;
	} 
	int mid = l + r >> 1, val = f[k].Top(); 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].Top(); 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;
	friend bool operator < (odt x, odt y){return x.l < y.l;}
};
set<odt> T[N]; odt a[N];
void change(int id, int l, int r, int z) {
	auto it = T[id].upper_bound(odt{l, 0});
	it--; auto itl = it;
	int cnt = 0;
	while (it != T[id].end()) {
		if (it->l > r) break;
		if (it->r >= l) a[++cnt] = *it, update(1, n, 1, it->l, it->r, id, -1);
		it++;
	}
	T[id].erase(itl, it);
	for (int i = 1; i <= cnt; i++) {
		if (a[i].l < l)
			update(1, n, 1, a[i].l, l - 1, id, 1), T[id].insert(odt{a[i].l, l - 1});
		if (a[i].r > r)
			update(1, n, 1, r + 1, a[i].r, id, 1), T[id].insert(odt{r + 1, a[i].r});
	}
	if (z == 0) T[id].insert(odt{l, r}), update(1, n, 1, l, r, id, 1);
}
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});
	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);
			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
Runtime Error

Test #1:

score: 10
Accepted
time: 14ms
memory: 100688kb

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
17246899135664170339
16659472119973467421
5618344994614112283
92650283427734...

result:

ok 288 tokens

Test #2:

score: -10
Runtime Error

input:

1000 1000
1 538 681 44
2 112 540 10
1 160 191 28
1 276 867 1
4 118 419
4 62 209
1 575 884 37
1 783 895 45
4 342 410
2 545 870 16
1 273 501 11
3 258 352 13270291835335737625
3 490 514 5208698592597571883
2 629 865 43
3 966 981 14431353048791951405
1 290 809 16
4 468 843
1 607 875 26
2 177 521 6
4 176...

output:


result:


Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 747ms
memory: 167856kb

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
14648794701578985531
0
3778617232493240005
8956067326602310519
17975264409458200641
16938285947326957203
0
0
14783754218831034862
7601682967357904165
0
0
0
0
0
0
11584905325916393312
0
0
4657169178464751085
17170356428308894805
0
0
0
0
148...

result:

wrong answer 22nd words differ - expected: '954290611784159519', found: '14648794701578985531'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 560ms
memory: 161096kb

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
4642876597625506611
3541385191970485134
15330757429201569746
0
4774641114671397458
9699935170387977545
0
8784363051093968179
0
0
8023696610151188629
10270101177550224023
11917196698575719908
6298384012519653477
7725984392284578759
0
0
0
0
0
438673155602015608
8244748990550860359
1258270799443126...

result:

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

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%