QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#130315 | #3300. Cactus Competition | sinsop90 | WA | 5ms | 23152kb | C++14 | 4.0kb | 2023-07-23 20:32:47 | 2023-07-23 20:32:48 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 3e5 + 5;
int n, m, a[maxn], b[maxn], f[maxn][25][2], g[maxn][25], ans, tot;
struct ASK {
int x, xx, y, yy;
}Q[maxn << 2];
struct SMT {
int sum, tag;
}tr[maxn << 2];
struct Rask {
int l, r, op;
};
vector<Rask> vec[maxn];
int querymax(int l, int r, int op) {
int len = log2(r - l + 1);
// cout << l << " " << r << " " << len << " " << f[l][len][op] << endl;
return max(f[l][len][op], f[r - (1 << len) + 1][len][op]);
}
int querymin(int l, int r, int op) {
int len = log2(r - l + 1);
return min(g[l][len], g[r - (1 << len) + 1][len]);
}
int ls(int p) {
return p << 1;
}
int rs(int p) {
return p << 1 | 1;
}
void pushup(int p) {
if(tr[p].tag) return;
tr[p].sum = tr[ls(p)].sum + tr[rs(p)].sum;
}
void update(int p, int l, int r, int nl, int nr, int op) {
if(nl <= l && r <= nr) {
tr[p].tag += op;
if(!tr[p].tag) tr[p].sum = tr[ls(p)].sum + tr[rs(p)].sum;
else if(tr[p].tag == 1) tr[p].sum = r - l + 1;
return;
}
int mid = (l + r) >> 1;
if(nl <= mid) update(ls(p), l, mid, nl, nr, op);
if(nr > mid) update(rs(p), mid + 1, r, nl, nr, op);
pushup(p);
}
int vis[105][105];
signed main() {
// freopen("M.in", "r", stdin);
// freopen("my.out", "w", stdout);
scanf("%lld%lld", &n, &m);
for(int i = 1;i <= n;i++) scanf("%lld", &a[i]), f[i][0][0] = a[i];
for(int i = 1;i <= m;i++) scanf("%lld", &b[i]), f[i][0][1] = b[i], g[i][0] = b[i];
for(int i = 1;(1 << i) <= n;i++) for(int j = 1;j + (1 << i) - 1 <= n;j++) f[j][i][0] = max(f[j][i - 1][0], f[j + (1 << i - 1)][i - 1][0]);
// cout << f[1][0][1] << endl;
for(int i = 1;(1 << i) <= m;i++) for(int j = 1;j + (1 << i) - 1 <= m;j++) f[j][i][1] = max(f[j][i - 1][1], f[j + (1 << i - 1)][i - 1][1]), g[j][i] = min(g[j][i - 1], g[j + (1 << i - 1)][i - 1]);
for(int i = 1;i <= n;i++) {
int l = 1, r = m, res = 0;
while(l <= r) {
int mid = (l + r) >> 1;
if(querymax(1, mid, 'b' - 'a') + a[i] < 0) res = mid, l = mid + 1;
else r = mid - 1;
}
if(!res) continue;
// cout << i << " " << res << " " << querymax(1, res, 'b' - 'a') << " " << f[1][0][1] << endl;
int p = querymin(1, res, 'b' - 'a');
l = 1, r = i, res = i;
while(l <= r) {
int mid = (l + r) >> 1;
if(querymax(mid, i, 'a' - 'a') + p < 0) res = mid, r = mid - 1;
else l = mid + 1;
}
Q[++ tot] = {res, i, 1, n};
// cout << "1: " << res << " " << i << endl;
}
for(int i = 1;i <= n;i++) {
int l = 1, r = m, res = m + 1;
while(l <= r) {
int mid = (l + r) >> 1;
if(querymax(mid, m, 'b' - 'a') + a[i] < 0) res = mid, r = mid - 1;
else l = mid + 1;
}
if(res == m + 1) continue;
int p = querymin(res, m, 'b' - 'a');
l = i, r = m, res = i;
while(l <= r) {
int mid = (l + r) >> 1;
if(querymax(i, mid, 'a' - 'a') + p < 0) res = mid, l = mid + 1;
else r = mid - 1;
}
// cout << querymax(2, 3, 0) + p << endl;
Q[++ tot] = {1, n, i, res};
// cout << "2: " << i << " " << res << endl;
}
for(int i = 1;i <= n;i++) {
if(a[i] + querymax(1, m, 'b' - 'a') < 0) Q[++ tot] = {1, i, i, n};
}
int rt = 0;
for(int i = 1;i <= m;i++) if(b[i] < b[rt]) rt = i;
for(int i = 1;i <= n;i++) {
int now = i - 1;
while(now < n && a[now + 1] + b[rt] < 0) now ++;
if(now == i - 1) continue;
Q[++ tot] = {i, now, i, now};
i = now;
}
for(int i = 2;i <= n;i++) Q[++ tot] = {i, i, 1, i - 1};
for(int i = 1;i <= tot;i++) {
for(int j = Q[i].x;j <= Q[i].xx;j++) for(int k = Q[i].y;k <= Q[i].yy;k++) vis[j][k] = 1;
// cout << Q[i].x << " " << Q[i].xx << " " << Q[i].y << " " << Q[i].yy << endl;
// cout << vis[7][6] << endl;
vec[Q[i].x].push_back({Q[i].y, Q[i].yy, 1}), vec[Q[i].xx + 1].push_back({Q[i].y, Q[i].yy, -1});
}
// for(int i = n;i >= 1;i--) {
// for(int j = 1;j <= n;j++) printf("%d ", vis[j][i]);
// puts("");
// }
for(int i = 1;i <= n + 1;i++) {
// cout << tr[1].sum << endl;
ans += tr[1].sum;
for(Rask t : vec[i]) update(1, 1, n, t.l, t.r, t.op);
}
printf("%lld\n", n * n - ans);
}
/*
5
1 0 -1 -2 1
0 1 1 0 1
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 22468kb
input:
3 3 -1 0 1 -1 0 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 22556kb
input:
3 3 -1 0 1 1 0 1
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 3ms
memory: 21820kb
input:
10 10 145195799 312862766 143966779 -11056226 -503624929 636383890 -182650312 -382759112 -290767690 377894950 -845235881 -418232930 -600566938 -957917357 -181139226 125255273 -175406945 740226783 -750456842 325848662
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 2ms
memory: 22672kb
input:
10 10 923415743 -503391272 885740174 329644337 -693052351 -53764994 731859967 -834732760 -57751504 151969590 553689579 313784278 -12090771 921222379 -378313551 819586787 -373658045 559813071 671861309 268258615
output:
13
result:
ok single line: '13'
Test #5:
score: 0
Accepted
time: 0ms
memory: 21052kb
input:
10 10 -123276196 264891802 609485405 -980113903 152483893 57563748 -454135131 618686452 545983457 236619926 648896419 838269531 -380077537 536463844 89691984 38425645 759165084 325716532 330825142 -472414030
output:
12
result:
ok single line: '12'
Test #6:
score: 0
Accepted
time: 1ms
memory: 21436kb
input:
10 10 982508669 144806400 -503165973 760719995 -249757698 -573349946 -974145393 -905114292 218260516 -582308724 -341366248 187422683 298181900 -305351333 -616330465 -358958909 499163196 -967112195 -892547772 -605274022
output:
1
result:
ok single line: '1'
Test #7:
score: 0
Accepted
time: 4ms
memory: 21052kb
input:
10 10 -46634296 998649898 637256009 858343376 -339756903 750734027 533317110 509238419 -386390857 573123021 281094131 -798662878 454769235 -725579556 448648301 -937460999 -94310392 -504422439 -566805692 -883657655
output:
2
result:
ok single line: '2'
Test #8:
score: 0
Accepted
time: 4ms
memory: 21272kb
input:
10 10 -448680004 -918586552 -352190179 959516158 674275159 -778874335 -736749389 -368418013 103878020 562512923 -493932809 -736960513 78543198 885372691 -119140562 627952281 733778437 115556860 -196686999 -530143800
output:
3
result:
ok single line: '3'
Test #9:
score: 0
Accepted
time: 4ms
memory: 21724kb
input:
10 10 438736217 -79057408 749090846 -106479211 -864134653 49806870 -724192950 -354806728 -230893984 130090227 -313678558 -493317070 -704907097 -240066585 275905249 -440144088 -697190358 608351624 783121279 -54163556
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 2ms
memory: 22856kb
input:
10 10 910467973 475480237 284540173 -490003419 -496858639 575308046 -772115835 -650286781 -946294433 -375903216 465208966 198897340 37926241 -452764487 81169636 803610511 943188813 773420180 248487883 -932609634
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 2ms
memory: 21096kb
input:
10 10 -717662422 899539843 686516865 -308859590 731187727 948271874 -278705921 533338789 378708586 -53953529 -819295682 -712753496 -588162402 -765119207 518537239 793210677 199564253 443460314 248599384 333581283
output:
14
result:
ok single line: '14'
Test #12:
score: 0
Accepted
time: 5ms
memory: 22884kb
input:
10 10 13154473 419018121 -416088051 751464183 -782740304 257733919 -917880927 -690282918 410240353 817939924 440852087 -846511822 -519300757 153508300 757901474 928246448 -132837037 -603019187 860960474 -381787006
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 0ms
memory: 22904kb
input:
10 10 -357608489 679822152 25019791 265926477 -309098231 -7866110 -344995594 54868813 319830921 627547981 -431127028 -396320203 -35574917 657270168 -452580497 -359511978 -443174072 195670048 -696354158 2633147
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 1ms
memory: 22352kb
input:
10 10 126298083 -169291689 736314121 784469908 642788743 -450191333 -98804016 -511077469 -691147937 -275067405 440527703 -329746015 -473928781 -114255013 -450714278 -903623369 888225605 -146644734 173060316 214649350
output:
0
result:
ok single line: '0'
Test #15:
score: 0
Accepted
time: 3ms
memory: 23152kb
input:
10 10 -631748556 73286407 324751086 157696597 846447361 -444570059 484021795 -258058046 -116283058 -158063251 712663587 -233692952 820220037 516771553 879333593 156354440 -36643636 -639052753 -790959020 950256682
output:
30
result:
ok single line: '30'
Test #16:
score: 0
Accepted
time: 1ms
memory: 22968kb
input:
20 10 -623445264 -424346675 38726811 -683309080 312098721 491569101 58067873 265188450 933087599 -786006093 -652539909 -790632832 780472328 -854541037 -851647529 130095820 35107516 -49396621 -476857996 -420750398 102904427 387758770 -297785914 -909492241 54351476 480814965 -450898650 532245762 14578...
output:
5
result:
ok single line: '5'
Test #17:
score: 0
Accepted
time: 5ms
memory: 22992kb
input:
20 10 -896420596 -203318573 177883279 273218889 -57519747 -45966158 -776510191 -517769446 453200208 481678849 182234053 -9041974 599680026 114185708 -42217888 -909337940 901125545 -573238491 923694668 317307691 -39965725 441117134 808874018 742445820 195129663 -895470087 -362043267 -116187269 768684...
output:
5
result:
ok single line: '5'
Test #18:
score: 0
Accepted
time: 3ms
memory: 23136kb
input:
20 10 -353233765 531419122 -565785466 -974734316 -965779178 -574407138 -468557050 143840293 -215604312 -616224273 -898730647 860935752 160786259 790117305 493435217 142732932 -298131838 151928054 -491642434 354879620 -793096213 -805492095 -608815122 348634111 -671513949 992581086 -838707020 58016785...
output:
9
result:
ok single line: '9'
Test #19:
score: 0
Accepted
time: 1ms
memory: 21624kb
input:
20 10 -701460484 808554993 -999153824 -785817990 -733107864 102913155 -574790819 366838774 386927511 368140655 -817331097 -532497190 -875689404 26653738 514253474 -613613559 138082391 199526495 -340809187 -265988736 139281656 -212060959 990432379 509453538 322401348 415039202 713351409 656821225 -37...
output:
1
result:
ok single line: '1'
Test #20:
score: -100
Wrong Answer
time: 1ms
memory: 21432kb
input:
20 10 283365694 154990137 -35366598 -650189405 -536760259 988010949 -588839879 419138587 473855117 783095177 -727335506 -711138940 688902025 848042392 -418956949 -551400268 -445912306 328186693 902566329 -781464261 -151440066 304048484 39686192 -66659263 690407227 450204900 21929380 -636199785 -2908...
output:
18
result:
wrong answer 1st lines differ - expected: '16', found: '18'