Submission #429783

#TimeUsernameProblemLanguageResultExecution timeMemory
429783schseHandcrafted Gift (IOI20_gift)C++17
25 / 100
195 ms21188 KiB
#include "gift.h" #include <bits/stdc++.h> using namespace std; #ifndef EVAL #include "grader.cpp" #endif struct node { int val = -1; int substr = 0; }; struct segtree { vector<node> tree = vector<node>(1 << 20); void updset(int index, int b, int e, int l, int r, int v) { if (l <= b && e <= r) { tree[index] = {v, 0}; return; } if (e <= l || r <= b) return; { if (tree[index * 2].val == -1) tree[index * 2].substr += tree[index].substr; else tree[index * 2].val -= tree[index].substr; if (tree[index * 2 + 1].val == -1) tree[index * 2 + 1].substr += tree[index].substr; else tree[index * 2 + 1].val -= tree[index].substr; if (tree[index].val != -1) tree[index * 2] = tree[index * 2 + 1] = {tree[index].val, 0}; } updset(index * 2, b, (b + e) / 2, l, r, v); updset(index * 2 + 1, (b + e) / 2, e, l, r, v); } void updsubs(int index, int b, int e, int l, int r, int v) { if (l <= b && e <= r) { tree[index] = {-1, v}; return; } if (e <= l || r <= b) return; { if (tree[index * 2].val == -1) tree[index * 2].substr += tree[index].substr; else tree[index * 2].val -= tree[index].substr; if (tree[index * 2 + 1].val == -1) tree[index * 2 + 1].substr += tree[index].substr; else tree[index * 2 + 1].val -= tree[index].substr; if (tree[index].val != -1) tree[index * 2] = tree[index * 2 + 1] = {tree[index].val, 0}; } updsubs(index * 2, b, (b + e) / 2, l, r, v); updsubs(index * 2 + 1, (b + e) / 2, e, l, r, v); } int query(int index, int b, int e, int p) { if (p < b || p >= e) return 0; if (e - b == 1) return tree[index].val; return query(index * 2, b, (b + e) / 2, p) + query(index * 2 + 1, (b + e) / 2, e, p); } } tree; int construct(int n, int r, std::vector<int> a, std::vector<int> b, std::vector<int> x) { int sb = 0; for (int i : x) sb |= i; if (sb == 1) { std::string s(n, 'R'); craft(s); return 1; } else if (sb == 2) { for (int i = 0; i < a.size(); i++) if (a[i] == b[i]) return 0; std::string s(n, 'R'); for (int i = 0; i < n; i++) s[i] = i % 2 ? 'R' : 'B'; craft(s); return 1; } else { for (int i = 0; i < n; i++) tree.updset(1, 0, n, i, i + 1, i); vector<int> prefix(n); iota(prefix.begin(), prefix.end(), 0); for (int i = 0; i < a.size(); i++) //update single color { if (x[i] == 1) { int va = tree.query(1, 0, n, a[i]); int vb = tree.query(1, 0, n, b[i]); tree.updset(1, 0, n, a[i], b[i], va); tree.updsubs(1, 0, n, b[i], n, vb - va); /* for (int e = b[i] + 1; e < n; e++) prefix[e] -= prefix[b[i]] - prefix[a[i]]; for (int e = a[i] + 1; e < b[i] + 1; e++) prefix[e] = prefix[a[i]]; */ } } for (int i = 0; i < a.size(); i++) //check wetherpossible { if (x[i] == 2) { int va = tree.query(1, 0, n, a[i]); int vb = tree.query(1, 0, n, b[i]); if (vb - va < 1) return 0; /*if (prefix[b[i]] - prefix[a[i]] < 1) return 0;*/ } } std::string s(n, 'R'); for (int i = 0; i < n; i++) s[i] = tree.query(1, 0, n, i) % 2 ? 'R' : 'B'; craft(s); return 1; } }

Compilation message (stderr)

gift.cpp: In function 'int construct(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
gift.cpp:95:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         for (int i = 0; i < a.size(); i++)
      |                         ~~^~~~~~~~~~
gift.cpp:111:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |         for (int i = 0; i < a.size(); i++) //update single color
      |                         ~~^~~~~~~~~~
gift.cpp:127:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |         for (int i = 0; i < a.size(); i++) //check wetherpossible
      |                         ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...