From 86d5635288d1c19340c6886adc924188ea976cbb Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 22 Dec 2022 21:14:44 +0800 Subject: [PATCH] =?UTF-8?q?2738.=20=E7=9F=A9=E9=98=B5=E4=B9=98=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://hydro.ac/d/bzoj/record/63a4583cb053be173969fd70 --- BZOJ/2738/2738.cpp | 118 ++++++++++++++++++++++++++++++++++++++++++ BZOJ/2738/data/1.in | 3 ++ BZOJ/2738/data/1.out | 3 ++ BZOJ/2738/data/10.in | 3 ++ BZOJ/2738/data/10.out | 3 ++ BZOJ/2738/data/11.in | 3 ++ BZOJ/2738/data/11.out | 3 ++ BZOJ/2738/data/12.in | 3 ++ BZOJ/2738/data/12.out | 3 ++ BZOJ/2738/data/13.in | 3 ++ BZOJ/2738/data/13.out | 3 ++ BZOJ/2738/data/14.in | 3 ++ BZOJ/2738/data/14.out | 3 ++ BZOJ/2738/data/15.in | 3 ++ BZOJ/2738/data/15.out | 3 ++ BZOJ/2738/data/16.in | 3 ++ BZOJ/2738/data/16.out | 3 ++ BZOJ/2738/data/17.in | 3 ++ BZOJ/2738/data/17.out | 3 ++ BZOJ/2738/data/18.in | 3 ++ BZOJ/2738/data/18.out | 3 ++ BZOJ/2738/data/19.in | 3 ++ BZOJ/2738/data/19.out | 3 ++ BZOJ/2738/data/2.in | 3 ++ BZOJ/2738/data/2.out | 3 ++ BZOJ/2738/data/20.in | 3 ++ BZOJ/2738/data/20.out | 3 ++ BZOJ/2738/data/3.in | 3 ++ BZOJ/2738/data/3.out | 3 ++ BZOJ/2738/data/4.in | 3 ++ BZOJ/2738/data/4.out | 3 ++ BZOJ/2738/data/5.in | 3 ++ BZOJ/2738/data/5.out | 3 ++ BZOJ/2738/data/6.in | 3 ++ BZOJ/2738/data/6.out | 3 ++ BZOJ/2738/data/7.in | 3 ++ BZOJ/2738/data/7.out | 3 ++ BZOJ/2738/data/8.in | 3 ++ BZOJ/2738/data/8.out | 3 ++ BZOJ/2738/data/9.in | 3 ++ BZOJ/2738/data/9.out | 3 ++ 41 files changed, 238 insertions(+) create mode 100644 BZOJ/2738/2738.cpp create mode 100644 BZOJ/2738/data/1.in create mode 100644 BZOJ/2738/data/1.out create mode 100644 BZOJ/2738/data/10.in create mode 100644 BZOJ/2738/data/10.out create mode 100644 BZOJ/2738/data/11.in create mode 100644 BZOJ/2738/data/11.out create mode 100644 BZOJ/2738/data/12.in create mode 100644 BZOJ/2738/data/12.out create mode 100644 BZOJ/2738/data/13.in create mode 100644 BZOJ/2738/data/13.out create mode 100644 BZOJ/2738/data/14.in create mode 100644 BZOJ/2738/data/14.out create mode 100644 BZOJ/2738/data/15.in create mode 100644 BZOJ/2738/data/15.out create mode 100644 BZOJ/2738/data/16.in create mode 100644 BZOJ/2738/data/16.out create mode 100644 BZOJ/2738/data/17.in create mode 100644 BZOJ/2738/data/17.out create mode 100644 BZOJ/2738/data/18.in create mode 100644 BZOJ/2738/data/18.out create mode 100644 BZOJ/2738/data/19.in create mode 100644 BZOJ/2738/data/19.out create mode 100644 BZOJ/2738/data/2.in create mode 100644 BZOJ/2738/data/2.out create mode 100644 BZOJ/2738/data/20.in create mode 100644 BZOJ/2738/data/20.out create mode 100644 BZOJ/2738/data/3.in create mode 100644 BZOJ/2738/data/3.out create mode 100644 BZOJ/2738/data/4.in create mode 100644 BZOJ/2738/data/4.out create mode 100644 BZOJ/2738/data/5.in create mode 100644 BZOJ/2738/data/5.out create mode 100644 BZOJ/2738/data/6.in create mode 100644 BZOJ/2738/data/6.out create mode 100644 BZOJ/2738/data/7.in create mode 100644 BZOJ/2738/data/7.out create mode 100644 BZOJ/2738/data/8.in create mode 100644 BZOJ/2738/data/8.out create mode 100644 BZOJ/2738/data/9.in create mode 100644 BZOJ/2738/data/9.out diff --git a/BZOJ/2738/2738.cpp b/BZOJ/2738/2738.cpp new file mode 100644 index 00000000..2ab7dfd3 --- /dev/null +++ b/BZOJ/2738/2738.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 505, + Q = 6e5 + 5; + +int n, q, ans[Q], tr[N][N]; +std::vector> qs; + +int lowbit(int x) { + return x & -x; +} + +void add(int x, int y, int v) { + for (int i = x; i <= n; i += lowbit(i)) { + for (int j = y; j <= n; j += lowbit(j)) { + tr[i][j] += v; + } + } +} + +int query(int x, int y) { + int res = 0; + + for (int i = x; i; i -= lowbit(i)) { + for (int j = y; j; j -= lowbit(j)) { + res += tr[i][j]; + } + } + + return res; +} + +void solve(const std::vector> &qs, long long l, long long r) { + if (qs.empty()) return; + + if (l == r) { + for (auto o : qs) { + if (std::get<5>(o)) { + ans[std::get<5>(o)] = l; + } + } + + return; + } + + long long mid = l + r >> 1; + std::vector> ql, qr; + + for (auto o : qs) { + int x, y, a, b, k, id; + + std::tie(x, y, a, b, k, id) = o; + + if (id) { + int t = query(a, b) - query(x - 1, b) - query(a, y - 1) + query(x - 1, y - 1); + + if (t >= k) { + ql.emplace_back(o); + } else { + qr.emplace_back(x, y, a, b, k - t, id); + } + } else { + if (k <= mid) { + add(x, y, 1); + ql.emplace_back(o); + } else { + qr.emplace_back(o); + } + } + } + + for (auto o : ql) { + int x, y, k, id; + + std::tie(x, y, std::ignore, std::ignore, k, id) = o; + + if (!id && k <= mid) add(x, y, -1); + } + + solve(ql, l, mid); + solve(qr, mid + 1, r); +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> q; + + for (int i = 1; i <= n; i++) { + for (int j = 1, x; j <= n; j++) { + cin >> x; + + qs.emplace_back(i, j, 0, 0, x, 0); + } + } + + for (int i = 1, x, y, a, b, k; i <= q; i++) { + cin >> x >> y >> a >> b >> k; + + qs.emplace_back(x, y, a, b, k, i); + } + + solve(qs, std::numeric_limits::min(), std::numeric_limits::max()); + + for (int i = 1; i <= q; i++) { + cout << ans[i] << endl; + } + + return 0; +} diff --git a/BZOJ/2738/data/1.in b/BZOJ/2738/data/1.in new file mode 100644 index 00000000..d598faaf --- /dev/null +++ b/BZOJ/2738/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d72c06e97a3c72473cf772733be03a358b024c33b742a9961f48993e7691724 +size 3634206 diff --git a/BZOJ/2738/data/1.out b/BZOJ/2738/data/1.out new file mode 100644 index 00000000..dfacacd8 --- /dev/null +++ b/BZOJ/2738/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ed099dc57ccbb14b4ffa7f110d2fa304c2c15472a7e9c1041048ed7f6fa3baf4 +size 587524 diff --git a/BZOJ/2738/data/10.in b/BZOJ/2738/data/10.in new file mode 100644 index 00000000..529e4d44 --- /dev/null +++ b/BZOJ/2738/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ea59afcf9917a87e1f01b69ba170137fd39b890449cdf35951108847ba82ce5 +size 2150733 diff --git a/BZOJ/2738/data/10.out b/BZOJ/2738/data/10.out new file mode 100644 index 00000000..ca022b95 --- /dev/null +++ b/BZOJ/2738/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e686fef6b5104b40e80965530361f02f77463c58d947783d32e4202ede5ead14 +size 293839 diff --git a/BZOJ/2738/data/11.in b/BZOJ/2738/data/11.in new file mode 100644 index 00000000..513170ae --- /dev/null +++ b/BZOJ/2738/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29be45d652d02ee66ef288816c5350fe9c719b856898ac0e47e5dc7de4de88a5 +size 2150520 diff --git a/BZOJ/2738/data/11.out b/BZOJ/2738/data/11.out new file mode 100644 index 00000000..831047bc --- /dev/null +++ b/BZOJ/2738/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84e51c80857c7fd6b0b01db25f9614de868274aaca2cfb84cb85a9d0be78f2c2 +size 293721 diff --git a/BZOJ/2738/data/12.in b/BZOJ/2738/data/12.in new file mode 100644 index 00000000..e3cae5f7 --- /dev/null +++ b/BZOJ/2738/data/12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abe765ed8472b770c5845af1421e1e4f8d2a942c46c1dd1e4988cba576f9d9d8 +size 113852 diff --git a/BZOJ/2738/data/12.out b/BZOJ/2738/data/12.out new file mode 100644 index 00000000..781361a3 --- /dev/null +++ b/BZOJ/2738/data/12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3858b0a79fe8dddfd7ffe464522445e275e921b71f4f77eb57f8676b33f701b6 +size 9795 diff --git a/BZOJ/2738/data/13.in b/BZOJ/2738/data/13.in new file mode 100644 index 00000000..1ecdcb86 --- /dev/null +++ b/BZOJ/2738/data/13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:207caacf3842bc9a821ab4000df0727f33aba74a1fcd0ffad4905d0327639eb6 +size 3633936 diff --git a/BZOJ/2738/data/13.out b/BZOJ/2738/data/13.out new file mode 100644 index 00000000..6987371f --- /dev/null +++ b/BZOJ/2738/data/13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:63bff31ab2d7aa517950ec4d2616ef4ef63e073b401cd8c6268002618431cd82 +size 587514 diff --git a/BZOJ/2738/data/14.in b/BZOJ/2738/data/14.in new file mode 100644 index 00000000..432f0855 --- /dev/null +++ b/BZOJ/2738/data/14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2ede6ed895e18a11837f8b35f8c3631c89b26762ea61573cf46e5e7dc85b31f2 +size 2150681 diff --git a/BZOJ/2738/data/14.out b/BZOJ/2738/data/14.out new file mode 100644 index 00000000..02a4b07b --- /dev/null +++ b/BZOJ/2738/data/14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:38eb80e006c52d9044fe35371d391a44f804401bfc69ffe1b9cb72a639a2ff17 +size 293870 diff --git a/BZOJ/2738/data/15.in b/BZOJ/2738/data/15.in new file mode 100644 index 00000000..c9b88b34 --- /dev/null +++ b/BZOJ/2738/data/15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:375f99f9ed846951efce69f05fc06c204944c1be8a34fd1b792876257ee4376d +size 3633620 diff --git a/BZOJ/2738/data/15.out b/BZOJ/2738/data/15.out new file mode 100644 index 00000000..2136c4f4 --- /dev/null +++ b/BZOJ/2738/data/15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81960f156279f00be16a295bf167867d01e9e85ad3ac55c9c7644d8fa001e5ff +size 587660 diff --git a/BZOJ/2738/data/16.in b/BZOJ/2738/data/16.in new file mode 100644 index 00000000..8051a318 --- /dev/null +++ b/BZOJ/2738/data/16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b1206a50a4c0322b908763d35ab52d23effea7ee2156478d06fafa8bdd27610 +size 113849 diff --git a/BZOJ/2738/data/16.out b/BZOJ/2738/data/16.out new file mode 100644 index 00000000..90ff5c48 --- /dev/null +++ b/BZOJ/2738/data/16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:333faff17de761b5cee98345418cb3d05add7b2a39f01043e59687cb60b67638 +size 9762 diff --git a/BZOJ/2738/data/17.in b/BZOJ/2738/data/17.in new file mode 100644 index 00000000..93b7adc6 --- /dev/null +++ b/BZOJ/2738/data/17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c6ee71784b8a9e6329ab6cec436a46c704201892943babb771ef745f09f0fcf +size 1071916 diff --git a/BZOJ/2738/data/17.out b/BZOJ/2738/data/17.out new file mode 100644 index 00000000..e6eabe2c --- /dev/null +++ b/BZOJ/2738/data/17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00b93709c3b74fb82c52c05923ceb12f446e64fc7b67378165663d34ce5fa363 +size 97952 diff --git a/BZOJ/2738/data/18.in b/BZOJ/2738/data/18.in new file mode 100644 index 00000000..2e9f58af --- /dev/null +++ b/BZOJ/2738/data/18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e89d14635da88dcd0640f097ea4e9a658d04bf8ee3378f540d9175b4d26143cc +size 1071731 diff --git a/BZOJ/2738/data/18.out b/BZOJ/2738/data/18.out new file mode 100644 index 00000000..5d96978a --- /dev/null +++ b/BZOJ/2738/data/18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:649196f726cff1527161070666ec072d39b271154a0022da9c2c703558fb9d25 +size 97973 diff --git a/BZOJ/2738/data/19.in b/BZOJ/2738/data/19.in new file mode 100644 index 00000000..34b1295f --- /dev/null +++ b/BZOJ/2738/data/19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3bd3b7bb47998e643d1d19033bff7183c74adae7217e1e20d85d5d6103699a1 +size 113821 diff --git a/BZOJ/2738/data/19.out b/BZOJ/2738/data/19.out new file mode 100644 index 00000000..74b63994 --- /dev/null +++ b/BZOJ/2738/data/19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:78394a96494c9e4c9d161cc2a8d736dc9444f3d8bb51ade32a4b82dc516599ee +size 9781 diff --git a/BZOJ/2738/data/2.in b/BZOJ/2738/data/2.in new file mode 100644 index 00000000..7cfbb7a8 --- /dev/null +++ b/BZOJ/2738/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f16306da61a1b544c33cc44a35327f011bc185b8ea09e77b6b42abe7a139584 +size 3633724 diff --git a/BZOJ/2738/data/2.out b/BZOJ/2738/data/2.out new file mode 100644 index 00000000..f16a58eb --- /dev/null +++ b/BZOJ/2738/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e1ecb657e57f96855cd284e1a47f39168642ceff6a12dde1aad8869f85751998 +size 587745 diff --git a/BZOJ/2738/data/20.in b/BZOJ/2738/data/20.in new file mode 100644 index 00000000..a95f0651 --- /dev/null +++ b/BZOJ/2738/data/20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e38c8d99ba9cb3cefc3b6b264b442bf7748de56c75e1906f558db22587f2c49f +size 1071812 diff --git a/BZOJ/2738/data/20.out b/BZOJ/2738/data/20.out new file mode 100644 index 00000000..8c964fe4 --- /dev/null +++ b/BZOJ/2738/data/20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11a2d679142dfa7b484d135c54683a962526fb8e401a8b924ed70d7e93ad0faf +size 98016 diff --git a/BZOJ/2738/data/3.in b/BZOJ/2738/data/3.in new file mode 100644 index 00000000..3de5f12e --- /dev/null +++ b/BZOJ/2738/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46d92de4a9cf8171271da137972b49aa43feb28db0bb8af40907801d872e24dc +size 3633849 diff --git a/BZOJ/2738/data/3.out b/BZOJ/2738/data/3.out new file mode 100644 index 00000000..84aea9dd --- /dev/null +++ b/BZOJ/2738/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7dfaa27fd9e9f8a25658ec43e3bb184a312f8dbf544ec1fad6b7ac787c0b658f +size 587486 diff --git a/BZOJ/2738/data/4.in b/BZOJ/2738/data/4.in new file mode 100644 index 00000000..9402ab19 --- /dev/null +++ b/BZOJ/2738/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99a171f7694b2e8506af911b424087f4770a3e8b1e7610b00cf08d3c366df273 +size 3634064 diff --git a/BZOJ/2738/data/4.out b/BZOJ/2738/data/4.out new file mode 100644 index 00000000..6bb181ec --- /dev/null +++ b/BZOJ/2738/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fceba3d9941525c82b407eb52c4a65cc7be792c15f32dcc51f18cfd5b521a3f2 +size 587667 diff --git a/BZOJ/2738/data/5.in b/BZOJ/2738/data/5.in new file mode 100644 index 00000000..22009a1c --- /dev/null +++ b/BZOJ/2738/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:35bd76f58837b03a1f050bf3344adb847a959eeac850d61cdb9a9d424f10b63e +size 1071623 diff --git a/BZOJ/2738/data/5.out b/BZOJ/2738/data/5.out new file mode 100644 index 00000000..bfa1c346 --- /dev/null +++ b/BZOJ/2738/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a339e267c8c868417e75c05a2d7abc1b9e6397f9071ff3ed80a36b9af406acb7 +size 97963 diff --git a/BZOJ/2738/data/6.in b/BZOJ/2738/data/6.in new file mode 100644 index 00000000..488146b9 --- /dev/null +++ b/BZOJ/2738/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f82813b73635f70b989d68efece4b974431dee7da52f15f49e12ab37520105c +size 3633589 diff --git a/BZOJ/2738/data/6.out b/BZOJ/2738/data/6.out new file mode 100644 index 00000000..6653b953 --- /dev/null +++ b/BZOJ/2738/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1467d1175e4fedd40d24aad202d7c9d6a7529a23327631e1e4c0270dd4582d1b +size 587520 diff --git a/BZOJ/2738/data/7.in b/BZOJ/2738/data/7.in new file mode 100644 index 00000000..3be5f79d --- /dev/null +++ b/BZOJ/2738/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8f7e00e5c1855554992b7d230f4f7f540882fed4f637f1af02a46a0b68a83f0 +size 113869 diff --git a/BZOJ/2738/data/7.out b/BZOJ/2738/data/7.out new file mode 100644 index 00000000..54ec4220 --- /dev/null +++ b/BZOJ/2738/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16ee2c27074384dfec0e79851b00d074d0957f03254af8e87b5fdecf57dd300b +size 9797 diff --git a/BZOJ/2738/data/8.in b/BZOJ/2738/data/8.in new file mode 100644 index 00000000..a68ebad9 --- /dev/null +++ b/BZOJ/2738/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bec92991ded6639237f2dfa426810249b7c0b4a5b4ef1f82b9d0d0a5ae53fd75 +size 2150195 diff --git a/BZOJ/2738/data/8.out b/BZOJ/2738/data/8.out new file mode 100644 index 00000000..7010ff22 --- /dev/null +++ b/BZOJ/2738/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fef154489e43ecd000ae2eade2b3cee1a84e0fbf39a4f58d31c9700ae2b7eda1 +size 293793 diff --git a/BZOJ/2738/data/9.in b/BZOJ/2738/data/9.in new file mode 100644 index 00000000..d233f7f3 --- /dev/null +++ b/BZOJ/2738/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e8635f8d26dd194c814cef3665f682086f35b7a735ec0f4a2e4f81345f00224e +size 3633378 diff --git a/BZOJ/2738/data/9.out b/BZOJ/2738/data/9.out new file mode 100644 index 00000000..8d4b981b --- /dev/null +++ b/BZOJ/2738/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae0ad1d5151b3bbc032f5a71aa6618d79cdd9b06298741395d1d666f6e4f6127 +size 587367