QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227650 | #5441. Quartz Collection | ucup-team870 | WA | 2ms | 11836kb | C++20 | 2.1kb | 2023-10-27 20:38:23 | 2023-10-27 20:38:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,l,r) for(int i=(l); i<=(r); i++)
#define per(i,r,l) for(int i=(r); i>=(l); i--)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
#define ilr int i,int l,int r
#define mi int mid=((l+r)-((l+r)%2!=0))/2;
#define ls i<<1
#define rs i<<1|1
const int N=2e5+5,inf=1e5;
P a[N];
ll sum,dif;
struct T{
int sz; ll v[4];
void add(int x){
v[(++sz)%4]+=x;
}
void del(int x){
v[(sz--)%4]-=x;
}
ll cal(){
return v[1]+v[0];
}
ll cal2(){
return v[2]+v[3];
}
void ot(){
cout<<sz<<" : "; rep(i,0,3)cout<<v[i]<<" "; cout<<"ot\n";
}
}s[N<<2];
T operator +(T a,T b){
T c; c.sz=a.sz+b.sz;
int tmp=((-a.sz)%4+4)%4;
rep(i,0,3){
c.v[i]=a.v[i]+b.v[(i+tmp)%4];
}
return c;
}
void ud(ilr,int x,int v){
// cout<<l<<' '<<r<<' '<<x<<' '<<v<<endl;
if(l==r){
if(v==1)s[i].add(x);
else s[i].del(x);
return;
}
mi
if(mid>=x)ud(ls,l,mid, x,v);
else ud(rs,mid+1,r, x,v);
s[i]=s[i<<1]+s[i<<1|1];
}
T qu(ilr,int x,int y){
if(l>=x && r<=y)return s[i];
mi T res={0};
if(mid>=x)res=qu(ls,l,mid,x,y);
if(y>mid)res=res+qu(rs,mid+1,r,x,y);
return res;
}
ll cal(){
T rl=qu(1,-inf,inf,-inf,0);
ll res=rl.cal();
T rr=qu(1,-inf,inf,1,inf);
if(rl.sz&1)res+=rr.cal2();
else res+=rr.cal();
ll da=res,db=dif-res;
// rl.ot(); rr.ot();
// cout<<da<<' '<<db<<'\n';
return (da-db+sum)/2;
}
signed main(){
IOS
int n,Q; cin>>n>>Q;
rep(i,1,n){
int x,y; cin>>x>>y;
sum+=x+y; dif+=x-y;
a[i]={x,y};
ud(1,-inf,inf,x-y,1);
}
cout<<cal()<<'\n';
rep(_,1,Q){
int t,x,y; cin>>t>>x>>y;
auto [px,py]=a[t];
sum+=(x+y)-(px+py); dif+=(x-y)-(px-py);
a[t]={x,y};
ud(1,-inf,inf,px-py,-1);
ud(1,-inf,inf,x-y,1);
cout<<cal()<<'\n';
}
}
/*
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: 0ms
memory: 11636kb
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: 0ms
memory: 7588kb
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: 2ms
memory: 11836kb
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:
5133 5032 5028 5029 4997 5017 4974 5004 4951 5012 4975 4942 4912 4896 4978 4944 4861 4811 4813 4750 4752 4686 4636 4648 4577 4650 4628 4709 4699 4707 4736 4811 4757 4779 4738 4709 4705 4759 4822 4856 4793 4797 4776 4736 4743 4822 4750 4765 4719 4682 4644 4620 4556 4525 4630 4612 4559 4596 4562 4528 ...
result:
wrong answer 1st numbers differ - expected: '5109', found: '5133'