QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#352131#6733. Moniphant Sleepddl_VS_pigeonWA 411ms42352kbC++203.3kb2024-03-12 21:31:102024-03-12 21:31:11

Judging History

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

  • [2024-03-12 21:31:11]
  • 评测
  • 测评结果:WA
  • 用时:411ms
  • 内存:42352kb
  • [2024-03-12 21:31:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;

int add(int a, int b) {
	if (a == inf) {
		return b > -inf ? inf : 0;
	} else if (b == inf) {
		return a > -inf ? inf : 0;
	} else {
		return a + b;
	}
}

struct Segt {
	struct T {
		int mnc, mxc, ctag, atag, a;
		T() : mnc(inf), mxc(inf), ctag(0), atag(0), a(0) {}
		void adda(int val) {
			atag = add(atag, val);
			a = add(a, val);
		}
		void addc(int val) {
			ctag = add(ctag, val);
			mnc = add(mnc, val);
			mxc = add(mxc, val);
		}
	};
	const int n;
	vector<T> t;
	Segt(int _n) : n(_n), t(n << 2 | 1) {}
	void adda1(int l, int r) {
		adda1(l, r, 1, 1, n);
	}
	void minusa1(int l, int r) {
		minusa1(l, r, 1, 1, n);
	}
	void minc0(int l, int r) {
		minc0(l, r, 1, 1, n);
	}
	void update(int l, int r) {
		update(l, r, 1, 1, n);
	}
	int query(int l) {
		return query(l, 1, 1, n) + int(5e5);
	}
	#define mid ((l + r) >> 1)
	#define ls (v << 1)
	#define rs (v << 1 | 1)
	void pu(int v) {
		t[v].mnc = min(t[ls].mnc, t[rs].mnc);
		t[v].mxc = max(t[ls].mxc, t[rs].mxc);
	}
	void pd(int v) {
		if (t[v].atag) {
			t[ls].adda(t[v].atag);
			t[rs].adda(t[v].atag);
			t[v].atag = 0;
		}
		if (t[v].ctag) {
			t[ls].addc(t[v].ctag);
			t[rs].addc(t[v].ctag);
			t[v].ctag = 0;
		}
	}
	void adda1(int al, int ar, int v, int l, int r) {
		if (ar < l || al > r) {
			return;
		}
		if (al <= l && ar >= r) {
			t[v].adda(1);
			t[v].addc(-1);
		} else {
			pd(v);
			adda1(al, ar, ls, l, mid);
			adda1(al, ar, rs, mid + 1, r);
			pu(v);
		}
	}
	void minusa1(int ml, int mr, int v, int l, int r) {
		if (mr < l || ml > r) {
			return;
		}
		if (ml <= l && mr >= r) {
			if (t[v].mxc + 1 <= 0) {
				t[v].adda(-1);
				t[v].addc(1);
				return;
			} else if (t[v].mnc == t[v].mxc) {
				t[v].adda(-1);
				t[v].addc(inf);
				return;
			}
		}
		pd(v);
		minusa1(ml, mr, ls, l, mid);
		minusa1(ml, mr, rs, mid + 1, r);
		pu(v);
	}
	void minc0(int ml, int mr, int v, int l, int r) {
		if (mr < l || ml > r || t[v].mxc <= 0) {
			return;
		}
		if (ml <= l && mr >= r) {
			if (t[v].mnc == t[v].mxc) {
				t[v].addc(-t[v].mxc);
				return;
			}
		}
		pd(v);
		minc0(ml, mr, ls, l, mid);
		minc0(ml, mr, rs, mid + 1, r);
		pu(v);
	}
	void update(int ul, int ur, int v, int l, int r) {
		if (ur < l || ul > r || t[v].mnc > 0) {
			return;
		}
		if (ul <= l && ur >= r) {
			if (t[v].mxc == t[v].mnc) {
				t[v].adda(t[v].mxc);
				t[v].addc(inf);
				return;
			}
		}
		pd(v);
		update(ul, ur, ls, l, mid);
		update(ul, ur, rs, mid + 1, r);
		pu(v);
	}
	int query(int loc, int v, int l, int r) {
		if (l == r) {
			return t[v].a;
		} else {
			pd(v);
			if (loc <= mid) {
				return query(loc, ls, l, mid);
			} else {
				return query(loc, rs, mid + 1, r);
			}
		}
	}
	#undef rs
	#undef ls
	#undef mid
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	int n, q;
	cin >> n >> q;
	Segt tr(n);
	for (int i = 1; i <= q; i++) {
		int op, l, r;
		cin >> op >> l >> r;
		if (op == 1) {
			tr.adda1(l, r);
		} else if (op == 2) {
			tr.minusa1(l, r);
		} else if (op == 3) {
			tr.minc0(l, r);
		} else if (op == 4) {
			tr.update(l, r);
		} else {
			cout << tr.query(l) << '\n';
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3824kb

input:

1 9
1 1 1
1 1 1
1 1 1
3 1 1
2 1 1
1 1 1
1 1 1
4 1 1
5 1 1

output:

500004

result:

ok 1 number(s): "500004"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

3 7
2 1 3
3 1 3
1 1 3
1 1 3
5 1 1
4 1 3
5 1 1

output:

500001
499999

result:

ok 2 number(s): "500001 499999"

Test #3:

score: -100
Wrong Answer
time: 411ms
memory: 42352kb

input:

500000 500000
2 132991 371170
5 15281 15281
1 278642 397098
2 152103 176573
2 13797 47775
3 139320 370045
3 79054 432340
3 82556 212775
4 270171 469418
5 148000 148000
3 371255 401414
5 71051 71051
2 358945 473071
2 231663 265401
2 20243 58131
1 247710 313373
5 154549 154549
1 17317 233265
5 37602 3...

output:

500000
499999
500000
499998
499999
500000
500001
499997
500000
499997
499997
499999
499998
500000
499997
500001
500000
500001
499999
500000
499997
499999
499997
499998
500000
500001
500003
499996
499998
500000
499998
500002
500001
500006
500003
500004
500004
500000
500001
499998
499997
499999
500008...

result:

wrong answer 7th numbers differ - expected: '500000', found: '500001'