QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768276#5669. Traveling in Jade CityvwxyzCompile Error//C++235.2kb2024-11-21 08:12:172024-11-21 08:12:18

Judging History

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

  • [2024-11-21 08:12:18]
  • 评测
  • [2024-11-21 08:12:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll=long long;
#define int 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){
    return a+b;
}

ll e(){
    return 0ll;
}

signed 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<<60;
    Segtree<ll,op,e> ST0(X0);
    Segtree<ll,op,e> ST1(X1);
    Segtree<ll,op,e> ST2(X2);
    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);
                    }
                    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(ans>=inf){
                cout<<"impossible"<<"\n";
            }
            else{
                cout<<ans<<"\n";
            }
        }
        else if(s=='c'){
            int i;cin>>i;
            i-=1;
            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));
            }
        }
        else{
            int i;cin>>i;
            ST1.set(i,inf+X1[i]-ST1.get(i));
        }
    }
}

Details

answer.code: In constructor ‘Segtree<S, op, e>::Segtree(const std::vector<_Tp>&)’:
answer.code:5:13: error: expected primary-expression before ‘long’
    5 | #define int long long
      |             ^~~~
answer.code:19:36: note: in expansion of macro ‘int’
   19 |   Segtree(const vector<S>& v) : _n(int(v.size())) {
      |                                    ^~~