QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#526247#5669. Traveling in Jade CityMitsukasa_AyaseWA 1384ms43220kbC++232.7kb2024-08-21 12:36:372024-08-21 12:36:39

Judging History

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

  • [2024-08-21 12:36:39]
  • 评测
  • 测评结果:WA
  • 用时:1384ms
  • 内存:43220kb
  • [2024-08-21 12:36:37]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long 
#define N 1000005
using namespace std;
int M,n,k,m,q,a[N*3],vis[N*3];
ll tr[N*3];
void modify(int x,int v){
    for(int i=x;i<=M;i+=i&(-i))
        tr[i]+=v;
}
ll qry(int x){
    ll res=0;
    for(int i=x;i;i-=i&(-i)) res+=tr[i];
    return res;
}
ll qr(int l,int r){
    return qry(r)-qry(l-1);
}
int qx,qy;
ll cirdis(int x,int y){
    if(x>y) swap(x,y);
    if(y>n){
cout<<qx<<" "<<qy<<endl;
        cout<<x<<" "<<y<<endl;
    }
    // assert(min(qr(x,y-1),qr(y,x+n-1))>=0);
    return min(qr(x,y-1),qr(y,x+n-1));
}
int upd(int x){
    if(x==1) x=n*2+1;
    else if(x==k) x=n*2+m+2;
    else x=n+x+1;
}
ll arcdis(int x,int y){
    if(x>y) swap(x,y);
    // assert(x>n*2);
    // assert(qr(x,y-1)>=0);
    return qr(x,y-1);
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k>>m>>q;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        a[i+n]=a[i];
    }
    for(int i=1;i<=m+1;++i)
        cin>>a[n*2+i];
    M=n*2+m+1;
    for(int i=1;i<=M;++i) modify(i,a[i]);
    for(int i=1;i<=q;++i){
        string s;
        int x,y;
        cin>>s;
        if(s[0]=='q'){
            cin>>x>>y;
qx=x,qy=y;
            if(x>y) swap(x,y);
            ll dis=1e18;
            if(y<=n){
if(n>=100)
cout<<x<<" "<<y<<" "<<n<<endl;
                dis=min(dis,cirdis(x,y));
                dis=min(dis,cirdis(x,1)+arcdis(n*2+1,n*2+m+2)+cirdis(k,y));
                dis=min(dis,cirdis(x,k)+arcdis(n*2+m+2,n*2+1)+cirdis(1,y));
            }else if(x>n){
                int xx=upd(x),yy=upd(y);
                if(xx>yy) swap(xx,yy);
                dis=min(dis,arcdis(xx,yy));
                dis=min(dis,arcdis(xx,n*2+1)+cirdis(1,k)+arcdis(yy,n*2+m+2));
            }else{
                int yy=upd(y);
                dis=min(dis,cirdis(x,1)+arcdis(n*2+1,yy));
                dis=min(dis,cirdis(x,k)+arcdis(n*2+m+2,yy));
            }
            if(dis>=1e9) 
                cout<<"impossible\n";
            else 
                cout<<dis<<"\n";
        }else if(s[0]=='c'){
            cin>>x;
            if(vis[x]){
                modify(x,-1e9);
                modify(x+n,-1e9);
            }else{
                modify(x,1e9);
                modify(x+n,1e9);
            }
            vis[x]^=1;
        }else{
            cin>>x;
            x+=2*n+1;
            if(vis[x]){
                modify(x,-1e9);
            }else{
                modify(x,1e9);
            }
            vis[x]^=1;
        }
    }
    return 0;
}
/*
6 4 1 3
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
1400000000 1400000000
q 1 4
x 0
q 1 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5832kb

input:

4 3 1 9
2 3 8 4
1 1
q 3 4
x 0
q 3 4
c 3
q 3 4
c 1
q 3 4
x 0
q 3 4

output:

6
8
9
impossible
6

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5796kb

input:

4 3 1 9
2 3 8 4
1 1
q 3 4
x 0
q 3 4
c 3
q 3 4
c 1
q 3 4
x 0
q 3 4

output:

6
8
9
impossible
6

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 1384ms
memory: 43220kb

input:

1000000 999999 1000000 1000000
200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 2...

output:

315488 428456 1000000
177406400
832172 1556505 1000000
832172 1556505
832172 1556505
832172 1556505
999999 1556505
832172 1556505
1 1556505
-877735200
130047 1778407 1000000
130047 1778407
130047 1778407
130047 1778407
999999 1778407
130047 1778407
1 1778407
-3129672000
681692 1985291 1000000
198529...

result:

wrong answer 1st lines differ - expected: '177406400', found: '315488 428456 1000000'