QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#770525#5669. Traveling in Jade CityvwxyzWA 0ms3780kbC++236.3kb2024-11-21 22:12:402024-11-21 22:12:41

Judging History

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

  • [2024-11-21 22:12:41]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3780kb
  • [2024-11-21 22:12:40]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll=long long;

template <class S, S (*op)(S, S), S (*e)()>
struct Segtree {
  int _n, size, log;
  vector<S> d;
  void update(int k) {
    d[k] = op(d[2 * k], d[2 * k + 1]);
  }

  Segtree() : Segtree(0) {
  }
  Segtree(int n) : Segtree(vector<S>(n, e())) {
  }
  Segtree(const vector<S>& v) : _n(int(v.size())) {
    size = bit_ceil((unsigned)_n);
    log = countr_zero((unsigned)size);
    d = vector<S>(2 * size, e());
    for (int i = 0; i < _n; i++) d[size + i] = v[i];
    for (int i = size - 1; i >= 1; i--) {
      update(i);
    }
  }
  void set(int p, S x) {
    p += size;
    d[p] = x;
    for (int i = 1; i <= log; i++) update(p >> i);
  }
  S get(int p) {
    return d[p + size];
  }
  S prod(int l, int r) {
    S sml = e(), smr = e();
    l += size;
    r += size;
    while (l < r) {
      if (l & 1) sml = op(sml, d[l++]);
      if (r & 1) smr = op(d[--r], smr);
      l >>= 1;
      r >>= 1;
    }
    return op(sml, smr);
  }
  S all_prod() {
    return d[1];
  }
  template <bool (*f)(S)>
  int max_right(int l) {
    return max_right(l, [](S x) { return f(x); });
  }
  template <class F>
  int max_right(int l, F f) {
    if (l == _n) return _n;
    l += size;
    S sm = e();
    do {
      while (l % 2 == 0) l >>= 1;
      if (!f(op(sm, d[l]))) {
        while (l < size) {
          l = (2 * l);
          if (f(op(sm, d[l]))) {
            sm = op(sm, d[l]);
            l++;
          }
        }
        return l - size;
      }
      sm = op(sm, d[l]);
      l++;
    } while ((l & -l) != l);
    return _n;
  }
  template <bool (*f)(S)>
  int min_left(int r) {
    return min_left(r, [](S x) { return f(x); });
  }
  template <class F>
  int min_left(int r, F f) {
    if (r == 0) return 0;
    r += size;
    S sm = e();
    do {
      r--;
      while (r > 1 && (r % 2)) r >>= 1;
      if (!f(op(d[r], sm))) {
        while (r < size) {
          r = (2 * r + 1);
          if (f(op(d[r], sm))) {
            sm = op(d[r], sm);
            r--;
          }
        }
        return r + 1 - size;
      }
      sm = op(d[r], sm);
    } while ((r & -r) != r);
    return 0;
  }
};

ll op(ll a,ll b){
    assert(a>=0&&b>=0);
    return a+b;
}

ll e(){
    return 0ll;
}

