QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#735373#5441. Quartz CollectionyanshanjiahongWA 3ms22492kbC++143.1kb2024-11-11 19:32:182024-11-11 19:32:18

Judging History

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

  • [2024-11-11 19:32:18]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:22492kb
  • [2024-11-11 19:32:18]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define repp(i,j,k) for(int i=j;i>=k;i--)
#define ls(x) (x<<1)
#define rs(x) ((x<<1)|1)
#define mp make_pair
#define sec second
#define fir first
#define pii pair<int,int>
#define lowbit(i) i&-i
#define double long double
#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=4e5+5,M=30,S=(1<<8)+5,inf=(ll)1e18+7;
const double eps=1e-8;
void read(int &p){
	int x=0,w=1;
	char ch=0;
	while(!isdigit(ch)){
		if(ch=='-')w=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	p=x*w;
}
int n,m,ans,vala[N],valq[N],qpos[N];
pii a[N],q[N];
int lsh[2][N],cntl[2],numn=0;
struct seg{
    int t[4][4*N],pren[4*N],tag[4*N];
    void pushup(int x){
        rep(i,0,3)
            t[i][x]=t[i][ls(x)]+t[i][rs(x)];
        pren[x]=pren[ls(x)];
    }
    int nwv[4];
    void addtag(int x,int v){
        if(!v)return;
        tag[x]+=v,pren[x]+=v;
        rep(i,0,3)
            nwv[i]=t[i][x];
        rep(i,0,3)
            t[((i+v)%4+4)%4][x]=nwv[i];
    }
    void pushdown(int x){
        addtag(ls(x),tag[x]),addtag(rs(x),tag[x]);
        tag[x]=0;
    }
    void modify(int x,int le,int ri,int p,int v,int op){
        if(le==ri){
            if(!op)numn+=v;
            t[(pren[x]+1)%4][x]+=v*lsh[op][le];
            return;
        }
        pushdown(x);
        int mid=(le+ri)>>1;
        if(p<=mid)addtag(rs(x),v),modify(ls(x),le,mid,p,v,op);
        else modify(rs(x),mid+1,ri,p,v,op);
        pushup(x);
    }
}T[2];
unordered_map<int,int>stp;
int calc(){
    int res=T[0].t[0][1]+T[0].t[1][1];
    if(numn&1)res+=T[1].t[0][1]+T[1].t[2][1];
    else res+=T[1].t[1][1]+T[1].t[3][1];
    return ans+res;
}
signed main(){
    read(n),read(m);
    rep(i,1,n){
        read(a[i].fir),read(a[i].sec),ans+=a[i].sec;
        int del=a[i].fir-a[i].sec;
        if(del<0)lsh[0][++cntl[0]]=del;
        else lsh[1][++cntl[1]]=del;
    }
    rep(i,1,m){
        read(qpos[i]),read(q[i].fir),read(q[i].sec);
        int del=q[i].fir-q[i].sec;
        if(del<0)lsh[0][++cntl[0]]=del;
        else lsh[1][++cntl[1]]=del;
    }
    rep(i,0,1){
        sort(lsh[i]+1,lsh[i]+cntl[i]+1);
        stp.clear();
        rep(j,1,cntl[i])
            if(!stp[lsh[i][j]])stp[lsh[i][j]]=j;
        rep(j,1,n)
            if(stp[a[j].fir-a[j].sec])vala[j]=stp[a[j].fir-a[j].sec]++;
        rep(j,1,m)
            if(stp[a[j].fir-a[j].sec])valq[j]=stp[a[j].fir-a[j].sec]++;
    }
    rep(i,1,n){
        if(a[i].fir-a[i].sec<0)T[0].modify(1,1,cntl[0],vala[i],1,0);
        else T[1].modify(1,1,cntl[1],vala[i],1,1);
    }
    printf("%lld\n",calc());
    rep(j,1,m){
        int i=qpos[j];
        if(a[i].fir-a[i].sec<0)T[0].modify(1,1,cntl[0],vala[i],-1,0);
        else T[1].modify(1,1,cntl[1],vala[i],-1,1);
        ans-=a[i].sec;
        vala[i]=valq[j],a[i]=q[j];
        ans+=a[i].sec;
        if(a[i].fir-a[i].sec<0)T[0].modify(1,1,cntl[0],vala[i],1,0);
        else T[1].modify(1,1,cntl[1],vala[i],1,1);
        printf("%lld\n",calc());
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 22116kb

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: 3ms
memory: 18328kb

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: 0ms
memory: 22492kb

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
5183
5123
5063
4923
4807
4806
4817
4823
4829
4974
4791
4768
4796
4772
4806
4797
4800
4810
4767
4742
4750
4601
4557
4644
4851
4793
4773
4788
4802
4767
4490
4495
4452
4374
4973
5021
5092
4977
4898
4817
4863
4695
4914
5116
5062
5047
5054
5021
4983
4923
5026
4736
4862
4890
4777
4757
4852
4725
...

result:

wrong answer 3rd numbers differ - expected: '5060', found: '5183'