QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#677986#5669. Traveling in Jade CityForever_Young#WA 329ms52140kbC++142.8kb2024-10-26 13:47:492024-10-26 13:47:52

Judging History

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

  • [2024-10-26 13:47:52]
  • 评测
  • 测评结果:WA
  • 用时:329ms
  • 内存:52140kb
  • [2024-10-26 13:47:49]
  • 提交

answer

#include<bits/stdc++.h>
#define MAXN 1000005
#define ll long long
#define inf 200000000
using namespace std;
int len[3],a[3][MAXN],c[MAXN],x[MAXN],seq[3][MAXN],bel[MAXN];
ll ta[3][MAXN];
int N,M,K,Q;

int bit(int x){return x&-x;}
void add(int k,int x,ll y){
    for (;x<=len[k]+1;x+=bit(x)){
//        printf("%d %d\n",x,bit(x));
        ta[k][x]+=y;
    }
//    printf("ok\n");
}
void modify(int k,int x) {
    if (a[k][x]>=inf){
        add(k,x,-inf);
        a[k][x]-=inf;
    }
    else{
        add(k,x,inf);
        a[k][x]+=inf;
    }
}
ll ask_0(int k,int x){
    if (x<=0) return 0;
    ll res=0;
    for(;x;x-=bit(x)) res+=ta[k][x];
    return res;
}
ll ask(int k,int x,int y) {
    return ask_0(k, y - 1) - ask_0(k, x - 1);
}

void query(int x,int y) {
    ll res = inf;
    int bx=bel[x],by=bel[y];
    int nx=seq[bx][x],ny=seq[by][y];
    if (bx==by) {
        if (nx>ny) swap(nx,ny);
        res=min(res,ask(bx,nx,ny));
        res=min(res,ask(bx,1,nx)+ask(bx,ny,len[bx]+1)+min(ask((bx+1)%3,1,len[(bx+1)%3]+1),ask((bx+2)%3,1,len[(bx+2)%3]+1)));
    } else {
        ll x1x=ask(bx,1,nx);
        ll y1y=ask(by,1,ny);
        ll xxn=ask(bx,nx,len[bx]+1);
        ll yyn=ask(by,ny,len[by]+1);
        res=min(res,x1x+y1y);
        res=min(res,xxn+yyn);
        int bz=3-bx-by;
        res=min(res,min(x1x+yyn,y1y+xxn)+ask(bz,1,len[bz]+1));
    }
    if (res>=inf) printf("impossible\n");
    else printf("%lld\n",res);
}

int main(){
    scanf("%d%d%d%d",&N,&K,&M,&Q);
    for (int i=1;i<=N;i++) scanf("%d",&c[i]);
    for (int i=1;i<=M+1;i++) scanf("%d",&x[i]);

    int now=1;
    len[0]=K-1;
    for (int i=1;i<K;i++){
        bel[now]=0;
        seq[0][now]=i;
        a[0][i]=c[i];
        now++;
    }
    bel[K]=0;
    seq[0][K]=K;

//    printf("1\n");

    now=1;
    len[1]=N-K+1;
    for (int i=1;i<=N-K+1;i++){
        bel[now]=1;
        seq[1][now]=i;
        a[1][i]=c[N-i+1];
        if (now==1) now=N; else now--;
    }
//    printf("2\n");

    now=1;
    len[2]=M+1;
    for (int i=1;i<=M+1;i++){
        bel[now]=2;
        seq[2][now]=i;
        a[2][i]=x[i];
        if (now==1) now=N+1; else now++;
    }
//    printf("3\n");
//    printf("%d %d %d\n",len[0],len[1],len[2]);

    for (int i=0;i<3;i++)
        for (int j=1;j<=len[i];j++) add(i,j,a[i][j]);
//    printf("?\n");

    while(Q--) {
        char s[10];
        int X,Y;
        scanf("%s", s);
        if (s[0] == 'q') {
            scanf("%d%d", &X, &Y);
            query(X, Y);
        } else {
            scanf("%d", &X);
            if (s[0] == 'x') modify(2, X + 1);
            else {
                if (X >= K) modify(1, N - X + 1);
                else modify(0, X);
            }
        }
    }
}

詳細信息

Test #1:

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

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

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: 329ms
memory: 52140kb

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:

0
impossible
impossible
impossible
0
0
0
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
4077112
impossible
0
impossible
impossible
impossible
impossible
0
impossible
impossible
impossible
0
imp...

result:

wrong answer 1st lines differ - expected: '177406400', found: '0'