int main() {
    int N,K,M,Q;
    cin>>N>>K>>M>>Q;
    int M0,M1,M2;
    M0=K-1;
    M1=M+1;
    M2=N-K+1;
    vector<ll> X0(M0);
    vector<ll> X2(M2);
    for(int i=0;i<N;i++){
        if (i<M0){
            cin>>X0[i];
        }
        else{
            cin>>X2[M2-1-(i-M0)];
        }
    }
    vector<ll> X1(M1);
    for(int m=0;m<M1;m++){
        cin>>X1[m];
    }
    const ll inf=1ll<<35;
    Segtree<ll,op,e> ST0(X0);
    Segtree<ll,op,e> ST1(X1);
    Segtree<ll,op,e> ST2(X2);
    int cnt=103720;
    for(int q=0;q<Q;q++){
        char s;
        cin>>s;
        if(s=='q'){
            int x,y;cin>>x>>y;
            x-=1;y-=1;
            ll ans=inf;
            function<ll(ll,ll)> dist=[&](ll x,ll y){
                ll ans=inf;
                if(0<=x&&x<=K-1&&0<=y&&y<=K-1){
                    int l=x;
                    int r=y;
                    if(l>r){
                        swap(l,r);
                    }
                    ans=min(ans,ST0.prod(l,r));
                }
                if((K-1<=x&&x<=N-1||x==0)&&(K-1<=y&&y<=N-1||y==0)){
                    int l=(x==0?0:N-x),r=(y==0?0:N-y);
                    if(l>r){
                        swap(l,r);
                    }
                    if(x==30596&&y==30594){
                        cout<<l<<" "<<r<<"\n";
                        cout<<ST2.get(l)<<" "<<ST2.get(l+1)<<"\n";
                    }
                    cout<<"C\n";
                    ans=min(ans,ST2.prod(l,r));
                }
                if((N<=x&&x<=N+M-1||x==0||x==K-1)&&(N<=y&&y<=N+M-1||y==0||y==K-1)){
                    int l;
                    if(x==0){
                        l=0;
                    }
                    else if(x==K-1){
                        l=M1;
                    }
                    else{
                        l=x-(N-1);
                    }
                    int r;
                    if(y==0){
                        r=0;
                    }
                    else if(y==K-1){
                        r=M1;
                    }
                    else{
                        r=y-(N-1);
                    }
                    if(l>r){
                        swap(l,r);
                    }
                    ans=min(ans,ST1.prod(l,r));
                }
                return ans;
            };
            ans=min(ans,dist(x,y));
            ans=min(ans,dist(x,0)+dist(0,y));
            ans=min(ans,dist(x,K-1)+dist(K-1,y));
            ans=min(ans,dist(x,0)+dist(0,K-1)+dist(K-1,y));
            ans=min(ans,dist(x,K-1)+dist(K-1,0)+dist(0,y));
            if(K==25123){
                cnt-=1;
                if(cnt==0){
                    cout<<x<<" "<<y<<" "<<ans<<"\n";
                    cout<<dist(x,y)<<"\n";
                    cout<<dist(x,0)<<" "<<dist(0,y)<<" "<<dist(x,0)+dist(0,y)<<"\n";
                    cout<<dist(x,K-1)<<" "<<dist(K-1,y)<<" "<<dist(x,K-1)+dist(K-1,y)<<"\n";
                    cout<<dist(x,0)<<" "<<dist(0,K-1)<<" "<<dist(K-1,y)<<" "<<dist(x,0)+dist(0,K-1)+dist(K-1,y)<<"\n";;
                    cout<<dist(x,K-1)<<" "<<dist(K-1,0)<<" "<<dist(0,y)<<" "<<dist(x,K-1)+dist(K-1,0)+dist(0,y)<<"\n";;
                }
                continue;
            }
            if(ans>=inf){
                cout<<"impossible"<<"\n";
            }
            else{
                cout<<ans<<"\n";
            }
        }
        else if(s=='c'){
            int i;cin>>i;
            i-=1;
            if(K==25123&&(i==30594||i==30595)){
                cout<<i<<" A\n";
            }
            if(i<K-1){
                ST0.set(i,inf+X0[i]-ST0.get(i));
            }
            else{
                ST2.set(N-1-i,inf+X2[i]-ST2.get(i));
                if(K==25123&&(i==30594||i==30595)){
                    cout<<N-1-i<<" "<<inf+X2[i]-ST2.get(i)<<" B\n";
                }
            }
        }
        else{
            int i;cin>>i;
            ST1.set(i,inf+X1[i]-ST1.get(i));
        }
    }
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3780kb

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:

C
C
C
C
C
C
C
C
C
C
C
6
C
C
C
C
C
C
C
C
C
C
C
8
C
C
C
C
C
C
C
C
C
C
C
9
C
C
C
C
C
C
C
C
C
C
C
impossible
C
C
C
C
C
C
C
C
C
C
C
6

result:

wrong answer 1st lines differ - expected: '6', found: 'C'