QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#224698 | #5441. Quartz Collection | ZSH_ZSH# | WA | 8ms | 8500kb | C++14 | 3.9kb | 2023-10-23 09:40:21 | 2023-10-23 09:40:21 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for (register int i=(a);i<=(b);i++)
#define drep(i,a,b) for (register int i=(a);i>=(b);i--)
typedef long long ll;
using namespace std;
const int N=300010;
int n,a[N],b[N],m;
struct info
{
int ls,rs,rnd,tag,val,X,size;
ll sum;
}t[N];
inline void push_up(int x)
{
t[x].sum=t[x].val;
if (t[x].ls) t[x].sum+=t[t[x].ls].sum;
if (t[x].rs) t[x].sum+=t[t[x].rs].sum;
t[x].size=1;
if (t[x].ls) t[x].size+=t[t[x].ls].size;
if (t[x].rs) t[x].size+=t[t[x].rs].size;
}
void setcov(int node)
{
t[node].tag^=1;
t[node].val=-t[node].val;
t[node].sum=-t[node].sum;
}
inline void push_down(int x)
{
if (t[x].tag)
{
if (t[x].ls) setcov(t[x].ls);
if (t[x].rs) setcov(t[x].rs);
t[x].tag=0;
}
}
array<int,2> split(int x,int X)
{
if (!x) return {0,0};
push_down(x);
if (t[x].X<=X)
{
auto rs=split(t[x].rs,X);
t[x].rs=rs[0];
push_up(x);
return {x,rs[1]};
}
else
{
auto ls=split(t[x].ls,X);
t[x].ls=ls[1];
push_up(x);
return {ls[0],x};
}
}
array<int,2> splitsz(int x,int sz)
{
if (!x) return {0,0};
push_down(x);
if (t[t[x].ls].size+1<=sz)
{
auto rs=splitsz(t[x].rs,sz-t[t[x].ls].size-1);
t[x].rs=rs[0];
push_up(x);
return {x,rs[1]};
}
else
{
auto ls=splitsz(t[x].ls,sz);
t[x].ls=ls[1];
push_up(x);
return {ls[0],x};
}
}
void dfs(int x)
{
printf("x %d ls %d rs %d\n",x,t[x].ls,t[x].rs);
push_down(x);
if (t[x].ls) dfs(t[x].ls);
if (t[x].rs) dfs(t[x].rs);
}
int merge(int x,int y)
{
if (!x||!y)
{
if (x||y) push_up(x+y);
return x+y;
}
push_down(x);
push_down(y);
if (t[x].rnd<t[y].rnd)
{
t[x].rs=merge(t[x].rs,y);
push_up(x);
return x;
}
else
{
t[y].ls=merge(x,t[y].ls);
push_up(y);
return y;
}
}
mt19937 rng(time(0));
int rt[5],cnt;
map<int,int> mp;
void ins(int x)
{
mp[x]++;
if (x<=0)
{
array<int,2> s[4];
rep(i,0,3) s[i]=split(rt[i],x);
t[++cnt].rnd=rng();
t[cnt].X=x;
t[cnt].val=x;
t[cnt].sum=x;
t[cnt].size=1;
int id=0;
rep(i,0,3) id+=t[s[i][0]].size;
id++; id%=4;
s[id][0]=merge(s[id][0],cnt);
rep(i,0,3) rt[i]=merge(s[i][0],s[(i+3)%4][1]);
}
else
{
auto s=split(rt[4],x);
t[++cnt].rnd=rng();
t[cnt].X=x;
t[cnt].val=t[cnt].sum=((t[s[0]].size%2==1)?x:-x);
t[cnt].size=1;
if (s[1]) setcov(s[1]);
rt[4]=merge(merge(s[0],cnt),s[1]);
}
}
void del(int x)
{
assert(mp[x]);
mp[x]--;
if (x<=0)
{
array<int,2> s[4];
rep(i,0,3) s[i]=split(rt[i],x);
int id=0;
rep(i,0,3) id+=t[s[i][0]].size;
id%=4;
{
auto ss=splitsz(s[id][0],t[s[id][0]].size-1);
s[id][0]=ss[0];
}
rep(i,0,3) rt[i]=merge(s[i][0],s[(i+1)%4][1]);
}
else
{
assert(t[rt[4]].size);
// printf("rt4 %d size %d\n",rt[4],t[rt[4]].size);
// dfs(rt[4]);
// {
// auto sss=splitsz(rt[4],t[rt[4]].size-1);
// printf("sss0 %d sss1 %d\n",sss[0],sss[1]);
// assert(t[sss[1]].size==1);
//// assert(t[sss[1]].X>=x);
// rt[4]=merge(sss[0],sss[1]);
// assert(t[rt[4]].size);
// }
auto s=split(rt[4],x);
auto ss=splitsz(s[0],t[s[0]].size-1);
if (s[1]) setcov(s[1]);
rt[4]=merge(ss[0],s[1]);
}
}
ll xns;
void solve()
{
ll ans=xns;
ans+=t[rt[0]].sum+t[rt[1]].sum;
ans-=t[rt[2]].sum+t[rt[3]].sum;
int sz=0;
rep(i,0,3) sz+=t[rt[i]].size;
sz%=2;
if (sz==0)
{
ans-=t[rt[4]].sum;
}
else ans+=t[rt[4]].sum;
printf("%lld\n",ans/2);
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m;
rep(i,1,n) cin>>a[i]>>b[i],a[i]*=2,b[i]*=2;
rep(i,1,n)
{
xns+=(a[i]+b[i])/2;
ins((a[i]-b[i])/2);
}
solve();
rep(i,1,m)
{
int t,A,B; cin>>t>>A>>B;
A*=2; B*=2;
xns-=((a[t]+b[t])/2);
del((a[t]-b[t])/2);
a[t]=A,b[t]=B;
xns+=((a[t]+b[t])/2);
ins((a[t]-b[t])/2);
solve();
}
return 0;
}
/*
4 5
2 4
5 7
1 7
2 1
4 5 2
1 6 2
4 4 3
2 1 3
3 6 6
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6016kb
input:
4 5 2 4 5 7 1 7 2 1 4 5 2 1 6 2 4 4 3 2 1 3 3 6 6
output:
13 14 15 14 10 13
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 6016kb
input:
1 1 1 1 1 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 6020kb
input:
100 100 6 7 100 8 5 61 5 75 59 65 51 47 83 37 34 54 87 46 4 26 21 87 12 97 86 68 60 11 62 76 14 83 29 31 91 62 57 80 47 75 85 97 62 77 91 86 14 25 48 77 83 65 39 61 78 77 45 46 90 74 100 91 86 98 55 5 84 42 91 69 100 4 74 98 60 37 75 44 41 12 15 34 36 1 99 16 7 87 36 26 79 42 41 84 17 98 72 16 38 55...
output:
5109 5065 5060 5007 4975 4993 4950 4928 4922 4930 4948 4915 4885 4863 4898 4864 4837 4787 4793 4774 4730 4708 4659 4617 4546 4618 4654 4687 4677 4685 4714 4733 4728 4701 4660 4631 4628 4682 4743 4777 4764 4772 4754 4759 4715 4744 4672 4687 4700 4649 4611 4543 4523 4554 4605 4585 4532 4520 4489 4505 ...
result:
ok 101 numbers
Test #4:
score: 0
Accepted
time: 3ms
memory: 6112kb
input:
1000 1000 411 789 753 186 495 203 417 324 490 424 195 480 314 23 663 218 12 747 124 390 134 38 218 536 291 840 174 908 474 767 313 167 575 9 857 427 313 27 959 935 258 70 472 957 747 228 205 939 293 303 626 802 712 283 658 346 208 383 889 204 99 640 801 966 828 742 534 11 259 734 226 129 843 350 50 ...
output:
490601 490340 490353 490689 490697 490600 490571 491078 491388 491507 491729 491809 491984 492228 492161 492171 492384 492276 492693 492547 492372 492580 492350 492795 492635 492941 492936 492797 492359 492108 492670 492589 492570 492700 492910 492401 492274 492263 491905 491692 492032 492168 492350...
result:
ok 1001 numbers
Test #5:
score: 0
Accepted
time: 8ms
memory: 6532kb
input:
5000 1000 72520 61541 4609 95655 27768 67682 48763 4836 63868 3082 44496 5022 70138 88832 25864 48681 5212 79532 1134 60190 84561 98392 91027 55707 72938 83316 60044 93249 82269 88819 83951 6069 35302 29132 1882 68479 3489 45817 79436 37261 88849 763 23786 62641 89532 32244 85372 46815 6765 56651 27...
output:
249456797 249463957 249477751 249431759 249421636 249444892 249421159 249434259 249445362 249448397 249505520 249532943 249538838 249493562 249475570 249507883 249503390 249512573 249524766 249475431 249511948 249496484 249455533 249428931 249385128 249380512 249370595 249390331 249422343 249398748 ...
result:
ok 1001 numbers
Test #6:
score: 0
Accepted
time: 8ms
memory: 6472kb
input:
4990 1000 28197 37778 70449 79157 73746 9790 57859 34774 60067 24125 4809 99133 51444 84059 21094 41904 63475 27833 23189 61130 3203 19272 87649 64152 92473 74674 85227 38234 55074 55761 80744 89480 23995 39894 49024 88746 57815 10851 10032 29151 9757 78417 77993 19383 39272 26155 39279 69209 64005 ...
output:
250090553 250118970 250123190 250148475 250125939 250104267 250093819 250095617 250069068 250084722 250077812 250113699 250078954 250113860 250175483 250182518 250204543 250223709 250264020 250312567 250359944 250405159 250405818 250426052 250472672 250505450 250530824 250554819 250565666 250535021 ...
result:
ok 1001 numbers
Test #7:
score: 0
Accepted
time: 4ms
memory: 8500kb
input:
4991 1000 39678 1249 54437 46017 45224 70229 17603 34864 29604 94448 85430 12263 55898 14782 85335 5653 87061 43854 64868 7691 89219 13493 36702 86976 59640 93900 95498 13230 31210 90574 51152 91506 21366 27131 6431 61743 75930 9336 44487 87340 70841 92525 2237 10001 35034 39269 15226 49198 30121 79...
output:
251570351 251589172 251538274 251520847 251547567 251518079 251492735 251519194 251505737 251483325 251462868 251443905 251469527 251466065 251440294 251390410 251368713 251377575 251395027 251339405 251359785 251351536 251300033 251339703 251323391 251335851 251351155 251372302 251421798 251435651 ...
result:
ok 1001 numbers
Test #8:
score: -100
Wrong Answer
time: 8ms
memory: 6460kb
input:
4992 1000 18454 5936 5721 80172 82110 63373 77346 34954 88742 64771 33347 84178 3457 12800 58088 93594 34839 51363 39251 21548 32131 7715 94267 68584 26806 70022 14280 98625 74643 59979 13048 58940 75633 14369 63838 45140 61340 75117 68541 45528 56117 72040 93777 67915 20397 60895 34278 96484 37454 ...
output:
249618219 249654234 249683165 249682436 249677245 249628244 249704005 249718772 249748178 249768835 249796157 249823793 249843763 249886481 249909282 249917273 249905042 249881567 249839421 249856597 249875790 249876920 249906243 249961596 249989304 249974693 250004114 250012548 249987610 249979537 ...
result:
wrong answer 984th numbers differ - expected: '251256923', found: '251308410'