QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#74299 | #3857. Single-track railway | alvinhsu | Compile Error | / | / | C++14 | 2.2kb | 2023-01-31 15:46:52 | 2023-01-31 15:46:54 |
Judging History
This is the latest submission verdict.
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-01-31 15:46:54]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2023-01-31 15:46:52]
- Submitted
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...)
#endif
template<class T>
struct SegTree {
const T INIT{};
int size; vector<T> seg;
SegTree(int n, vector<T>&v) : size(1){
while(size < n) size <<= 1;
seg.assign(2*size+1, INIT); build(v);
}
T cmb(T a, T b){
return a + b;
}
void build(vector<T>&a) { build(a, 0, 0, size); }
void pull(T p){ seg[p] = cmb(seg[2*p+1], seg[2*p+2]); }
void upd(int i, int v) { upd(i, v, 0, 0, size); }
T query(int l, int r) { return query(l, r, 0, 0, size); }
void build(vector<T>&a, int node, int left, int right){
if (left == right){ if (left < a.size()) { seg[node] = a[left]; } return;}
int mid = left + (right - left) / 2;
build(a, node*2+1, left, mid); build(a, node*2+2, mid+1, right);
pull(node);
}
void upd(int i, int v, int node, int left, int right) {
if (left == right){ seg[node] = v; return; }
int mid = left + (right - left) / 2;
if (i <= mid){ upd(i,v,node*2+1, left, mid); }
else { upd(i,v,node*2+2, mid+1, right); }
pull(node);
}
T query(int l, int r, int node, int left, int right){
if (l > right || r < left) return INIT;
if (left >= l && right <= r) return seg[node];
int mid = left + (right - left) / 2;
return cmb(query(l, r, node*2+1, left, mid), query(l, r, node*2+2, mid+1, right));
}
};
void solve(){
//20 70 40 10 50
//20 90 130 140 190
int n;
cin >> n;
vector<int>v(n-1);
for (auto &a : v){
cin >> a;
}
SegTree st(n, v);
int q;
cin >> q;
int mn = 1e9;
auto bst = [&](){
int l = 0, r = n-1;
while(l < r){
int m = l + (r - l) / 2;
mn = min(mn, abs(st.query(0, m) - st.query(m+1, n-1)));
// dbg(m, st.query(0,m), st.query(m+1, n-1));
if (st.query(0, m) > st.query(m+1, n-1)){
r = m;
}
else {
l = m+1;
}
}
};
bst();
cout << mn << endl;
while(q--){
mn = 1e9;
int x,val;
cin >> x >> val;
st.upd(x-1, val);
bst();
cout << mn << endl;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int tc = 1;
// cin >> tc;
for (int i = 1; i <= tc; i++){
//cout << "Case #" << i << ": ";
solve();
}
return 0;
}
詳細信息
answer.code: In function ‘void solve()’: answer.code:58:17: error: missing template arguments before ‘st’ 58 | SegTree st(n, v); | ^~ answer.code: In lambda function: answer.code:66:42: error: ‘st’ was not declared in this scope; did you mean ‘bst’? 66 | mn = min(mn, abs(st.query(0, m) - st.query(m+1, n-1))); | ^~ | bst answer.code: In function ‘void solve()’: answer.code:82:17: error: ‘st’ was not declared in this scope; did you mean ‘bst’? 82 | st.upd(x-1, val); | ^~ | bst