답안 #383744

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383744 2021-03-30T18:56:24 Z Return_0 운세 보기 2 (JOI14_fortune_telling2) C++17
100 / 100
942 ms 87244 KB
#pragma GCC optimize("Ofast,unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef int ll; typedef long long lol;
typedef long double ld;
typedef pair <ll, ll> pll;

#ifdef SINA
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; }
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); }
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1); cout.flush();
#else
#define dbg(...) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< (x) << endl, 0
#define cl const ll
#define fr first
#define sc second
#define lc (v << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
#define All(x) (x).begin(), (x).end()

cl inf = sizeof(ll) == 4 ? (1e9 + 10) : (3e18), mod = 1e9 + 7, MOD = 998244353;

template <class A,class B> ostream& operator << (ostream& out,const pair<A,B>&a){return out<<'('<<a.first<<", "<<a.second<<')';}
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out<< '['; for (int i = -1; ++i < int(a.size());) out<< a[i] << (i + 1 < int(a.size()) ? ", " : ""); return out<<']'; }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;

cl N = 2e5 + 7, NNN = 6e5 + 7;

vector <ll> cmprs; inline ll indx (cl &x) { return upper_bound(All(cmprs), x) - cmprs.begin(); }
ll a [N], b [N], c [N], fen [NNN], n, q;
vector <pll> QR [NNN];
lol ans;

struct segtree1 {
	ll l, r, mx;
	segtree1 *lt, *rt;
	inline segtree1 (cl &L = 1, cl &R = N - 2) : l(L), r(R), mx(0) {}

	void build () {
		if (l == r) return;
		lt = new segtree1 (l, mid);
		rt = new segtree1 (mid + 1, r);
		lt->build();
		rt->build();
		mx = max(lt->mx, rt->mx);
	}

	void modify (cl &pos, cl &x) {
		if (l == r) {
			mx = x;
			return;
		}
		if (pos <= mid) lt->modify(pos, x);
		else rt->modify(pos, x);
		mx = max(lt->mx, rt->mx);
	}

	ll ask (cl &ql, cl &qr) {
		if (r < ql || qr < l)   return 0;
		if (ql <= l && r <= qr) return mx;
		return max(lt->ask(ql, qr), rt->ask(ql, qr));
	}
} seg;

inline void add (ll i) { for (; i; i -= i & -i) ++fen[i]; }
inline ll ask (ll i) { ll t = 0; for (i = indx(i); i < NNN; i += i & -i) t += fen[i]; return t; }

