criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <iostream>
#include <vector>
#include <cmath>
#include <limits.h>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;
using P = pair<int,int>;
using ll = long long;
#define int long long
signed main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<k;i++){
        vector<int> b(n);
        for(int j=0;j<n;j++){
            b[max(0,j-a[j])]++;
            if(j+a[j]+1<n)b[j+a[j]+1]--;
        }
        for(int i=1;i<n;i++)b[i]=b[i-1]+b[i];
        bool c=true;
        for(int i=0;i<n;i++){
            a[i]=b[i];
            if(a[i]<n)c=false;
        }
        if(c){
            for(int i=0;i<n;i++){
                cout<<a[i]+(k-i-1)*n<<" ";
            }
            cout<<endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:18: error: no matching function for call to 'max(int, long long int)'
   22 |             b[max(0,j-a[j])]++;
      |               ~~~^~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:22:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   22 |             b[max(0,j-a[j])]++;
      |               ~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:22:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   22 |             b[max(0,j-a[j])]++;
      |               ~~~^~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
#include "../lib/lazysegmenttree/lazy_segtree_add_sum.hpp"

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n, k; cin >> n >> k;
  vll a(n);
  REP(i, n) cin >> a[i];

  LazySegTreeAddSum<ll> st1(a);
  REP(_, k) {
    if(st1.query(0, n) == n * n) {
      break;
    }
    LazySegTreeAddSum<ll> st2(n);
    REP(i, n) {
      ll val = st1.query(i, i+1);
      st2.update(max(0ll, i-val), min(n, i+val+1), 1);
    }
    st1 = st2;
  }

  REP(i, n) {
    cout << st1.query(i, i+1);
    if(i == n-1) cout << endl;
    else cout << " ";
  }


}
























Compiler output:
a.cc:2:10: fatal error: ../lib/lazysegmenttree/lazy_segtree_add_sum.hpp: No such file or directory
    2 | #include "../lib/lazysegmenttree/lazy_segtree_add_sum.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
//#define i_7 (long long)(1e9+7)
#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

vector<vector<long long>> dp(m, vector<long long>(100'010, 0));

int main(){
  //using namespace std;
  int n;
  cin>>n;
  long long V[n], W[n];
  REP(i, n) cin>>V[i]>>W[i];
  int q;
  cin>>q;
  int v[q];
  long long l[q];
  REP(i, q) cin>>v[i]>>l[q];
  
  int m = min(1<<9, n);
  //vector<vector<long long>> dp(m, vector<long long>(100'010, 0));
  REP(i, m){
    REP(j, 100'010){
      if(i == 0){
        if(W[i] <= j) dp[i][j] = V[i];
        continue;
      }
      dp[i][j] = dp[i/2][j];
      if(j < W[i]) continue;
      dp[i][j] = max(dp[i][j], dp[i/2][j - W[i]] + V[i]);
    }
  }
  
  auto query = [&](int qv, long long ql) -> long long {
    long long res = -1;
    if(qv < m) return dp[qv][ql];
    int tv = qv;
    typedef pair<long long, long long> P;
    vector<P> temp;
    while(tv >= m){
      temp.emplace_back(V[tv], W[tv]);
      tv /= 2;
    }
    int k = temp.size();
    REP(s, 1<<k){
      long long totv = 0, totw = 0;
      REP(i, k){
        if(s>>i&1){
          totv += temp[i].first;
          totw += temp[i].second;
        }
      }
      if(totw > ql) continue;
      res = max(res, totv + dp[tv][ql - totw]);
    }
    return res;
  };
  
  REP(i, q){
    long long ans = query(v[i], l[i]);
    cout << ans << endl;
  }
  
  return 0;
}


Compiler output:
a.cc:69:30: error: 'm' was not declared in this scope; did you mean 'tm'?
   69 | vector<vector<long long>> dp(m, vector<long long>(100'010, 0));
      |                              ^
      |                              tm
Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
//#define i_7 (long long)(1e9+7)
#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  //using namespace std;
  int n;
  cin>>n;
  long long V[n], W[n];
  REP(i, n) cin>>V[i]>>W[i];
  int q;
  cin>>q;
  int v[q];
  long long l[q];
  REP(i, q) cin>>v[i]>>l[q];
  
  int m = min(1<<9, n);
  vector<vector<long long>> dp(m, vector<long long>(100'010, 0));
  REP(i, m){
    REP(j, 100'010){
      if(i == 0){
        if(W[i] <= j) dp[i][j] = V[i];
        continue;
      }
      dp[i][j] = dp[i/2][j];
      if(j < W[i]) continue;
      dp[i][j] = max(dp[i][j], dp[i/2][j - W[i]] + V[i]);
    }
  }
  
  auto query = [&](int qv, long long ql) -> long long {
    long long res = -1;
    if(qv < m) return dp[qv][ql];
    int tv = qv;
    typedef pair<long long, long long> P;
    vector<P> temp;
    while(tv >= m){
      temp.emplace_back(V[tv], W[tv]);
      tv /= 2;
    }
    int k = temp.size();
    REP(s, 1<<k){
      long long totv = 0, totw = 0;
      REP(i, k){
        if(s>>i&1){
          totv += temp[i].first;
          totw += temp[i].second;
        }
      }
      if(totw > ql) continue;
      res = max(res, totv + dp[tv][ql - totw]);
    }
    return res;
  }
  
  REP(i, q){
    long long ans = query(v[i], l[i]);
    cout << ans << endl;
  }
  
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:6:18: error: expected ',' or ';' before 'for'
    6 | #define REP(i,n) for(int i=0;i<n;i++)
      |                  ^~~
a.cc:120:3: note: in expansion of macro 'REP'
  120 |   REP(i, q){
      |   ^~~
a.cc:120:7: error: 'i' was not declared in this scope
  120 |   REP(i, q){
      |       ^
a.cc:6:30: note: in definition of macro 'REP'
    6 | #define REP(i,n) for(int i=0;i<n;i++)
      |                              ^
Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
//#define i_7 (long long)(1e9+7)
#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  //using namespace std;
  int n;
  cin>>n;
  long long V[n], W[n];
  REP(i, n) cin>>V[i]>>W[i];
  int q;
  cin>>q;
  int v[q];
  long long l[q];
  REP(i, q) cin>>v[i]>>l[q];
  
  int m = min(1<<9, n);
  vector<vector<long long>> dp(m, vector<long long>(100'010, 0));
  REP(i, m){
    REP(j, 100'010){
      if(i == 0){
        if(W[i] <= j) dp[i][j] = V[i];
        continue;
      }
      dp[i][j] = dp[i/2][j];
      if(j < W[i]) continue;
      dp[i][j] = max(dp[i][j], dp[i/2][j - W[i]] + V[i]);
    }
  }
  
  auto query = [&](int qv, long long ql) -> long long {
    long long res = -1;
    if(qv < m) return dp[qv][ql];
    int tv = qv;
    typedef pair<long long, long long> P;
    vector<P> temp;
    while(tv >= m){
      temp.emplace_back(V[i], W[i]);
      tv /= 2;
    }
    int k = temp.size();
    REP(s, 1<<k){
      long long totv = 0, totw = 0;
      REP(i, k){
        if(s>>i&1){
          totv += temp[i].first;
          totw += temp[i].second;
        }
      }
      if(totw > ql) continue;
      res = max(res, totv + dp[tv][ql - totw]);
    }
    return res;
  }
  
  REP(i, q){
    long long ans = query(v[i], l[i]);
    cout << ans << endl;
  }
  
  return 0;
}


Compiler output:
a.cc: In lambda function:
a.cc:102:27: error: 'i' was not declared in this scope
  102 |       temp.emplace_back(V[i], W[i]);
      |                           ^
a.cc: In function 'int main()':
a.cc:6:18: error: expected ',' or ';' before 'for'
    6 | #define REP(i,n) for(int i=0;i<n;i++)
      |                  ^~~
a.cc:120:3: note: in expansion of macro 'REP'
  120 |   REP(i, q){
      |   ^~~
a.cc:120:7: error: 'i' was not declared in this scope
  120 |   REP(i, q){
      |       ^
a.cc:6:30: note: in definition of macro 'REP'
    6 | #define REP(i,n) for(int i=0;i<n;i++)
      |                              ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

const int mxn = 2e5 + 5;
const int mxl = 1e5 + 1;
int n, q, v[mxn], w[mxn], par[mxn], dp[513][mxl];

int solve(int u, int l) {
	// cout << u << '\n';
	if (u <= 511)
		return dp[u][l];
	else {
		vector<int> path;
		while (u >= 512) {
			path.push_back(u);
			u /= 2;
		}
		int t = path.size();
		int ret = 0;
		for (int i=0; i<(1 << t); i++) {
			int tw = 0, tv = 0;
			for (int j=0; j<t; j++) {
				if (i & (1 << j)) {
					tw += w[path[j]];
					tv += v[path[j]];
				}
			}
			if (l - tw >= 0)
				ret = max(ret, dp[u][l - tw] + tv);
		}
		return ret;
	}
}

int main() {
	// ifstream fin("in.txt");
	// ofstream fout("out.txt");
	cin >> n;
	for (int i=1; i<=n; i++) {
		cin >> v[i] >> w[i];
	}
	// for (int i=2; i<=n; i++) {
	// 	par[i] = i / 2;
	// }
	// par[1] = 0;
	for (int i=1; i<mxl; i++) {
		dp[1][i] = (i >= w[1] ? v[1] : 0);
	}
	for (int i=2; i<=min(511, n); i++) {
		int p = i / 2;
		for (int j=1; j<mxl; j++) {
			dp[i][j] = dp[p][j];
			if (j - w[i] >= 0)
				dp[i][j] = max(dp[i][j], dp[p][j - w[i]] + v[i]);
			// dp[i][j] = max(dp[i][j], dp[i][j - 1]);
		}
	}
	cin >> q;
	for (int i=0; i<q; i++) {
		int u, l;
		fin >> u >> l;
		// if (i == 0)
			cout << solve(u, l) << '\n';
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:61:17: error: 'fin' was not declared in this scope; did you mean 'sin'?
   61 |                 fin >> u >> l;
      |                 ^~~
      |                 sin
Language: C++

#include<bits/stdc++.h>
using namespace std;
long long dp[515][100005], v[262150];
int w[262150];
long long query(int x, int y){
    if(x < 512){
        return dp[x][y];
    }
    int ans = query(x/2, y);
    if(w[x] >= y){
        ans = max(ans, query(x/2, y - w[x]) + v[x]);
    }
    return ans;
}
int main(){
    for(int i = 0; i < 512; i++){
        for(int j = 0; j <= 100000; j++){
            dp[i][j] = 0;
        }
    }
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> v[i] >> w[i];
    }
    for(int i = 1; i < 512; i++){
        int f = i/2;
        for(int j = 1; j <= 100000; j++){
            dp[i][j] = dp[f][j];
            if(j >= w[i]){
                dp[i][j] = max(dp[i][j], dp[f][j - w[i]] + v[i]);
            }
        }
    }
    int q;
    cin >> q;
    for(int i = 1; i <= q; i++){
        int x, y;
        cin >> x >> y;
        cout << query(x, y) << '\n';
    }
    return 0;
}

Compiler output:
a.cc: In function 'long long int query(int, int)':
a.cc:11:18: error: no matching function for call to 'max(int&, long long int)'
   11 |         ans = max(ans, query(x/2, y - w[x]) + v[x]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:11:18: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   11 |         ans = max(ans, query(x/2, y - w[x]) + v[x]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:11:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   11 |         ans = max(ans, query(x/2, y - w[x]) + v[x]);
      |               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Language: C++

#include <bits/stdc++.h>
#define ll long long
using namespace std;

inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	
	while (ch<'0'||ch>'9)
	{
		if (ch=='-')  w=-w;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9')
	{
		s=(s<<1)+(s<<3)+(ch^'0');
		ch=getchar();
	}
	return s*w;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);//读入优化 
  
  ll n;
  cin >> n;//读入 
  
  vector<ll> v(n+1), w(n+1);//把它当成普通数组就可以啦 
  
  for (int i = 1; i <= n; i++)  v[i]=read(),w[i]=read();

  ll MAX_W = 100001LL;//所有询问的L值的最大值 
  vector<vector<ll> > dp(1LL<<10, vector<ll>(MAX_W, 0));//建立dp数组，向量套向量 

  for (ll i = 1; i < 1LL<<10; i++)//预处理出深度在(n/2)向下取整的节点的dp值(一行)，就是经典的01背包 
  {
    if (i > n) break;//如果它不是这棵树的节点，跳出 
    for (ll j = 1; j < MAX_W; j++)
	{
      dp[i][j] = dp[i/2][j];//dp[i/2][j]表示它父亲的dp值；即这个节点不选，直接继承上面的状态 
      if (j - w[i] >= 0) {//如果它是可以通过取该节点与其他一些东西所得到的 
        dp[i][j] = max(dp[i][j], dp[i/2][j-w[i]] + v[i]);
        //用dp[i/2][j-w[i]]+v[i]来更新答案
		//dp[i/2]表示其父节点的dp值。之所以不是dp[i]，是因为这不是无限背包 
      }
    }
  }
  ll query;//询问次数 
  cin >> query;//输入 
 
  for (ll q = 0; q < query; q++)//q次询问 
  {
    ll val, lim;
    val=read(),lim=read();
    if (val < (1LL<<10))//如果它已经被预处理过了，直接打印输出 
	{
      cout << dp[val][lim] << endl;
      continue;//别忘记continue 
    }
    
    ll ans = 0;
    int len = (int)(log2(val)) - 10 + 1;//记录下从len及它自己向上，有多少个节点没有被预处理过 
    for (int i = 0; i < (1<<len); i++)//01枚举上面未被预处理的len个节点的状态，即选或不选(与状压dp有些像) 
    { 
      ll vtemp = 0, wtemp = 0, index = val;
      //vtemp记录下当前被枚举选到的节点的value之和，wtemp同理记录下weight之和，方便转移 
      for (int j = 0; j < len; j++)
	  {
        if ((i>>j) & 1)//对于所有被选择的
		{
          vtemp += v[index];
          wtemp += w[index];
        }//求出vtemp,wtemp 
        index /= 2;//它的父亲 
        if (index < 1LL<<10)//如果index的这个节点已经被预处理过，尝试转移 
		{
          if (lim - wtemp < 0) break;//根本挤不下去，选这些都超过上限limit了，直接跳出 
          ans = max(ans, vtemp + dp[index][lim-wtemp]);
          //全篇最最核心的代码
		  //用vtemp+dp[intex][lim-wtemp]更新答案。即，vtemp表示当前的价值，还要加上之前预处理过的值，就是节点为index，上限为lim-wtemp所能得到的价值和的最大值 
          break;//转移成功，溜掉 
        }
      }
    }
    cout << ans << endl;//打印输出 
  }
  return 0; 
}
//完结撒花 

Compiler output:
a.cc:10:27: warning: missing terminating ' character
   10 |         while (ch<'0'||ch>'9)
      |                           ^
a.cc:10:27: error: missing terminating ' character
   10 |         while (ch<'0'||ch>'9)
      |                           ^~~
a.cc: In function 'int read()':
a.cc:11:9: error: expected primary-expression before '{' token
   11 |         {
      |         ^
a.cc:10:27: error: expected ')' before '{' token
   10 |         while (ch<'0'||ch>'9)
      |               ~           ^
      |                           )
   11 |         {
      |         ~
Language: C++

#include <bits/stdc++.h>
using namespace std;int p[1024][1<<17],v[1<<19],w[1<<19],q,l,i,f(int a,int l){if(l<0)return -1e9;if(!a)return 0;if(a>1023)return max(f(a/2,l),f(a/2,l-w[a])+v[a]);if(~p[a][l])return p[a][l];return p[a][l]=max({f(a/2,l),f(a,l-1),f(a/2,l-w[a])+v[a]});};int main(){memset(p,-1,1<<29);cin>>l;for(;i++<l;)cin>>v[i]>>w[i];cin>>q;while(q--){cin>>i>>l;cout<<f(i,l)<<" ";}}

Compiler output:
a.cc:2:78: error: a function-definition is not allowed here before '{' token
    2 | using namespace std;int p[1024][1<<17],v[1<<19],w[1<<19],q,l,i,f(int a,int l){if(l<0)return -1e9;if(!a)return 0;if(a>1023)return max(f(a/2,l),f(a/2,l-w[a])+v[a]);if(~p[a][l])return p[a][l];return p[a][l]=max({f(a/2,l),f(a,l-1),f(a/2,l-w[a])+v[a]});};int main(){memset(p,-1,1<<29);cin>>l;for(;i++<l;)cin>>v[i]>>w[i];cin>>q;while(q--){cin>>i>>l;cout<<f(i,l)<<" ";}}
      |                                                                              ^
a.cc: In function 'int main()':
a.cc:2:350: error: 'f' was not declared in this scope
    2 | using namespace std;int p[1024][1<<17],v[1<<19],w[1<<19],q,l,i,f(int a,int l){if(l<0)return -1e9;if(!a)return 0;if(a>1023)return max(f(a/2,l),f(a/2,l-w[a])+v[a]);if(~p[a][l])return p[a][l];return p[a][l]=max({f(a/2,l),f(a,l-1),f(a/2,l-w[a])+v[a]});};int main(){memset(p,-1,1<<29);cin>>l;for(;i++<l;)cin>>v[i]>>w[i];cin>>q;while(q--){cin>>i>>l;cout<<f(i,l)<<" ";}}
      |                                                                                                                                                                                                                                                                                                                                                              ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef int I;
#define REP(i,n) for(I i=0;i<(I)(n);i++)

I n,dp[1024][100001],v[323456],w[323456];

void dfs(I i){
    I j=i/2;
    if(i>1){
        for(I k=1024;k+1;k--){
            if(dp[j-1][k]or!k){
                I ne=k+w[i-1];
                if(ne<=100000)dp[i-1][ne]=max(dp[j-1][k]+v[i-1],dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=min(1024,n))dfs(i*2);
    if(i*2+1<=min(1024,n))dfs(i*2+1);
}

signed main(){
    cin>>n;
    REP(i,n){I x,y;cin>>v[i]>>w[i];}
    dp[0][w[0]]=v[0];
    dfs(1);
    REP(i,1024)REP(j,100000)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    I q;cin>>q;
    REP(i,q){
        I u,l;cin>>u>>l;
        vector<I> cand;
        while(u>c1){
            cand.push_back(u);
            u=u/2;
        }
        I r=cand.size();
        I ans=0;
        REP(j,1<<r){
            I v_sub=0;I w_sub=0;
            REP(k,r){
                if(j>>k&1){
                    v_sub+=v[cand[k]-1];
                    w_sub+=w[cand[k]-1];
                }
            }
            if(w_sub<=l)ans=max(ans,dp[u-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:33:17: error: 'c1' was not declared in this scope; did you mean 'y1'?
   33 |         while(u>c1){
      |                 ^~
      |                 y1
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef int I;
#define REP(i,n) for(I i=0;i<(I)(n);i++)

I n,dp[1024][100001],v[323456],w[323456];

void dfs(I i){
    I j=i/2;
    if(i>1){
        for(I k=1024;k+1;k--){
            if(dp[j-1][k]or!k){
                I ne=k+w[i-1];
                if(ne<=100000)dp[i-1][ne]=max(dp[j-1][k]+v[i-1],dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=min(c1,n))dfs(i*2);
    if(i*2+1<=min(c1,n))dfs(i*2+1);
}

signed main(){
    cin>>n;
    REP(i,n){I x,y;cin>>v[i]>>w[i];}
    dp[0][w[0]]=v[0];
    dfs(1);
    REP(i,1024)REP(j,100000)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    I q;cin>>q;
    REP(i,q){
        I u,l;cin>>u>>l;
        vector<I> cand;
        while(u>c1){
            cand.push_back(u);
            u=u/2;
        }
        I r=cand.size();
        I ans=0;
        REP(j,1<<r){
            I v_sub=0;I w_sub=0;
            REP(k,r){
                if(j>>k&1){
                    v_sub+=v[cand[k]-1];
                    w_sub+=w[cand[k]-1];
                }
            }
            if(w_sub<=l)ans=max(ans,dp[u-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
}


Compiler output:
a.cc: In function 'void dfs(I)':
a.cc:19:17: error: 'c1' was not declared in this scope; did you mean 'y1'?
   19 |     if(i*2<=min(c1,n))dfs(i*2);
      |                 ^~
      |                 y1
a.cc:20:19: error: 'c1' was not declared in this scope; did you mean 'y1'?
   20 |     if(i*2+1<=min(c1,n))dfs(i*2+1);
      |                   ^~
      |                   y1
a.cc: In function 'int main()':
a.cc:33:17: error: 'c1' was not declared in this scope; did you mean 'y1'?
   33 |         while(u>c1){
      |                 ^~
      |                 y1
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef int I;
#define REP(i,n) for(I i=0;i<(I)(n);i++)

I n;I vw[323456][2],dp[1024][900001];
I c1,c2;

void dfs(I i){
    I j=i/2;
    if(i>1){
        for(I k=c2;k+1;k--){
            if(dp[j-1][k]or!k){
                I ne=k+vw[i-1][1];
                dp[i-1][ne]=max(dp[j-1][k]+vw[i-1][0],dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=min(c1,n))dfs(i*2);
    if(i*2+1<=min(c1,n))dfs(i*2+1);
}

signed main(){
    cin>>n;
    //vw.resize(n);
    REP(i,n){cin>>vw[i][0]>>vw[i][1];}
    c1=1024;c2=100000;
    //dp.resize(c1);REP(i,c1)dp[i].resize(c2+1);
    dp[0][vw[0][1]]=vw[0][0];
    dfs(1);
    REP(i,c1)REP(j,c2)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    I q;cin>>q;
    REP(i,q){
        I v,l;cin>>v>>l;
        vector<I> cand;
        while(v>c1){
            cand.push_back(v);
            v=v/2;
        }
        I r=cand.size();
        I ans=0;
        REP(j,1<<r){
            I v_sub=0;I w_sub=0;
            REP(k,r){
                if(j>>k&1){
                    v_sub+=vw[cand[k]-1][0];
                    w_sub+=vw[cand[k]-1][1];
                }
            }
            if(w_sub<=l)ans=max(ans,dp[v-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
}


Compiler output:
/tmp/cc3DH9P3.o: in function `dfs(int)':
a.cc:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/cc3DH9P3.o
a.cc:(.text+0x1b3): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/cc3DH9P3.o
a.cc:(.text+0x1e9): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/cc3DH9P3.o
/tmp/cc3DH9P3.o: in function `main':
a.cc:(.text+0x2a0): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/cc3DH9P3.o
a.cc:(.text+0x2aa): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/cc3DH9P3.o
a.cc:(.text+0x384): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/cc3DH9P3.o
a.cc:(.text+0x397): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/cc3DH9P3.o
a.cc:(.text+0x423): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/cc3DH9P3.o
collect2: error: ld returned 1 exit status
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef int I;
#define REP(i,n) for(I i=0;i<(I)(n);i++)

I n;I vw[500000][2],dp[1024][900001];
I c1,c2;

void dfs(I i){
    I j=i/2;
    if(i>1){
        for(I k=c2;k+1;k--){
            if(dp[j-1][k]or!k){
                I ne=k+vw[i-1][1];
                dp[i-1][ne]=max(dp[j-1][k]+vw[i-1][0],dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=min(c1,n))dfs(i*2);
    if(i*2+1<=min(c1,n))dfs(i*2+1);
}

signed main(){
    cin>>n;
    //vw.resize(n);
    REP(i,n){cin>>vw[i][0]>>vw[i][1];}
    c1=1024;c2=100000;
    //dp.resize(c1);REP(i,c1)dp[i].resize(c2+1);
    dp[0][vw[0][1]]=vw[0][0];
    dfs(1);
    REP(i,c1)REP(j,c2)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    I q;cin>>q;
    REP(i,q){
        I v,l;cin>>v>>l;
        vector<I> cand;
        while(v>c1){
            cand.push_back(v);
            v=v/2;
        }
        I r=cand.size();
        I ans=0;
        REP(j,1<<r){
            I v_sub=0;I w_sub=0;
            REP(k,r){
                if(j>>k&1){
                    v_sub+=vw[cand[k]-1][0];
                    w_sub+=vw[cand[k]-1][1];
                }
            }
            if(w_sub<=l)ans=max(ans,dp[v-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
}


Compiler output:
/tmp/cc3KnTn7.o: in function `dfs(int)':
a.cc:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/cc3KnTn7.o
a.cc:(.text+0x1b3): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/cc3KnTn7.o
a.cc:(.text+0x1e9): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/cc3KnTn7.o
/tmp/cc3KnTn7.o: in function `main':
a.cc:(.text+0x2a0): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/cc3KnTn7.o
a.cc:(.text+0x2aa): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/cc3KnTn7.o
a.cc:(.text+0x384): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/cc3KnTn7.o
a.cc:(.text+0x397): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/cc3KnTn7.o
a.cc:(.text+0x423): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/cc3KnTn7.o
collect2: error: ld returned 1 exit status
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef int I;
#define REP(i,n) for(I i=0;i<(I)(n);i++)

I n;I vw[1<<20][2],dp[1024][1<<20];
I c1,c2;

void dfs(I i){
    I j=i/2;
    if(i>1){
        for(I k=c2;k+1;k--){
            if(dp[j-1][k]or!k){
                I ne=k+vw[i-1][1];
                if(ne<=c2)dp[i-1][ne]=max(dp[j-1][k]+vw[i-1][0],dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=min(c1,n))dfs(i*2);
    if(i*2+1<=min(c1,n))dfs(i*2+1);
}

signed main(){
    cin>>n;
    //vw.resize(n);
    REP(i,n){cin>>vw[i][0]>>vw[i][1];}
    c1=1024;c2=100000;
    //dp.resize(c1);REP(i,c1)dp[i].resize(c2+1);
    dp[0][vw[0][1]]=vw[0][0];
    dfs(1);
    REP(i,c1)REP(j,c2)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    I q;cin>>q;
    REP(i,q){
        I v,l;cin>>v>>l;
        vector<I> cand;
        while(v>c1){
            cand.push_back(v);
            v=v/2;
        }
        I r=cand.size();
        I ans=0;
        REP(j,1<<r){
            I v_sub=0;I w_sub=0;
            REP(k,r){
                if(j>>k&1){
                    v_sub+=vw[cand[k]-1][0];
                    w_sub+=vw[cand[k]-1][1];
                }
            }
            if(w_sub<=l)ans=max(ans,dp[v-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
}


Compiler output:
/tmp/ccA0GKIs.o: in function `dfs(int)':
a.cc:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/ccA0GKIs.o
a.cc:(.text+0x8c): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/ccA0GKIs.o
a.cc:(.text+0x1af): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/ccA0GKIs.o
a.cc:(.text+0x1e5): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/ccA0GKIs.o
/tmp/ccA0GKIs.o: in function `main':
a.cc:(.text+0x29c): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/ccA0GKIs.o
a.cc:(.text+0x2a6): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/ccA0GKIs.o
a.cc:(.text+0x377): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/ccA0GKIs.o
a.cc:(.text+0x38a): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/ccA0GKIs.o
a.cc:(.text+0x416): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/ccA0GKIs.o
collect2: error: ld returned 1 exit status
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef int I;
#define REP(i,n) for(I i=0;i<(I)(n);i++)

I n;I vw[1<<20][2],dp[1024][1<<20];
I c1,c2;

void dfs(I i){
    I j=i/2;
    if(i>1){
        for(I k=c2;k+1;k--){
            if(dp[j-1][k]or!k){
                I ne=k+vw[i-1][1];
                if(ne<=c2)dp[i-1][ne]=max(dp[j-1][k]+vw[i-1][0],dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=min(c1,n))dfs(i*2);
    if(i*2+1<=min(c1,n))dfs(i*2+1);
}

signed main(){
    cin>>n;
    //vw.resize(n);
    REP(i,n){I x,y;cin>>vw[i][0]>>vw[i][1];}
    c1=1024;c2=100000;
    //dp.resize(c1);REP(i,c1)dp[i].resize(c2+1);
    dp[0][vw[0][1]]=vw[0][0];
    dfs(1);
    REP(i,c1)REP(j,c2)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    I q;cin>>q;
    REP(i,q){
        I v,l;cin>>v>>l;
        vector<I> cand;
        while(v>c1){
            cand.push_back(v);
            v=v/2;
        }
        I r=cand.size();
        I ans=0;
        REP(j,1<<r){
            I v_sub=0;I w_sub=0;
            REP(k,r){
                if(j>>k&1){
                    v_sub+=vw[cand[k]-1][0];
                    w_sub+=vw[cand[k]-1][1];
                }
            }
            if(w_sub<=l)ans=max(ans,dp[v-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
}


Compiler output:
/tmp/ccG16API.o: in function `dfs(int)':
a.cc:(.text+0x27): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/ccG16API.o
a.cc:(.text+0x8c): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/ccG16API.o
a.cc:(.text+0x1af): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/ccG16API.o
a.cc:(.text+0x1e5): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/ccG16API.o
/tmp/ccG16API.o: in function `main':
a.cc:(.text+0x29c): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/ccG16API.o
a.cc:(.text+0x2a6): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/ccG16API.o
a.cc:(.text+0x377): relocation truncated to fit: R_X86_64_PC32 against symbol `c2' defined in .bss section in /tmp/ccG16API.o
a.cc:(.text+0x38a): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/ccG16API.o
a.cc:(.text+0x416): relocation truncated to fit: R_X86_64_PC32 against symbol `c1' defined in .bss section in /tmp/ccG16API.o
collect2: error: ld returned 1 exit status
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef int I;
#define REP(i,n) for(I i=0;i<(I)(n);i++)

I n;I vw[26214][2],dp[1024][100001];
I c1,c2;

void dfs(I i){
    I j=i/2;
    if(i>1){
        for(I k=c2;k+1;k--){
            if(dp[j-1][k]or!k){
                I ne=k+vw[i-1][1];
                if(ne<=c2)dp[i-1][ne]=max(dp[j-1][k]+vw[i-1][0],dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=min(c1,n))dfs(i*2);
    if(i*2+1<=min(c1,n))dfs(i*2+1);
}

signed main(){
    cin>>n;
    //vw.resize(n);
    REP(i,n){I x,y;cin>>x>>y;vw[i]={x,y};}
    c1=1024;c2=100000;
    //dp.resize(c1);REP(i,c1)dp[i].resize(c2+1);
    dp[0][vw[0][1]]=vw[0][0];
    dfs(1);
    REP(i,c1)REP(j,c2)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    I q;cin>>q;
    REP(i,q){
        I v,l;cin>>v>>l;
        vector<I> cand;
        while(v>c1){
            cand.push_back(v);
            v=v/2;
        }
        I r=cand.size();
        I ans=0;
        REP(j,1<<r){
            I v_sub=0;I w_sub=0;
            REP(k,r){
                if(j>>k&1){
                    v_sub+=vw[cand[k]-1][0];
                    w_sub+=vw[cand[k]-1][1];
                }
            }
            if(w_sub<=l)ans=max(ans,dp[v-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:27:35: error: assigning to an array from an initializer list
   27 |     REP(i,n){I x,y;cin>>x>>y;vw[i]={x,y};}
      |                              ~~~~~^~~~~~
Language: C++

// IN the name of GOD

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M = 1e9 + 7, N = 1e5 + 10;
int n;
void solve () {
    cin >> n;
    vector <int> val(n + 1), w(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> val[i] >> w[i];
    }
    int limit = min (512, n);
    vector<vector<int>> dp(limit, vector<int>(N));
    for (int j = 0; j < N; ++i) {
        dp[0][j] = (j >= w[0] ? v[0] : 0);
    }
    for (int i = 1; i < limit; ++i) {
        int p = (i - 1)/2;
        for (int j = 0; j < N; j++) {
            dp[i][j] = dp[p][j];
            if (j >= w[i]) {
                dp[i][j] = max(dp[i][j], dp[p][j] - w[i] + v[i]);

            }
        }
    }

    int tt;
    cin >> tt;
    while (tt-) {
        int ver, L;
        cin >> ver >> L;
        --ver;
        vector <int> ids;
        while (ver >= limit) {
            ids.push_back(ver);
            ver = (ver - 1)/2;
        }
        int sz = (int)ids.size();
        int ans = 0;
        for (int t = 0; t < (1 << sz); t++) {
            int sv = 0;
            int sw = 0;
            for (int i = 0; i < sz; ++i) {
                if (tie & (1 << i)) {
                    sv += v[ids[i]];
                    sw += w[ids[i]];
                }
            }
            if (sw <= L) {
                ans = max(ans, dp[ver][L - sw] + sv);
            }
        }
        cout << ans << "\n";
    }

}
int main () {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int tt = 1;
        // scanf("%d", &tt);
    while (tt--)
        solve();
 
}


// 5Te8Y4drgCRfCx8ugdwuEX8KFC6k2EUu 
// bandit12


Compiler output:
a.cc: In function 'void solve()':
a.cc:16:30: error: 'i' was not declared in this scope
   16 |     for (int j = 0; j < N; ++i) {
      |                              ^
a.cc:17:33: error: 'v' was not declared in this scope
   17 |         dp[0][j] = (j >= w[0] ? v[0] : 0);
      |                                 ^
a.cc:24:60: error: 'v' was not declared in this scope
   24 |                 dp[i][j] = max(dp[i][j], dp[p][j] - w[i] + v[i]);
      |                                                            ^
a.cc:32:15: error: expected primary-expression before ')' token
   32 |     while (tt-) {
      |               ^
a.cc:47:25: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator&'
   47 |                 if (tie & (1 << i)) {
      |                     ~~~~^~~~~~~~~~
a.cc:48:27: error: 'v' was not declared in this scope
   48 |                     sv += v[ids[i]];
      |                           ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll dp[520][100005];

void Main() {
    ll N;
    cin >> N;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    ll Q;
    cin >> Q;

    // vector<vector<ll>> dp(min(N + 1, (1LL << 9) + 1), vector<ll>(100001, 0));
    rep2(i, 1, min(N + 1, (1LL << 9) + 1)) {
        rep(j, 100001) {
            ll par = i / 2;
            dp[i][j] = dp[par][j];
            if (j - items[i - 1].second >= 0) {
                dp[i][j] = max(dp[i][j], dp[par][j - items[i - 1].second] + items[i - 1].first);
            }
        }
    }
    vector<ll> ans(Q);
    vector<P> query(Q);
    rep(q, Q) cin >> query[q].first >> query[q].second;
    rep(q, Q) {
        ll v = query[q].first;
        ll L = query[q].sec;
        vector<ll> use;
        v--;
        ll u = v;
        use.push_back(u);
        while (u != 0) {
            u = (u - 1) / 2;
            use.push_back(u);
        }
        if (v < (1LL << 9)) {
            ans[q] = dp[v + 1][L];
            continue;
        }
        sort(use.begin(), use.end());
        ll n = use.size();
        vector<ll> use_p;
        ll last = -1;
        rep(i, n) {
            if (use[i] >= (1LL << 9)) {
                use_p.push_back(use[i]);
            } else {
                last = max(last, use[i]);
            }
        }
        ll a = 0;
        rep(i, 1LL << (ll) use_p.size()) {
            ll value = 0;
            ll weight = 0;
            rep(j, use_p.size()) {
                if (i & (1 << j)) {
                    value += items[use_p[j]].first;
                    weight += items[use_p[j]].second;
                    if (weight > L) break;
                }
            }
            if (L - weight < 0) continue;
            a = max(a, dp[last + 1][L - weight] + value);
        }
        ans[q] = a;
    }
    rep(q, Q) {
        cout << ans[q] << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Compiler output:
a.cc: In function 'void Main()':
a.cc:52:25: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<long long int, long long int> >, std::pair<long long int, long long int> >::value_type' {aka 'struct std::pair<long long int, long long int>'} has no member named 'sec'
   52 |         ll L = query[q].sec;
      |                         ^~~
Language: C++

#include <bits/stdc++.h>
#define MAX (ll)(1e5 + 7)
#define INF (ll)(1e18)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;
using cd = complex<double>;

int v[3 * MAX], w[3 * MAX], dp[sqrt (3 * MAX)][MAX];
int main () {
	int n, q;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> v[i] >> w[i];
	}
	int x = sqrt (n);
	for (int i = 0; i <= x; i++) {
		for (int j = 0; j < MAX; j++) {
			dp[i][j] = -MOD;
		}
	}
	dp[0][0] = 0;
	for (int i = 1; i <= x; i++) {
		for (int j = 0; j < MAX; j++) {
			dp[i][j] = max (dp[i / 2][j], dp[i][j]);
			if (j) {
				dp[i][j] = max (dp[i][j], dp[i][j - 1]);
			}
			if (j - w[i] >= 0) {
				dp[i][j] = max (dp[i / 2][j - w[i]] + v[i], dp[i][j]);
			}
		}
	}
	cin >> q;	
	for (int i = 0; i < q; i++) {
		int vv, l;
		cin >> vv >> l;
		vector<int> ve;
		while (vv > x) {
			ve.push_back (vv);
			vv = vv / 2;
		}
		int y = (1 << ve.size ()), ma = 0;
		for (int i = 0; i < y; i++) {
			int ww = 0, lx = 0;
			for (int j = 0; j < ve.size (); j++) {
				if ((i >> j) & 1) {
					ww += w[ve[j]], lx += v[ve[j]];
				}
			}
			if (ww <= l) {
				ma = max (lx + dp[vv][l - ww], ma);
			}
		}
		cout << ma << "\n";
	}
}


Compiler output:
a.cc:10:37: error: conversion from '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'} to 'long unsigned int' in a converted constant expression
   10 | int v[3 * MAX], w[3 * MAX], dp[sqrt (3 * MAX)][MAX];
      |                                ~~~~~^~~~~~~~~
a.cc:10:37: error: could not convert 'std::sqrt<long long int>((3 * (ll)(1.0e+5 + (double)7)))' from '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'} to 'long unsigned int'
   10 | int v[3 * MAX], w[3 * MAX], dp[sqrt (3 * MAX)][MAX];
      |                                ~~~~~^~~~~~~~~
      |                                     |
      |                                     __gnu_cxx::__enable_if<true, double>::__type {aka double}
a.cc:10:37: error: size of array 'dp' has non-integral type '__gnu_cxx::__enable_if<true, double>::__type' {aka 'double'}
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/


int main(){
  ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> v(n+1),w(n+1);
  rep(i,n){
    cin >> v[i+1] >> w[i+1];
  }
  vector<vector<P>> data((1<<9)+5); //d9 made hanbun-zenrekkyo
  REP(i,1,min(n+1,1<<9)){
    vector<int> ls;
    if(i==1){
      data[i].emplace_back(w[i],v[i]);
      data[i].emplace_back(0,0);
    } else {
      for(auto it:data[i/2]){
        data[i].emplace_back(it.F,it.S);
        data[i].emplace_back(it.F+w[i],it.S+v[i]);
      }
    }

    sort(data[i].begin(),data[i].end());
    REP(j,1,data[i].size()){
      data[i][j].S = max(data[i][j].S, data[i][j-1].S);
    }
  }

  int q;
  cin >> q;
  while(q--){
    int x,L; cin >> x >> L;
    if(x<min(n+1,1<<9)){
      int pos = lower_bound(data[x].begin(),data[x].end(),P(L+1,0)) - data[x].begin();
      int ans = data[x][pos-1].S;
      cout << ans << ln;
    } else {
      vector<int> ls;
      int tmp = x;
      while(tmp>=(1<<9)){ ls.emplace_back(tmp); tmp/=2; }
//      sort(ls.rbegin(),ls.rend());
      int ans = 0;
      rep(b,1<<sz){
        int vsum = 0, wsum = 0;
        rep(j,sz)if(bit(b,j)){
          vsum += v[ls[j]];
          wsum += w[ls[j]];
        }
        if(wsum>L) continue;
        int pos = lower_bound(data[tmp].begin(),data[tmp].end(),P(L-wsum+1,0)) - data[tmp].begin();
        ans = max(ans, vsum+data[tmp][pos-1].S);
      }
      cout << ans << ln;
    }
  }

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:61:16: error: 'sz' was not declared in this scope
   61 |       rep(b,1<<sz){
      |                ^~
a.cc:8:52: note: in definition of macro 'REP'
    8 | #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
      |                                                    ^
a.cc:61:7: note: in expansion of macro 'rep'
   61 |       rep(b,1<<sz){
      |       ^~~