QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#216654#5415. RopewayddCompile Error//C++204.4kb2023-10-15 20:46:532023-10-15 20:46:53

Judging History

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

  • [2023-10-15 20:46:53]
  • 评测
  • [2023-10-15 20:46:53]
  • 提交

answer

//#pragma GCC optimize ("Ofast,unroll-loops")
//#pragma GCC target ("avx2")
#define int ll
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define notall(x) x.begin()+1,x.end()
#define all(x) x.begin(),x.end()
#define mul_t int _t;cin>>_t;while(_t--)
const int int_inf = 1000000100;
const ll ll_inf = 1000000000000000100;
//writers
template<class T>
void writeln(const T &t) {
    cout << t << '\n';
}
template<class T, class...args>
void writeln(const T &t, const args &...rest) {
    cout << t << ' ';
    writeln(rest...);
}
template<class T1>
void writeln(const vector<T1> &v) {
    for (auto c : v)
        cout << c << ' ';
    cout << ' ' << '\n';
}
template<class T1, class T2>
void writeln(const vector<T1> &v, T2 n) {
    for (T2 i = 1; i <= n; i++)
        cout << v[i] << ' ';
    cout << ' ' << '\n';
}
template<class T1, class T2>
void writeln(const pair<T1, T2> p) {
    cout << p.first << ' ' << p.second << ' ' << '\n';
}

struct SegmentTree {
    vector<long long> st, arr;
    int size;

    SegmentTree(int n) {
        size = n;
        st.assign(4 * n, ll_inf);
        arr.assign(n, ll_inf);
    }

    void build(int node, int start, int end) {
        if (start == end) {
            st[node] = arr[start];
        } else {
            int mid = (start + end) / 2;
            build(2 * node, start, mid);
            build(2 * node + 1, mid + 1, end);
            st[node] = min(st[2 * node], st[2 * node + 1]);
        }
    }

    void update(int node, int start, int end, int idx, long long val) {
        if (start == end) {
            arr[idx] = val;
            st[node] = val;
        } else {
            int mid = (start + end) / 2;
            if (start <= idx && idx <= mid) {
                update(2 * node, start, mid, idx, val);
            } else {
                update(2 * node + 1, mid + 1, end, idx, val);
            }
            st[node] = min(st[2 * node], st[2 * node + 1]);
        }
    }

    long long query(int node, int start, int end, int left, int right) {
        if (right < start || end < left) {
            return ll_inf;
        }
        if (left <= start && end <= right) {
            return st[node];
        }
        int mid = (start + end) / 2;
        long long p1 = query(2 * node, start, mid, left, right);
        long long p2 = query(2 * node + 1, mid + 1, end, left, right);
        return min(p1, p2);
    }
};

void solve(){
    ll n,k;
    cin>>n>>k;
    vector<ll>a(n+2);
    for(int i=1;i<=n;i++)cin>>a[i];
    string s;
    cin>>s;
    set<int>must;
    vector<int>num1;
    s="1"+s+"1";
    for(int i=0;i<=n+1;i++)if(s[i]=='1')must.insert(i),num1.push_back(i);
    ll q;
    //两个端点
    auto cacl=[&](ll l,ll r)->ll
    {  
        if(r<=l+1)return 0;
        SegmentTree tr(r-l+1);
        tr.build(1,0,r-l);
        vector<ll>dp(r-l+1,ll_inf),b(r-l+1);
        for(int i=0,j=l;j<=r;i++,j++)b[i]=a[j];
        dp[0]=b[0];
        //writeln("nowis",l,r);
        tr.update(1,0,r-l,0,dp[0]);
        for(int i=1;i<=r-l;i++)
        {
            ll nowl=max(0ll,i-k);
            dp[i]=b[i]+tr.query(1,0,r-l,nowl,i-1);
            tr.update(1,0,r-l,i,dp[i]);
        }
        // cout<<"b ";
        // writeln(b);
        // cout<<"dp ";
        // writeln(dp);
        return dp[r-l];
    };
    ll ans=0;
    for(auto c:num1)ans+=a[c];
    ll sz=num1.size();
    for(int i=0;i<sz-1;i++)
    {
        ll l=num1[i],r=num1[i+1];
        ll nowadd=cacl(l,r);
        ans+=nowadd;
        ans-=(a[l]+a[r]);
    }
    // writeln(ans);
    cin>>q;
    for(int i=1;i<=q;i++)
    {
        ll tmp=ans;
        ll pos,xx;
        cin>>pos>>xx;
      //  writeln("ssssssbbbb",pos,xx);
        if(must.count(pos))
        {
            tmp+=(xx-a[pos]);
        }
        else 
        {
            auto nowpos=prev(must.upper_bound(pos));
            ll x=*nowpos,y=*next(nowpos);
            ll sb=cacl(x,y);
            tmp-=sb;
         //   writeln("sb1",x,sb);
            ll lst=a[pos];
            a[pos]=xx;
          //  writeln("apos",a[pos]);
            sb=cacl(x,y);
            tmp+=sb;
          //  writeln("sb2",sb);
            a[pos]=lst;
        }
        writeln(tmp);
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(15);
    mul_t
    solve();
}

Details

In file included from /usr/include/c++/11/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:33,
                 from answer.code:4:
/usr/include/x86_64-linux-gnu/c++/11/bits/c++config.h:280:33: error: expected initializer before ‘size_t’
  280 |   typedef __SIZE_TYPE__         size_t;
      |                                 ^~~~~~
/usr/include/x86_64-linux-gnu/c++/11/bits/c++config.h:281:33: error: expected initializer before ‘ptrdiff_t’
  281 |   typedef __PTRDIFF_TYPE__      ptrdiff_t;
      |                                 ^~~~~~~~~
In file included from /usr/include/c++/11/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:33,
                 from answer.code:4:
/usr/include/assert.h:70:41: error: expected ‘,’ or ‘...’ before ‘__line’
   70 |                            unsigned int __line, const char *__function)
      |                                         ^~~~~~
