Submission #1020924

#TimeUsernameProblemLanguageResultExecution timeMemory
1020924mdn2002Distributing Candies (IOI21_candies)C++17
Compilation error
0 ms0 KiB
/* Mayoeba Yabureru */ #include<bits/stdc++.h> #include <pstl/execution_impl.h> using namespace std; struct Node { int valuel = 0, valuer = 0, lazyadd = 0, lazyset = -1; int left = -1, right = -1; Node() {} }; Node st[5000006]; int cnt; void push(int node, int l, int r) { int left = st[node].left, right = st[node].right; if (st[node].lazyset != -1) { //cout << '*' << l << ' ' << r << ' ' << st[node].lazyset << ' ' << st[node].lazyadd << endl; if (st[node].lazyset == 0) { st[node].valuel = 0; st[node].valuer = 0; } else { st[node].valuel = l; st[node].valuer = r; } st[node].valuel += st[node].lazyadd; st[node].valuer += st[node].lazyadd; if (l != r) { st[left].lazyset = st[right].lazyset = st[node].lazyset; st[left].lazyadd = st[right].lazyadd = 0; st[left].lazyadd += st[node].lazyadd; st[right].lazyadd += st[node].lazyadd; } st[node].lazyset = -1; st[node].lazyadd = 0; } else if (st[node].lazyadd != 0) { st[left].lazyadd += st[node].lazyadd; st[right].lazyadd += st[node].lazyadd; st[node].valuel += st[node].lazyadd; st[node].valuer += st[node].lazyadd; st[node].lazyadd = 0; } } void update(int node, int l, int r, int val) { if (st[node].left == -1) { st[node].left = ++ cnt; st[cnt] = Node(); } if (st[node].right == -1) { st[node].right = ++ cnt; st[cnt] = Node(); } //cout << ' ' << l << ' ' << r << ' ' << st[node].lazyset << endl; push(node, l, r); long long vall = st[node].valuel, valr = st[node].valuer; //cout << ' ' << l << ' ' << r << ' ' << vall << ' ' << valr << ' ' << val << endl; if (val >= 0 && vall + val > l && valr + val > r) { // all the boxes with cap inbetween l and r are set to equal the cap st[node].lazyadd = 0; st[node].lazyset = 1; push(node, l, r); return; } if (val >= 0 && vall + val <= l && valr + val <= r) { // all the boxes with cap inbetween l and r are added val st[node].lazyadd = val; push(node, l, r); return; } if (val < 0 && vall + val < 0 && valr + val < 0) { // all the boxes with cap inbetween l and r are set to equal the 0 st[node].lazyadd = 0; st[node].lazyset = 0; push(node, l, r); return; } if (val < 0 && vall + val >= 0 && valr + val >= 0) { // all the boxes with cap inbetween l and r are added val st[node].lazyadd = val; push(node, l, r); return; } int mid = (l + r) / 2; int left = st[node].left, right = st[node].right; update(left, l, mid, val); update(right, mid + 1, r, val); st[node].valuel = st[left].valuel; st[node].valuer = st[right].valuer; } int query(int node, int l, int r, int x) { if (st[node].left == -1) { st[node].left = ++ cnt; st[cnt] = Node(); } if (st[node].right == -1) { st[node].right = ++ cnt; st[cnt] = Node(); } push(node, l, r); if (l == x && r == x) return st[node].valuel; int mid = (l + r) / 2; if (x <= mid) return query(st[node].left, l, mid, x); return query(st[node].right, mid + 1, r, x); } vector<int> distribute_candies(std::vector<int> c, std::vector<int> l, std::vector<int> r, std::vector<int> v) { int n = c.size(); st[0] = Node(); for (auto x : v) update(0, 1, 1e9, x); vector<int> s(n); for (int i = 0; i < n; i ++) { //cout << ' ' << c[i] << endl; s[i] = query(0, 1, 1e9, c[i]); } return s; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int T = 1; for (int I = 0; I < T; I ++){ int n; cin >> n; vector<int> c(n); for(int i = 0; i < n; ++i) cin >> c[i]; int q; cin >> q; vector<int> l(q), r(q), v(q); for(int i = 0; i < q; ++i) cin >> l[i] >> r[i] >> v[i]; vector<int> ans = distribute_candies(c, l, r, v); for(int i = 0; i < n; ++i) cout << ans[i] << ' '; cout << endl; } } /* 3 10 15 13 2 0 2 20 0 2 -11 */

Compilation message (stderr)

/usr/bin/ld: /tmp/cc06ezIM.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cctqtSAI.o:candies.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status