QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#144057 | #4918. 染色 | heyangyang | 0 | 716ms | 167040kb | C++14 | 4.5kb | 2023-08-21 15:25:43 | 2023-08-21 15:25:48 |
Judging History
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});
if (it != T[id].begin()) 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
Wrong Answer
Test #1:
score: 10
Accepted
time: 11ms
memory: 100316kb
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: 0
Accepted
time: 16ms
memory: 97472kb
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:
0 0 0 1090256298972435763 147836376791542005 2987455658418197192 17393388322162025577 0 15463425577465259729 5603739312727078592 9162759280430770517 5734982725161877299 17209386033616770563 4838930779004365643 849737692109005723 6426101344117061130 5419322161439603233 5062725202245147693 71096115354...
result:
ok 245 tokens
Test #3:
score: -10
Wrong Answer
time: 9ms
memory: 101128kb
input:
1000 1000 3 99 666 17220025026447219412 4 5 483 3 749 845 16031212477837693538 3 133 609 17502764194597679430 1 20 226 5 4 251 561 4 633 824 4 200 311 4 519 771 1 441 468 4 1 143 922 2 3 125 229 12754000280540900298 1 498 505 6 1 363 450 3 2 271 554 3 1 114 704 4 2 120 814 2 3 690 982 45445988286128...
output:
7328512720450443476 7442164624875844502 14518824065043662144 15136137278022830944 9027578627713658176 14666047547670987011 9573739028108360400 15993305979184887208 14884581396130778517 17761136731703624839 13312122318790827838 14347674975080853967 17128890277609978434 9773479657321740818 15378095570...
result:
wrong answer 53rd words differ - expected: '17307351699015109712', found: '3115927441791180404'
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 716ms
memory: 167040kb
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: 563ms
memory: 161072kb
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 10221802998207082170 11260979534991171848 15330757429201569746 0 4774641114671397458 12106296338416626678 0 8778885470154990195 0 0 0 10270101177550224023 11917196698575719908 6298384012519653477 12893243169920745029 0 0 0 0 0 438673155602015608 8244748990550860359 12582707994431266683 853282204...
result:
wrong answer 3rd words differ - expected: '16968625150574630951', found: '10221802998207082170'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%