QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#123482 | #5441. Quartz Collection | ___ | WA | 11ms | 37132kb | C++98 | 4.6kb | 2023-07-12 17:31:26 | 2023-07-12 17:31:29 |
Judging History
answer
#include<stdio.h>
#include<algorithm>
#define ll long long
#define N 100010
//using namespace std;
const int maxn=100000;
struct node{
ll add;int ls,rs;
}a[N<<5];int lena;
int rt[4],aux[4],rx;
int stac[N<<4];int lens;
void del(int x){
a[x].ls=a[x].rs=0;
a[x].add=0;
stac[++lens]=x;
return ;
}
int newnode(){
return ++lena;
if(lens){
return stac[lens--];
}else return ++lena;
}
void pushup(int x){
a[x].add=a[a[x].ls].add+a[a[x].rs].add;
}
int split(int&x,int&y,int nowl,int nowr,int l,int r){
if(r<nowl||l>nowr)return 0;
if(l<=nowl&&r>=nowr){
y=x;x=0;
return 0;
}
if(!y)y=newnode();
int mid=((maxn+maxn+nowl+nowr)>>1)-maxn;
split(a[x].ls,a[y].ls,nowl,mid,l,r);
split(a[x].rs,a[y].rs,mid+1,nowr,l,r);
pushup(x);pushup(y);
return 0;
}
int merge(int&x,int&y,int l,int r){
if(x==0||y==0){
x=x+y;y=0;
return 0;
}
if(l==r){
a[x].add+=a[y].add;
del(y);
return 0;
}
int mid=((maxn+maxn+l+r)>>1)-maxn;
merge(a[x].ls,a[y].ls,l,mid);
merge(a[x].rs,a[y].rs,mid+1,r);
del(y);
pushup(x);
return 0;
}
int build(int&x,int l,int r){
if(!x)x=newnode();
if(l==r){
a[x].ls=a[x].rs=a[x].add=0;
return 0;
}
int mid=((maxn+maxn+l+r)>>1)-maxn;
build(a[x].ls,l,mid);
build(a[x].rs,mid+1,r);
a[x].add=0;
return 0;
}
int change(int&x,int l,int r,int id,int s){
// printf("%d %d %d %d %d\n",x,l,r,id,s);
if(id<l||id>r)return 0;
if(l==r){
a[x].add+=s;
return 0;
}
int mid=((maxn+maxn+l+r)>>1)-maxn;
change(a[x].ls,l,mid,id,s);
change(a[x].rs,mid+1,r,id,s);
pushup(x);
return 0;
}
ll find(int&x,int nowl,int nowr,int l,int r){
if(l>nowr||r<nowl)return 0;
if(l<=nowl&&r>=nowr)return a[x].add;
int mid=((maxn+maxn+nowl+nowr)>>1)-maxn;
return find(a[x].ls,nowl,mid,l,r)+find(a[x].rs,mid+1,nowr,l,r);
}
ll addb,addx;
int sa[N],sb[N],sx[N];
int n,m;
void work(){
int t,x,y;
scanf("%d%d%d",&t,&x,&y);
int l=sx[t],r=x-y;
addb-=sb[t];addx-=sx[t];
sa[t]=x;sb[t]=y;
sx[t]=r;
addb+=sb[t];addx+=sx[t];
x=l;y=r;
if(x==y)return ;
//printf("chn %d %d\n",x,y);
if(x<y){
for(int i=0;i<4;i++)split(rt[i],aux[i],-maxn,maxn,x+1,y-1);
// printf("PWPx");for(int i=1;i<=n;i++)printf("%d %d ",a[rt[i%4]].add,a[aux[i%4]].add);puts("");
for(int i=0;i<4;i++)merge(rt[(i-1+n)%4],aux[i],-maxn,maxn);
// printf("PWP");for(int i=1;i<=n;i++)printf("%d ",a[rt[i%4]].add);puts("");
int p=find(rx,-maxn,maxn,-maxn,x);
// printf("T! %d\n",p);
change(rt[(p)%4],-maxn,maxn,x,-x);
change(rx,-maxn,maxn,x,-1);
p=find(rx,-maxn,maxn,-maxn,y-1)+1;
// printf("T! %d\n",p);
change(rt[(p)%4],-maxn,maxn,y,y);
change(rx,-maxn,maxn,y,1);
// printf("PWPp");for(int i=1;i<=n;i++)printf("%d ",a[rt[i%4]].add);puts("");
}else{
for(int i=0;i<4;i++)split(rt[i],aux[i],-maxn,maxn,y+1,x-1);
for(int i=0;i<4;i++)merge(rt[(i+1)%4],aux[i],-maxn,maxn);
// printf("QWQ");for(int i=1;i<=n;i++)printf("%d ",a[rt[i%4]].add);puts("");
int p=find(rx,-maxn,maxn,-maxn,x-1)+1;
// printf("S! %d\n",p);
change(rt[(p)%4],-maxn,maxn,x,-x);
change(rx,-maxn,maxn,x,-1);
p=find(rx,-maxn,maxn,-maxn,y)+1;
// printf("S! %d\n",p);
change(rt[(p)%4],-maxn,maxn,y,y);
change(rx,-maxn,maxn,y,1);
// printf("PWPp");for(int i=1;i<=n;i++)printf("%d ",a[rt[i%4]].add);puts("");
}
}
void ask(){
ll p=find(rt[0],-maxn,maxn,-maxn,0)+find(rt[1],-maxn,maxn,-maxn,0);
ll q=find(rt[1],-maxn,maxn,1,maxn)+find(rt[3],-maxn,maxn,1,maxn);
// printf("T%lld %lld %lld\n",p,q,addb);
// printf("ANS%lld\n",p+q+addb);
printf("%lld\n",p+q+addb);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<=3;i++)build(rt[i],-maxn,maxn);
build(rx,-maxn,maxn);
for(int i=1;i<=n;i++)scanf("%d%d",&sa[i],&sb[i]);
for(int i=1;i<=n;i++)addb+=sb[i];
for(int i=1;i<=n;i++)sx[i]=sa[i]-sb[i];
for(int i=1;i<=n;i++)addx+=sx[i];
std:: sort(sx+1,sx+n+1);
// for(int i=1;i<=n;i++)printf("a%da",sx[i]);
// puts("QWQ");
for(int i=1;i<=n;i++){
// printf("p%d\n",i);
change(rt[i%4],-maxn,maxn,sx[i],sx[i]);
change(rx,-maxn,maxn,sx[i],1);
}
for(int i=1;i<=n;i++)sx[i]=sa[i]-sb[i];
ask();
for(int i=1;i<=m;i++){
work();ask();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 35336kb
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: 35748kb
input:
1 1 1 1 1 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: 0
Accepted
time: 4ms
memory: 33016kb
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: 10ms
memory: 36772kb
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: 11ms
memory: 35316kb
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: -100
Wrong Answer
time: 11ms
memory: 37132kb
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 250118900 250132192 250072951 250112037 250090365 250025935 250056382 250064698 250138416 250143782 250118937 250068100 250129226 250297030 250230843 250252868 250183962 250229191 250447374 250494751 250593624 250594283 250504444 250532202 250430580 250500616 250621711 250743521 250640564 ...
result:
wrong answer 2nd numbers differ - expected: '250118970', found: '250118900'