QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#62048 | #3850. DJ Darko | 2pal1rak | Compile Error | / | / | C++20 | 4.7kb | 2022-11-17 02:19:23 | 2022-11-17 02:20:32 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2022-11-17 02:20:32]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2022-11-17 02:19:23]
- 提交
answer
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <random>
#include <cstdlib>
#define debug(x) std::cout << #x << " " << (x) << '\n';
#define pb push_back
#define mp std::make_pair
#define remax(a, b) a = std::max((a), (b));
#define remin(a, b) a = std::min((a), (b));
class FenwickTree {
private:
std::vector<int64_t> data;
public:
FenwickTree(int32_t n): data(n + 1, 0) {}
void add(int32_t ind, int64_t v) {
while(ind < data.size()) {
data[ind] += v;
ind += (ind & (-ind));
}
}
int64_t get(int32_t ind) {
int64_t res = 0;
while(ind > 0) {
res += data[ind];
ind -= (ind & (-ind));
}
return res;
}
};
struct Interval {
int32_t l, len;
int64_t val;
Interval(int32_t _l, int32_t _len, int64_t _val): l(_l), len(_len), val(_val) {}
bool operator<(const Interval &o) const {
if(l != o.l) return l < o.l;
else if(len != o.len) return len < o.len;
else return val < o.val;
}
};
void splitIntervals(std::set<Interval> &s, int32_t l, int32_t r) {
auto f = [](int x) {
int l = x;
auto it = s.lower_bound(Interval(l + 1, -1, 0));
if (it != s.begin()) {
it--;
if (it->l != l) {
auto i1 = Interval(it->l, l - it->l, it->val);
auto i2 = Interval(l, it->len - (l - it->l), it->val);
s.erase(it);
if (i1.len > 0)
s.insert(i1);
if (i2.len)
s.insert(i2);
}
}
}
f(l);
f(r + 1);
}
int main() {
#ifdef USEFOPEN
freopen("1.in", "r", stdin);
//freopen("1.out", "w", stdout);
#endif
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int32_t n, q;
std::cin >> n >> q;
std::vector<int32_t> a(n);
for(int32_t i = 0; i < n; i++) {
std::cin >> a[i];
}
std::vector<int64_t> b(n);
for(int32_t i = 0; i < n; i++) {
std::cin >> b[i];
if(i != 0) {
b[i] += b[i - 1];
}
}
auto getIntervalB = [&b](int32_t l, int32_t r) {
l--; r--;
return b[r] - (l == 0 ? 0 : b[l - 1]);
};
auto check = [](int32_t m, const std::vector<std::pair<int64_t, int64_t>> &x) {
int64_t middle = x[m].first, res = 0;
for(int32_t i = 0; i < x.size(); i++) {
res += abs(x[i].first - middle) * x[i].second;
}
return res;
};
std::set<Interval> s;
s.insert(Interval(n + 1, 0, 0));
s.insert(Interval(-1, 0, 0));
for(int32_t i = 0; i < n; i++) {
s.insert(Interval(i + 1, 1, a[i]));
}
FenwickTree fenwick(n);
for(int32_t i = 0; i < q; i++) {
int32_t type, l, r;
std::cin >> type >> l >> r;
if(type == 1) {
int32_t x;
std::cin >> x;
fenwick.add(l, x);
fenwick.add(r + 1, -x);
splitIntervals(s, l, r);
}
else {
splitIntervals(s, l, r);
std::vector<std::pair<int64_t, int64_t>> x;
auto it = s.lower_bound(Interval(l, -1, 0));
while(it->l <= r) {
int64_t prefSum = fenwick.get(it->l);
fenwick.add(it->l, -prefSum);
fenwick.add(it->l + it->len, prefSum);
x.pb({ it->val + prefSum, getIntervalB(it->l, it->l + it->len - 1) });
auto jt = it;
it++;
s.erase(jt);
}
std::sort(x.begin(), x.end());
int32_t low = 0, high = x.size() - 1;
while(low < high) {
int32_t mid = (low + high) / 2;
//std::cout << mid << " " << check(mid, x) << " " << check(mid + 1, x) << '\n';
if(check(mid, x) <= check(mid + 1, x)) {
high = mid;
}
else {
low = mid + 1;
}
}
assert(low == high);
std::cout << x[low].first << '\n';
s.insert(Interval(l, r - l + 1, x[low].first));
}
/**
for(auto &x : s) {
std::cout << " { " << x.l << ", " << x.len << ", " << x.val << " }, ";
}
std::cout << '\n';
*/
}
}
Details
answer.code: In lambda function: answer.code:65:19: error: ‘s’ is not captured 65 | auto it = s.lower_bound(Interval(l + 1, -1, 0)); | ^ answer.code:63:15: note: the lambda has no capture-default 63 | auto f = [](int x) { | ^ answer.code:61:41: note: ‘std::set<Interval>& s’ declared here 61 | void splitIntervals(std::set<Interval> &s, int32_t l, int32_t r) { | ~~~~~~~~~~~~~~~~~~~~^ answer.code:66:19: error: ‘s’ is not captured 66 | if (it != s.begin()) { | ^ answer.code:63:15: note: the lambda has no capture-default 63 | auto f = [](int x) { | ^ answer.code:61:41: note: ‘std::set<Interval>& s’ declared here 61 | void splitIntervals(std::set<Interval> &s, int32_t l, int32_t r) { | ~~~~~~~~~~~~~~~~~~~~^ answer.code:71:17: error: ‘s’ is not captured 71 | s.erase(it); | ^ answer.code:63:15: note: the lambda has no capture-default 63 | auto f = [](int x) { | ^ answer.code:61:41: note: ‘std::set<Interval>& s’ declared here 61 | void splitIntervals(std::set<Interval> &s, int32_t l, int32_t r) { | ~~~~~~~~~~~~~~~~~~~~^ answer.code:73:21: error: ‘s’ is not captured 73 | s.insert(i1); | ^ answer.code:63:15: note: the lambda has no capture-default 63 | auto f = [](int x) { | ^ answer.code:61:41: note: ‘std::set<Interval>& s’ declared here 61 | void splitIntervals(std::set<Interval> &s, int32_t l, int32_t r) { | ~~~~~~~~~~~~~~~~~~~~^ answer.code:75:21: error: ‘s’ is not captured 75 | s.insert(i2); | ^ answer.code:63:15: note: the lambda has no capture-default 63 | auto f = [](int x) { | ^ answer.code:61:41: note: ‘std::set<Interval>& s’ declared here 61 | void splitIntervals(std::set<Interval> &s, int32_t l, int32_t r) { | ~~~~~~~~~~~~~~~~~~~~^ answer.code: In function ‘void splitIntervals(std::set<Interval>&, int32_t, int32_t)’: answer.code:80:5: error: expected ‘,’ or ‘;’ before ‘f’ 80 | f(l); | ^