QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149747 | #5441. Quartz Collection | tanao | WA | 4ms | 28816kb | C++14 | 1.8kb | 2023-08-25 13:57:19 | 2023-08-25 13:57:21 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
#define MAX_N 200010
#define N 200000
using namespace std;
ll c[MAX_N<<1];
struct node
{
ll siz,sum[4];
}s[MAX_N<<3];
namespace SEG
{
void up(node&p,node l,node r)
{
p.siz=l.siz+r.siz;
for(ll i=0;i<4;++i)
p.sum[i]=l.sum[i]+r.sum[(i-l.siz%4+4)%4];
}
void build(ll p,ll l,ll r)
{
if(l==r)
{
if(!c[l])return;
s[p].siz=c[l];
for(ll i=0;i<4;++i)s[p].sum[i]=(c[l]/4+((c[l]-1)%4>=i&&c[l]))*(l-N);
return;
}
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
up(s[p],s[p<<1],s[p<<1|1]);
}
node query(ll p,ll l,ll r,ll x,ll y)
{
if(x<=l&&r<=y)return s[p];
node a={0,{0}},b={0,{0}};
if(x<=mid)a=query(p<<1,l,mid,x,y);
if(y>mid)b=query(p<<1|1,mid+1,r,x,y);
up(a,a,b);
return a;
}
void change(ll p,ll l,ll r,ll x,ll c)
{
if(l==r)
{
s[p].siz+=c;
if(c==1)s[p].sum[(s[p].siz-1)%4]+=l-N;
else s[p].sum[s[p].siz%4]-=l-N;
return;
}
if(x<=mid)change(p<<1,l,mid,x,c);
else change(p<<1|1,mid+1,r,x,c);
up(s[p],s[p<<1],s[p<<1|1]);
}
}
ll a[MAX_N],b[MAX_N];
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
ll n,m;cin>>n>>m;
multiset<ll>s;ll sumb=0;
for(ll i=1;i<=n;++i)cin>>a[i]>>b[i],c[a[i]-b[i]+N]++,sumb+=b[i];
SEG::build(1,1,2*N);
node l=SEG::query(1,1,2*N,1,N),r=SEG::query(1,1,2*N,N+1,2*N);
cout<<l.sum[0]+l.sum[3]+r.sum[l.siz%2==0?0:1]+r.sum[l.siz%2==0?2:3]+sumb<<endl;
while(m--)
{
ll t,x,y;
cin>>t>>x>>y;
SEG::change(1,1,2*N,a[t]-b[t]+N,-1);sumb-=b[t];
a[t]=x,b[t]=y;
SEG::change(1,1,2*N,a[t]-b[t]+N,1);sumb+=b[t];
node l=SEG::query(1,1,2*N,1,N),r=SEG::query(1,1,2*N,N+1,2*N);
cout<<l.sum[0]+l.sum[3]+r.sum[l.siz%2==0?0:1]+r.sum[l.siz%2==0?2:3]+sumb<<endl;
}
return 0;
}
/*
-2 -2 -6 1//
-6 -2 -2 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 27464kb
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: 28816kb
input:
1 1 1 1 1 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 27588kb
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:
5201 5157 5152 5099 5067 5085 5042 5020 5014 5022 5040 5007 4977 4955 4990 4956 4929 4879 4885 4866 4822 4800 4751 4709 4638 4710 4746 4779 4769 4777 4806 4825 4820 4793 4752 4723 4720 4774 4835 4869 4856 4864 4846 4851 4807 4836 4764 4779 4792 4741 4703 4635 4615 4646 4697 4677 4624 4612 4581 4597 ...
result:
wrong answer 1st numbers differ - expected: '5109', found: '5201'