Submission #1119981

#TimeUsernameProblemLanguageResultExecution timeMemory
1119981Yang8onFortune Telling 2 (JOI14_fortune_telling2)C++17
100 / 100
353 ms33364 KiB
#include <bits/stdc++.h> #define Y8o "FortuneTelling2" #define maxn (int) 2e5 + 5 #define ll long long #define pii pair<int, int> #define gb(i, j) ((i >> j) & 1) #define all(x) x.begin(), x.end() #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define fi(i, a, b) for(int i = a; i <= b; i ++) #define fid(i, a, b) for(int i = a; i >= b; i --) #define f first #define s second using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll GetRandom(ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rng); } void iof() { ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL); if(fopen(Y8o".inp", "r")) { freopen(Y8o".inp", "r", stdin); // freopen(Y8o".out", "w", stdout); } } void ctime() { cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; } int n, Q, N, ans[maxn]; pii a[maxn]; int qr[maxn], ma[maxn]; vector<int> cur; vector<pii> events[maxn]; struct SEGMT { int st[(int)4e6 + 5]; void update(int i, int val, int id = 1, int l = 1, int r = N) { if(i < l || r < i) return ; if(l == r) return st[id] = max(st[id], val), void(); int mid = (l + r) >> 1; update(i, val, _left), update(i, val, _right); st[id] = max(st[id * 2], st[id * 2 + 1]); } int get(int u, int v, int id = 1, int l = 1, int r = N) { if(v < l || r < u) return 0; if(u <= l && r <= v) return st[id]; int mid = (l + r) >> 1; return max( get(u, v, _left), get(u, v, _right) ); } } ST; struct BIT { int bit[(int)1e6 + 5]; void update(int x, int val) { while(x > 0) bit[x] += val, x -= (x & -x); } int get(int x, int best = 0) { while(x <= (int)1e6) best += bit[x], x += (x & -x); return best; } } Bit; int fake(int x) { return lower_bound(all(cur), x) - cur.begin() + 1; } void solve() { cin >> n >> Q; fi(i, 1, n) cin >> a[i].f >> a[i].s, cur.push_back(a[i].f), cur.push_back(a[i].s); fi(i, 1, Q) cin >> qr[i], cur.push_back(qr[i]); sort(all(cur)); cur.resize(unique(all(cur)) - cur.begin()); N = cur.size(); fi(i, 1, Q) ST.update(fake(qr[i]), i); fi(i, 1, n) { int L = min(a[i].f, a[i].s), R = max(a[i].f, a[i].s); int vt = ST.get(fake(L), fake(R) - 1) + 1; if(vt != 1) a[i] = {R, L}; events[vt].push_back({ i, fake(R) }); } fid(i, Q, 1) { Bit.update(fake(qr[i]), +1); while(events[i].size()) { int id, R; tie(id, R) = events[i].back(); events[i].pop_back(); if(Bit.get(R) % 2) swap(a[id].f, a[id].s); } } ll sum = 0; fi(i, 1, n) sum += a[i].f; //, cout << a[i].f << ' ' << a[i].s << '\n'; cout << sum; } int main() { iof(); int nTest = 1; // cin >> nTest; while(nTest --) { solve(); } ctime(); return 0; }

Compilation message (stderr)

fortune_telling2.cpp: In function 'void iof()':
fortune_telling2.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...