int main ()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin>> n >> q;
	for (ll i = 1; i <= n; i++) cin>> a[i] >> b[i], cmprs.push_back(a[i]), cmprs.push_back(b[i]);
	for (ll i = 1; i <= q; i++) cin>> c[i], cmprs.push_back(c[i]);

	sort(All(cmprs)); cmprs.resize(unique(All(cmprs)) - cmprs.begin());

	seg.r = SZ(cmprs); seg.build();
	for (ll i = 1; i <= q; i++) seg.modify(c[i] = indx(c[i]), i);

	for (ll i = 1; i <= n; i++) QR[seg.ask(indx(min(a[i], b[i])), indx(max(a[i], b[i])) - 1)].push_back({max(a[i], b[i]), i});

	for (ll i = q; i; i--) {
		for (auto &x : QR[i]) {
			if (ask(x.fr) & 1) ans += min(a[x.sc], b[x.sc]);
			else ans += max(a[x.sc], b[x.sc]);
		}
		add(c[i]);
	}
	for (auto &x : QR[0]) ans += (ask(x.fr) & 1 ? b[x.sc] : a[x.sc]);

	cout<< ans << endl;

	cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

	return 0;
}
/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14572 KB Output is correct
2 Correct 12 ms 14700 KB Output is correct
3 Correct 12 ms 14828 KB Output is correct
4 Correct 14 ms 14828 KB Output is correct
5 Correct 12 ms 14828 KB Output is correct
6 Correct 12 ms 14828 KB Output is correct
7 Correct 14 ms 14828 KB Output is correct
8 Correct 12 ms 14828 KB Output is correct
9 Correct 12 ms 14828 KB Output is correct
10 Correct 11 ms 14572 KB Output is correct
11 Correct 12 ms 14700 KB Output is correct
12 Correct 14 ms 14700 KB Output is correct
13 Correct 12 ms 14700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14572 KB Output is correct
2 Correct 12 ms 14700 KB Output is correct
3 Correct 12 ms 14828 KB Output is correct
4 Correct 14 ms 14828 KB Output is correct
5 Correct 12 ms 14828 KB Output is correct
6 Correct 12 ms 14828 KB Output is correct
7 Correct 14 ms 14828 KB Output is correct
8 Correct 12 ms 14828 KB Output is correct
9 Correct 12 ms 14828 KB Output is correct
10 Correct 11 ms 14572 KB Output is correct
11 Correct 12 ms 14700 KB Output is correct
12 Correct 14 ms 14700 KB Output is correct
13 Correct 12 ms 14700 KB Output is correct
14 Correct 39 ms 18028 KB Output is correct
15 Correct 61 ms 21616 KB Output is correct
16 Correct 96 ms 25196 KB Output is correct
17 Correct 133 ms 28780 KB Output is correct
18 Correct 135 ms 28780 KB Output is correct
19 Correct 134 ms 28780 KB Output is correct
20 Correct 135 ms 28908 KB Output is correct
21 Correct 133 ms 29164 KB Output is correct
22 Correct 98 ms 24428 KB Output is correct
23 Correct 74 ms 22508 KB Output is correct
24 Correct 70 ms 20972 KB Output is correct
25 Correct 83 ms 25492 KB Output is correct
26 Correct 88 ms 24044 KB Output is correct
27 Correct 109 ms 24940 KB Output is correct
28 Correct 91 ms 24940 KB Output is correct
29 Correct 117 ms 26860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 14572 KB Output is correct
2 Correct 12 ms 14700 KB Output is correct
3 Correct 12 ms 14828 KB Output is correct
4 Correct 14 ms 14828 KB Output is correct
5 Correct 12 ms 14828 KB Output is correct
6 Correct 12 ms 14828 KB Output is correct
7 Correct 14 ms 14828 KB Output is correct
8 Correct 12 ms 14828 KB Output is correct
9 Correct 12 ms 14828 KB Output is correct
10 Correct 11 ms 14572 KB Output is correct
11 Correct 12 ms 14700 KB Output is correct
12 Correct 14 ms 14700 KB Output is correct
13 Correct 12 ms 14700 KB Output is correct
14 Correct 39 ms 18028 KB Output is correct
15 Correct 61 ms 21616 KB Output is correct
16 Correct 96 ms 25196 KB Output is correct
17 Correct 133 ms 28780 KB Output is correct
18 Correct 135 ms 28780 KB Output is correct
19 Correct 134 ms 28780 KB Output is correct
20 Correct 135 ms 28908 KB Output is correct
21 Correct 133 ms 29164 KB Output is correct
22 Correct 98 ms 24428 KB Output is correct
23 Correct 74 ms 22508 KB Output is correct
24 Correct 70 ms 20972 KB Output is correct
25 Correct 83 ms 25492 KB Output is correct
26 Correct 88 ms 24044 KB Output is correct
27 Correct 109 ms 24940 KB Output is correct
28 Correct 91 ms 24940 KB Output is correct
29 Correct 117 ms 26860 KB Output is correct
30 Correct 290 ms 40120 KB Output is correct
31 Correct 382 ms 49636 KB Output is correct
32 Correct 535 ms 61796 KB Output is correct
33 Correct 916 ms 86068 KB Output is correct
34 Correct 260 ms 37608 KB Output is correct
35 Correct 930 ms 86236 KB Output is correct
36 Correct 942 ms 86104 KB Output is correct
37 Correct 890 ms 85980 KB Output is correct
38 Correct 922 ms 86364 KB Output is correct
39 Correct 892 ms 85940 KB Output is correct
40 Correct 829 ms 87244 KB Output is correct
41 Correct 871 ms 85940 KB Output is correct
42 Correct 892 ms 85596 KB Output is correct
43 Correct 500 ms 85980 KB Output is correct
44 Correct 483 ms 86132 KB Output is correct
45 Correct 473 ms 86372 KB Output is correct
46 Correct 441 ms 55004 KB Output is correct
47 Correct 418 ms 44680 KB Output is correct
48 Correct 597 ms 66396 KB Output is correct
49 Correct 628 ms 66868 KB Output is correct