Submission #234277

#TimeUsernameProblemLanguageResultExecution timeMemory
234277DS007Fortune Telling 2 (JOI14_fortune_telling2)C++14
100 / 100
748 ms73748 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e5; vector<int> t[N * 4]; int n, k, a[N], b[N], c[N]; void build(int v, int l, int r) { if (l == r) { t[v].push_back(c[l]); return; } int mid = (l + r) / 2; build(v * 2, l, mid); build(v * 2 + 1, mid + 1, r); merge(t[v * 2].begin(), t[v * 2].end(), t[v * 2 + 1].begin(), t[v * 2 + 1].end(), back_inserter(t[v])); } int last(int v, int l, int r, int tl, int tr) { if (l == r) { if (tl <= c[l] && c[l] <= tr) return l; else return -1; } int mid = (l + r) / 2; if (lower_bound(t[v * 2 + 1].begin(), t[v * 2 + 1].end(), tl) == upper_bound(t[v * 2 + 1].begin(), t[v * 2 + 1].end(), tr)) return last(v * 2, l, mid, tl, tr); else return last(v * 2 + 1, mid + 1, r, tl, tr); } int count(int v, int l, int r, int tl, int tr, int lower) { if (tl > tr) return 0; else if (l == tl && r == tr) return t[v].end() - lower_bound(t[v].begin(), t[v].end(), lower); int mid = (l + r) / 2; return count(v * 2, l, mid, tl, min(mid, tr), lower) + count(v * 2 + 1, mid + 1, r, max(mid + 1, tl), tr, lower); } int solveTestCase(int test) { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; for (int i = 0; i < k; i++) cin >> c[i]; build(1, 0, k - 1); int ans = 0; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { ans += a[i]; continue; } int tl = last(1, 0, k - 1, min(a[i], b[i]), max(a[i], b[i]) - 1); int f = count(1, 0, k - 1, tl + 1, k - 1, max(a[i], b[i])); if (tl == -1) { if (f % 2) ans += b[i]; else ans += a[i]; } else { if (f % 2) ans += min(a[i], b[i]); else ans += max(a[i], b[i]); } } cout << ans; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int test = 1; //cin >> test; for (int i = 1; i <= test; i++) solveTestCase(i); }

Compilation message (stderr)

fortune_telling2.cpp: In function 'long long int solveTestCase(long long int)':
fortune_telling2.cpp:76:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...