QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#123487#5441. Quartz Collection___WA 3ms48480kbC++984.6kb2023-07-12 17:35:212023-07-12 17:35:21

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-12 17:35:21]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:48480kb
  • [2023-07-12 17:35:21]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
#define ll long long
#define N 100010
#define int long long 
//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;
    if(x)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("%lld%lld%lld",&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);
}
signed main(){
    scanf("%lld%lld",&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("%lld%lld",&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();
    }
}

详细

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 48480kb

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
15

result:

wrong answer 6th numbers differ - expected: '13', found: '15'