답안 #429586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
429586 2021-06-16T07:19:14 Z Return_0 Examination (JOI19_examination) C++17
100 / 100
246 ms 5856 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 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 = 1e5 + 7;

struct fenwick {
	ll fen [N];
	fenwick () { memset(fen, 0, sizeof fen); }
	inline void add (ll i) { for (; i < N; i += i & -i) ++fen[i]; }
	inline ll ask (ll i) { ll t = 0; for (; i; i -= i & -i) t += fen[i]; return t; }
} fen [2];

ll A [N], B [N], X [N], Y [N], Z [N], id1 [N], id2 [N], ans [N], n, q;
vector <ll> vec [2];
inline ll Getx (cl &x) { return lower_bound(All(vec[0]), x) - vec[0].begin() + 1; }
inline ll Gety (cl &y) { return lower_bound(All(vec[1]), y) - vec[1].begin() + 1; }

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], id1[i] = i, vec[0].push_back(A[i]), vec[1].push_back(B[i]);
	for (ll i = 1; i <= q; i++) cin>> X[i] >> Y[i] >> Z[i], Z[i] = max(Z[i], X[i] + Y[i]), id2[i] = i;

	sort(id1 + 1, id1 + n + 1, [&](cl &x, cl &y) { return A[x] + B[x] > A[y] + B[y]; });
	sort(id2 + 1, id2 + q + 1, [&](cl &x, cl &y) { return Z[x] > Z[y]; });
	sort(All(vec[0])); vec[0].resize(unique(All(vec[0])) - vec[0].begin());
	sort(All(vec[1])); vec[1].resize(unique(All(vec[1])) - vec[1].begin());

	for (ll i = 1, j, ptr = 1; i <= q; i++) {
		j = id2[i];
		for (; ptr <= n && A[id1[ptr]] + B[id1[ptr]] >= Z[j]; ptr++) fen[0].add(Getx(A[id1[ptr]])), fen[1].add(Gety(B[id1[ptr]]));
		ans[j] = ptr - fen[0].ask(Getx(X[j]) - 1) - fen[1].ask(Gety(Y[j]) - 1) - 1;
	}

	output(1, q, ans, 0);

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

	return 0;
}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100

10 10
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009
43754 45346 3158
25224 58881 18727
7298 24412 63782
24107 10583 61508
65025 29140 7278
36104 56758 2775
23126 67608 122051
56910 17272 62933
39675 15874 117117

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 2 ms 1100 KB Output is correct
7 Correct 5 ms 1228 KB Output is correct
8 Correct 5 ms 1228 KB Output is correct
9 Correct 5 ms 1228 KB Output is correct
10 Correct 4 ms 1228 KB Output is correct
11 Correct 4 ms 1228 KB Output is correct
12 Correct 3 ms 1228 KB Output is correct
13 Correct 6 ms 1228 KB Output is correct
14 Correct 7 ms 1228 KB Output is correct
15 Correct 5 ms 1228 KB Output is correct
16 Correct 4 ms 1260 KB Output is correct
17 Correct 4 ms 1228 KB Output is correct
18 Correct 3 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 5760 KB Output is correct
2 Correct 182 ms 5780 KB Output is correct
3 Correct 165 ms 5684 KB Output is correct
4 Correct 129 ms 5836 KB Output is correct
5 Correct 138 ms 5856 KB Output is correct
6 Correct 77 ms 5696 KB Output is correct
7 Correct 166 ms 5728 KB Output is correct
8 Correct 174 ms 5812 KB Output is correct
9 Correct 154 ms 5812 KB Output is correct
10 Correct 135 ms 5628 KB Output is correct
11 Correct 138 ms 5604 KB Output is correct
12 Correct 66 ms 5388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 5760 KB Output is correct
2 Correct 182 ms 5780 KB Output is correct
3 Correct 165 ms 5684 KB Output is correct
4 Correct 129 ms 5836 KB Output is correct
5 Correct 138 ms 5856 KB Output is correct
6 Correct 77 ms 5696 KB Output is correct
7 Correct 166 ms 5728 KB Output is correct
8 Correct 174 ms 5812 KB Output is correct
9 Correct 154 ms 5812 KB Output is correct
10 Correct 135 ms 5628 KB Output is correct
11 Correct 138 ms 5604 KB Output is correct
12 Correct 66 ms 5388 KB Output is correct
13 Correct 201 ms 5684 KB Output is correct
14 Correct 212 ms 5816 KB Output is correct
15 Correct 220 ms 5728 KB Output is correct
16 Correct 127 ms 5752 KB Output is correct
17 Correct 143 ms 5752 KB Output is correct
18 Correct 88 ms 5764 KB Output is correct
19 Correct 185 ms 5732 KB Output is correct
20 Correct 181 ms 5776 KB Output is correct
21 Correct 194 ms 5804 KB Output is correct
22 Correct 112 ms 5612 KB Output is correct
23 Correct 133 ms 5596 KB Output is correct
24 Correct 63 ms 5340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 2 ms 1100 KB Output is correct
7 Correct 5 ms 1228 KB Output is correct
8 Correct 5 ms 1228 KB Output is correct
9 Correct 5 ms 1228 KB Output is correct
10 Correct 4 ms 1228 KB Output is correct
11 Correct 4 ms 1228 KB Output is correct
12 Correct 3 ms 1228 KB Output is correct
13 Correct 6 ms 1228 KB Output is correct
14 Correct 7 ms 1228 KB Output is correct
15 Correct 5 ms 1228 KB Output is correct
16 Correct 4 ms 1260 KB Output is correct
17 Correct 4 ms 1228 KB Output is correct
18 Correct 3 ms 1228 KB Output is correct
19 Correct 172 ms 5760 KB Output is correct
20 Correct 182 ms 5780 KB Output is correct
21 Correct 165 ms 5684 KB Output is correct
22 Correct 129 ms 5836 KB Output is correct
23 Correct 138 ms 5856 KB Output is correct
24 Correct 77 ms 5696 KB Output is correct
25 Correct 166 ms 5728 KB Output is correct
26 Correct 174 ms 5812 KB Output is correct
27 Correct 154 ms 5812 KB Output is correct
28 Correct 135 ms 5628 KB Output is correct
29 Correct 138 ms 5604 KB Output is correct
30 Correct 66 ms 5388 KB Output is correct
31 Correct 201 ms 5684 KB Output is correct
32 Correct 212 ms 5816 KB Output is correct
33 Correct 220 ms 5728 KB Output is correct
34 Correct 127 ms 5752 KB Output is correct
35 Correct 143 ms 5752 KB Output is correct
36 Correct 88 ms 5764 KB Output is correct
37 Correct 185 ms 5732 KB Output is correct
38 Correct 181 ms 5776 KB Output is correct
39 Correct 194 ms 5804 KB Output is correct
40 Correct 112 ms 5612 KB Output is correct
41 Correct 133 ms 5596 KB Output is correct
42 Correct 63 ms 5340 KB Output is correct
43 Correct 238 ms 5740 KB Output is correct
44 Correct 219 ms 5736 KB Output is correct
45 Correct 246 ms 5756 KB Output is correct
46 Correct 149 ms 5736 KB Output is correct
47 Correct 139 ms 5688 KB Output is correct
48 Correct 84 ms 5552 KB Output is correct
49 Correct 206 ms 5736 KB Output is correct
50 Correct 196 ms 5688 KB Output is correct
51 Correct 185 ms 5800 KB Output is correct
52 Correct 146 ms 5612 KB Output is correct
53 Correct 122 ms 5600 KB Output is correct