QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#123485 | #5441. Quartz Collection | ___ | Compile Error | / | / | C++98 | 4.6kb | 2023-07-12 17:34:07 | 2023-07-12 17:34:10 |
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:34:10]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-07-12 17:34:07]
- 提交
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("%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
answer.code: In function ‘void work()’: answer.code:94:13: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 94 | scanf("%d%d%d",&t,&x,&y); | ~^ ~~ | | | | int* long long int* | %lld answer.code:94:15: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘long long int*’ [-Wformat=] 94 | scanf("%d%d%d",&t,&x,&y); | ~^ ~~ | | | | int* long long int* | %lld answer.code:94:17: warning: format ‘%d’ expects argument of type ‘int*’, but argument 4 has type ‘long long int*’ [-Wformat=] 94 | scanf("%d%d%d",&t,&x,&y); | ~^ ~~ | | | | int* long long int* | %lld At global scope: cc1plus: error: ‘::main’ must return ‘int’ answer.code: In function ‘int main()’: answer.code:141:13: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 141 | scanf("%d%d",&n,&m); | ~^ ~~ | | | | int* long long int* | %lld answer.code:141:15: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘long long int*’ [-Wformat=] 141 | scanf("%d%d",&n,&m); | ~^ ~~ | | | | int* long long int* | %lld answer.code:144:34: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 144 | for(int i=1;i<=n;i++)scanf("%d%d",&sa[i],&sb[i]); | ~^ ~~~~~~ | | | | int* long long int* | %lld answer.code:144:36: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘long long int*’ [-Wformat=] 144 | for(int i=1;i<=n;i++)scanf("%d%d",&sa[i],&sb[i]); | ~^ ~~~~~~ | | | | int* long long int* | %lld answer.code: In function ‘void work()’: answer.code:94:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 94 | scanf("%d%d%d",&t,&x,&y); | ~~~~~^~~~~~~~~~~~~~~~~~~ answer.code: In function ‘int main()’: answer.code:141:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 141 | scanf("%d%d",&n,&m); | ~~~~~^~~~~~~~~~~~~~ answer.code:144:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 144 | for(int i=1;i<=n;i++)scanf("%d%d",&sa[i],&sb[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~