/usr/include/assert.h:74:13: error: variable or field ‘__assert_perror_fail’ declared void
   74 | extern void __assert_perror_fail (int __errnum, const char *__file,
      |             ^~~~~~~~~~~~~~~~~~~~
answer.code:3:13: error: ‘ll’ was not declared in this scope; did you mean ‘all’?
    3 | #define int ll
      |             ^~
In file included from /usr/include/c++/11/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:33,
                 from answer.code:4:
/usr/include/assert.h:74:49: error: expected primary-expression before ‘const’
   74 | extern void __assert_perror_fail (int __errnum, const char *__file,
      |                                                 ^~~~~
/usr/include/assert.h:75:35: error: expected primary-expression before ‘unsigned’
   75 |                                   unsigned int __line, const char *__function)
      |                                   ^~~~~~~~
/usr/include/assert.h:75:56: error: expected primary-expression before ‘const’
   75 |                                   unsigned int __line, const char *__function)
      |                                                        ^~~~~
answer.code:3:13: error: ‘ll’ has not been declared
    3 | #define int ll
      |             ^~
In file included from /usr/include/ctype.h:26,
                 from /usr/include/c++/11/cctype:42,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:35,
                 from answer.code:4:
/usr/include/x86_64-linux-gnu/bits/types.h:32:28: error: expected initializer before ‘__u_short’
   32 | typedef unsigned short int __u_short;
      |                            ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:33:22: error: expected initializer before ‘__u_int’
   33 | typedef unsigned int __u_int;
      |                      ^~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:34:27: error: expected initializer before ‘__u_long’
   34 | typedef unsigned long int __u_long;
      |                           ^~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:39:26: error: expected initializer before ‘__int16_t’
   39 | typedef signed short int __int16_t;
      |                          ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:40:28: error: expected initializer before ‘__uint16_t’
   40 | typedef unsigned short int __uint16_t;
      |                            ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:41:20: error: expected initializer before ‘__int32_t’
   41 | typedef signed int __int32_t;
      |                    ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:42:22: error: expected initializer before ‘__uint32_t’
   42 | typedef unsigned int __uint32_t;
      |                      ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:44:25: error: expected initializer before ‘__int64_t’
   44 | typedef signed long int __int64_t;
      |                         ^~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:45:27: error: expected initializer before ‘__uint64_t’
   45 | typedef unsigned long int __uint64_t;
      |                           ^~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/types.h:54:9: error: ‘__int16_t’ does not name a type; did you mean ‘__int8_t’?
   54 | typedef __int16_t __int_least16_t;
      |         ^~~~~~~~~
      |         __int8_t
/usr/include/x86_64-linux-gnu/bits/types.h:55:9: error: ‘__uint16_t’ does not name a type; did you mean ‘__uint8_t’?
   55 | typedef __uint16_t __uint_least16_t;
      |         ^~~~~~~~~~
      |         __uint8_t
/usr/include/x86_64-linux-gnu/bits/types.h:56:9: error: ‘__int32_t’ does not name a type; did you mean ‘__int8_t’?
   56 | typedef __int32_t __int_least32_t;
      |         ^~~~~~~~~
      |         __int8_t
/usr/include/x86_64-linux-gnu/bits/types.h:57:9: error: ‘__uint32_t’ does not name a type; did you mean ‘__uint8_t’?
   57 | typedef __uint32_t __uint_least32_t;
      |         ^~~~~~~~~~
      |         __uint8_t
/usr/include/x86_64-linux-gnu/bits/types.h:58:9: error: ‘__int64_t’ do...