QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#296241#7436. Optimal Ordered Problem Solverzlt0 932ms123332kbC++146.2kb2024-01-02 15:49:582024-01-02 15:49:58

Judging History

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

  • [2024-01-02 15:49:58]
  • 评测
  • 测评结果:0
  • 用时:932ms
  • 内存:123332kb
  • [2024-01-02 15:49:58]
  • 提交

answer

// Problem: P9061 [Ynoi2002] Optimal Ordered Problem Solver
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P9061
// Memory Limit: 512 MB
// Time Limit: 4000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<int, int> pii;

namespace IO {
    char ibuf[1 << 20], *iS, *iT, obuf[1 << 20], *oS = obuf;
#define writesp(x) write(x), pc(' ')
#define writeln(x) write(x), pc('\n')
#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, 1 << 20, stdin), (iS == iT ? EOF : *iS++) : *iS++)
	template<typename T = int>
    inline T read() {
        char ch = gh();
        T x = 0;
        bool t = 0;
        while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
        while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
        return t ? ~(x - 1) : x;
    }
    inline void flush () {
    	fwrite(obuf, 1, oS - obuf, stdout), oS = obuf;
	}
    inline void pc (char ch) {
    	if (oS == obuf + (1 << 20)) flush(); 
    	*oS++ = ch;
	}
	template<typename _Tp>
    inline void write (_Tp x) {
    	static char stk[64], *tp = stk;
    	if (x < 0) x = ~(x - 1), pc('-');
		do *tp++ = x % 10, x /= 10;
		while (x);
		while (tp != stk) pc((*--tp) | 48);
    }
}

using IO::read;
using IO::write;
using IO::pc;
using IO::flush;

const int maxn = 1000100;

int n, m, ans[maxn];
pii a[maxn];
vector<int> vc[maxn];
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

struct node {
	int o, x, y, qx, qy, id;
} qq[maxn];

struct {
	int c[maxn];
	
	inline void init() {
		mems(c, 0);
	}
	
	inline void update(int x, int d) {
		for (int i = x; i <= n; i += (i & (-i))) {
			c[i] += d;
		}
	}
	
	inline int query(int x) {
		int res = 0;
		for (int i = x; i; i -= (i & (-i))) {
			res += c[i];
		}
		return res;
	}
	
	inline int query(int l, int r) {
		return query(r) - query(l - 1);
	}
} t1, t2;

struct {
	int c[maxn];
	
	inline void init() {
		mems(c, 0x3f);
	}
	
	inline void update(int x, int d) {
		for (int i = x; i; i -= (i & (-i))) {
			c[i] = min(c[i], d);
		}
	}
	
	inline int query(int x) {
		int res = 2e9;
		for (int i = x; i <= n; i += (i & (-i))) {
			res = min(res, c[i]);
		}
		return res;
	}
} t3;

struct {
	int c[maxn];
	
	inline void init() {
		mems(c, -0x3f);
	}
	
	inline void update(int x, int d) {
		for (int i = x; i; i -= (i & (-i))) {
			c[i] = max(c[i], d);
		}
	}
	
	inline int query(int x) {
		int res = -2e9;
		for (int i = x; i <= n; i += (i & (-i))) {
			res = max(res, c[i]);
		}
		return res;
	}
} t4;

int p[maxn], ls[maxn], rs[maxn], ax[maxn], ay[maxn], sz[maxn], tagx[maxn], tagy[maxn], rt, nt;

inline void pushup(int x) {
	sz[x] = sz[ls[x]] + sz[rs[x]] + 1;
}

inline void pushdown(int x) {
	if (tagx[x] != -1) {
		if (ls[x]) {
			ax[ls[x]] = tagx[ls[x]] = tagx[x];
		}
		if (rs[x]) {
			ax[rs[x]] = tagx[rs[x]] = tagx[x];
		}
		tagx[x] = -1;
	}
	if (tagy[x] != -1) {
		if (ls[x]) {
			ay[ls[x]] = tagy[ls[x]] = tagy[x];
		}
		if (rs[x]) {
			ay[rs[x]] = tagy[rs[x]] = tagy[x];
		}
		tagy[x] = -1;
	}
}

// x <= k, x > k
void splitx(int u, int k, int &x, int &y) {
	if (!u) {
		x = y = 0;
		return;
	}
	pushdown(u);
	if (ax[u] <= k) {
		x = u;
		splitx(rs[u], k, rs[u], y);
	} else {
		y = u;
		splitx(ls[u], k, x, ls[u]);
	}
	pushup(u);
}

// y > k, y <= k
void splity(int u, int k, int &x, int &y) {
	if (!u) {
		x = y = 0;
		return;
	}
	pushdown(u);
	if (ay[u] > k) {
		x = u;
		splity(rs[u], k, rs[u], y);
	} else {
		y = u;
		splity(ls[u], k, x, ls[u]);
	}
	pushup(u);
}

int merge(int x, int y) {
	if (!x || !y) {
		return x | y;
	}
	pushdown(x);
	pushdown(y);
	if (p[x] < p[y]) {
		rs[x] = merge(rs[x], y);
		pushup(x);
		return x;
	} else {
		ls[y] = merge(x, ls[y]);
		pushup(y);
		return y;
	}
}

inline int newnode(int x, int y) {
	int u = ++nt;
	ax[u] = x;
	ay[u] = y;
	sz[u] = 1;
	p[u] = rnd();
	return u;
}

void solve() {
	n = read();
	m = read();
	for (int i = 1; i <= n; ++i) {
		a[i].fst = read();
		a[i].scd = read();
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= m; ++i) {
		qq[i].o = read();
		qq[i].x = read();
		qq[i].y = read();
		qq[i].qx = read();
		qq[i].qy = read();
		qq[i].id = i;
	}
	t3.init();
	t4.init();
	sort(qq + 1, qq + m + 1, [&](const node &a, const node &b) {
		return a.qx > b.qx;
	});
	for (int i = 1, j = n; i <= m; ++i) {
		while (j && a[j].fst > qq[i].qx) {
			t1.update(a[j].scd, 1);
			--j;
		}
		ans[qq[i].id] = t1.query(qq[i].qy + 1, n);
	}
	sort(qq + 1, qq + m + 1, [&](const node &a, const node &b) {
		return a.x > b.x;
	});
	t1.init();
	for (int i = n, j = 1; i; --i) {
		t1.update(a[i].fst, 1);
		t2.update(a[i].scd, 1);
		while (j <= m && qq[j].x >= a[i].fst) {
			t3.update(qq[j].y, qq[j].id);
			++j;
		}
		int t = t3.query(a[i].scd);
		if (t <= m) {
			vc[t].pb(i);
		}
	}
	sort(qq + 1, qq + m + 1, [&](const node &a, const node &b) {
		return a.id < b.id;
	});
	mems(tagx, -1);
	mems(tagy, -1);
	for (int i = 1, x, y, z; i <= m; ++i) {
		t4.update(qq[i].x, qq[i].y);
		splitx(rt, qq[i].x, x, z);
		splity(x, qq[i].y, x, y);
		if (y) {
			if (qq[i].o == 1) {
				ay[y] = tagy[y] = qq[i].y;
			} else {
				ax[y] = tagx[y] = qq[i].x;
			}
		}
		rt = merge(merge(x, y), z);
		for (int j : vc[i]) {
			int xx = a[j].fst, yy = a[j].scd;
			t1.update(xx, -1);
			t2.update(yy, -1);
			if (qq[i].o == 1) {
				yy = qq[i].y;
			} else {
				xx = qq[i].x;
			}
			splitx(rt, qq[i].x, x, z);
			splity(x, qq[i].y, x, y);
			rt = merge(merge(x, newnode(xx, yy)), merge(y, z));
		}
		if (t4.query(qq[i].qx + 1) > qq[i].qy) {
			ans[i] = 0;
		} else {
			ans[i] += t1.query(qq[i].qx) + t2.query(qq[i].qy) + sz[rt];
			splitx(rt, qq[i].qx, x, z);
			splity(x, qq[i].qy, x, y);
			ans[i] += sz[y] - n;
		}
		writeln(ans[i]);
	}
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	flush();
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 61772kb

input:

995 996
950 481
376 18
141 776
711 966
130 727
468 529
47 39
857 563
832 821
776 472
154 914
825 279
332 415
470 361
968 440
45 560
299 755
703 785
744 387
547 382
3 549
344 573
778 424
784 765
280 115
251 434
695 98
463 506
379 38
610 486
305 623
703 244
856 365
117 360
772 847
331 723
663 991
900 ...

output:

423
473
758
313
694
232
333
784
821
154
247
244
504
54
200
370
872
782
734
174
660
467
76
754
77
3
140
970
522
411
435
690
503
573
254
116
239
1
0
315
309
494
214
824
429
619
977
696
116
51
66
495
371
279
383
124
313
135
216
406
18
543
1
381
426
164
27
0
158
605
657
541
468
652
557
44
124
517
215
33...

result:

wrong answer 27th numbers differ - expected: '144', found: '140'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 932ms
memory: 115480kb

input:

999996 999996
921339 140126
955508 363759
958698 342406
280137 955674
907511 75721
189876 946586
152058 168837
541857 557702
84498 865987
185574 809224
704828 701026
815379 548000
989515 518951
335439 336866
745570 790616
766723 212893
926629 859003
51261 40866
592510 556235
324926 700261
320946 798...

output:

0
0
953730
0
0
587546
0
0
0
0
-330458
0
0
0
0
-418270
0
0
0
0
0
0
-226369
0
0
0
0
0
0
0
0
0
0
0
-697615
0
0
-701549
0
0
0
0
-686645
0
0
0
-701138
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-695553
-701362
0
0
0
0
0
0
-713416
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-710881
0
0
0
0
0
0
0
...

result:

wrong answer 6th numbers differ - expected: '512663', found: '587546'

Subtask #3:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 895ms
memory: 123332kb

input:

999995 999997
261379 334440
985281 986034
549380 718157
670003 253925
533027 437989
326806 983213
965935 756259
229069 686789
331338 684961
957559 390618
937820 959719
338153 779814
582581 965418
634156 421264
308778 938878
913059 390904
481477 431492
739774 793015
901442 934600
256704 991485
366691...

output:

160635
633543
123517
313575
450013
383634
574180
2370
203695
326069
117988
567269
652812
199767
380301
380361
105864
373840
788324
703158
609783
648143
367045
497960
57966
478827
745034
75921
543044
251821
769802
436471
480950
235819
509607
757166
763468
396826
262664
2227
267148
165759
558927
16521...

result:

wrong answer 3rd numbers differ - expected: '123519', found: '123517'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%