답안 #926281

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926281 2024-02-12T18:15:55 Z OAleksa Examination (JOI19_examination) C++14
22 / 100
164 ms 15140 KB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int N = 1e5 + 69;
int n, q, a[N], b[N], f[N], ans[N], c[N];
void Modify(int v, int val) {
	for (int i = v;i < N;i += (i & -i))
		f[i] += val;
}
int Get(int v) {
	int res = 0;
	for (int i = v;i > 0;i -= (i & -i))
		res += f[i];
	return res;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
  	cin >> n >> q;
  	for (int i = 1;i <= n;i++) {
  		cin >> a[i] >> b[i];
  		c[i] = a[i] + b[i];
  	}
  	vector<tuple<int, int, int>> t1, t2, t3;
  	for (int i = 1;i <= q;i++) {
  		int x, y, z;
  		cin >> x >> y >> z;
  		if (x + y >= z) 
  			t1.push_back({x, y, i});
  		else {
  			t2.push_back({x, z, i});
  			t3.push_back({z, y, i});
  		}
  	}
  	
  	//x-y
  	//x-z
  	//z-y
  	vector<int> all;
  	for (int i = 1;i <= n;i++)
  		all.push_back(b[i]);
  	for (auto u : t1)
  		all.push_back(get<1>(u));
  	sort(all.begin(), all.end());
  	all.erase(unique(all.begin(), all.end()), all.end());
  	sort(t1.rbegin(), t1.rend());
  	vector<int> ord(n);
  	iota(ord.begin(), ord.end(), 1);
  	sort(ord.begin(), ord.end(), [&](int i, int j) {
  		return a[i] < a[j];
  	});
  	int ptr = n - 1;
  	for (auto u : t1) {
  		int x, y, ind;
  		tie(x, y, ind) = u;
  		while (ptr >= 0 && a[ord[ptr]] >= x) {
  			auto u = lower_bound(all.begin(), all.end(), b[ord[ptr]]) - all.begin() + 1;
  			Modify(u, 1);
  			ptr--;
  		}
  		int p = lower_bound(all.begin(), all.end(), y) - all.begin() + 1;
  		ans[ind] = Get(N - 1) - Get(p - 1);
  	}
  	
  	for (int i = 0;i < N;i++)
  		f[i] = 0;
  	all.clear();
  	for (int i = 1;i <= n;i++)
  		all.push_back(c[i]);
  	for (auto u : t2)
  		all.push_back(get<1>(u));
  	sort(all.begin(), all.end());
  	all.erase(unique(all.begin(), all.end()), all.end());
  	sort(t2.rbegin(), t2.rend());
  	ptr = n - 1;
  	for (auto u : t2) {
  		int x, z, ind;
  		tie(x, z, ind) = u;
  		while (ptr >= 0 && a[ord[ptr]] >= x) {
  			auto u = lower_bound(all.begin(), all.end(), c[ord[ptr]]) - all.begin() + 1;
  			Modify(u, 1);
  			ptr--;
  		}
  		int p = lower_bound(all.begin(), all.end(), z) - all.begin() + 1;
  		ans[ind] += Get(N - 1) - Get(p - 1);
  	}
  	
  	for (int i = 0;i < N;i++)
  		f[i] = 0;
  	all.clear();
  	for (int i = 1;i <= n;i++)
  		all.push_back(b[i]);
  	for (auto u : t3)
  		all.push_back(get<1>(u));
  	sort(all.begin(), all.end());
  	all.erase(unique(all.begin(), all.end()), all.end());
  	sort(t3.rbegin(), t3.rend());
  	sort(ord.begin(), ord.end(), [&](int i, int j) {
  		return c[i] < c[j];
  	});
  	ptr = n - 1;
  	for (auto u : t3) {
  		int y, z, ind;
  		tie(z, y, ind) = u;
  		while (ptr >= 0 && c[ord[ptr]] >= z) {
  			auto u = lower_bound(all.begin(), all.end(), b[ord[ptr]]) - all.begin() + 1;
  			Modify(u, 1);
  			ptr--;
  		}
  		int p = lower_bound(all.begin(), all.end(), y) - all.begin() + 1;
			ans[ind] -= Get(p - 1);
  	}
  	for (int i = 1;i <= q;i++)
  		cout << ans[i] << '\n';
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2436 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 4 ms 1548 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 4 ms 1372 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 4 ms 2904 KB Output is correct
12 Correct 3 ms 2908 KB Output is correct
13 Correct 4 ms 1372 KB Output is correct
14 Correct 4 ms 1372 KB Output is correct
15 Correct 3 ms 1372 KB Output is correct
16 Correct 3 ms 1536 KB Output is correct
17 Correct 4 ms 2908 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 10848 KB Output is correct
2 Correct 123 ms 10856 KB Output is correct
3 Correct 117 ms 11452 KB Output is correct
4 Correct 73 ms 10884 KB Output is correct
5 Correct 116 ms 10688 KB Output is correct
6 Correct 58 ms 10840 KB Output is correct
7 Correct 121 ms 10760 KB Output is correct
8 Correct 106 ms 10848 KB Output is correct
9 Correct 108 ms 11112 KB Output is correct
10 Correct 99 ms 10624 KB Output is correct
11 Correct 85 ms 10944 KB Output is correct
12 Correct 47 ms 10948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 10848 KB Output is correct
2 Correct 123 ms 10856 KB Output is correct
3 Correct 117 ms 11452 KB Output is correct
4 Correct 73 ms 10884 KB Output is correct
5 Correct 116 ms 10688 KB Output is correct
6 Correct 58 ms 10840 KB Output is correct
7 Correct 121 ms 10760 KB Output is correct
8 Correct 106 ms 10848 KB Output is correct
9 Correct 108 ms 11112 KB Output is correct
10 Correct 99 ms 10624 KB Output is correct
11 Correct 85 ms 10944 KB Output is correct
12 Correct 47 ms 10948 KB Output is correct
13 Correct 161 ms 10864 KB Output is correct
14 Correct 164 ms 11824 KB Output is correct
15 Correct 114 ms 11232 KB Output is correct
16 Correct 103 ms 10860 KB Output is correct
17 Correct 135 ms 10644 KB Output is correct
18 Correct 67 ms 11520 KB Output is correct
19 Correct 161 ms 10608 KB Output is correct
20 Correct 154 ms 10480 KB Output is correct
21 Incorrect 163 ms 15140 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2436 KB Output is correct
5 Correct 1 ms 1116 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 4 ms 1548 KB Output is correct
8 Correct 4 ms 1372 KB Output is correct
9 Correct 4 ms 1372 KB Output is correct
10 Correct 3 ms 1372 KB Output is correct
11 Correct 4 ms 2904 KB Output is correct
12 Correct 3 ms 2908 KB Output is correct
13 Correct 4 ms 1372 KB Output is correct
14 Correct 4 ms 1372 KB Output is correct
15 Correct 3 ms 1372 KB Output is correct
16 Correct 3 ms 1536 KB Output is correct
17 Correct 4 ms 2908 KB Output is correct
18 Correct 2 ms 1372 KB Output is correct
19 Correct 120 ms 10848 KB Output is correct
20 Correct 123 ms 10856 KB Output is correct
21 Correct 117 ms 11452 KB Output is correct
22 Correct 73 ms 10884 KB Output is correct
23 Correct 116 ms 10688 KB Output is correct
24 Correct 58 ms 10840 KB Output is correct
25 Correct 121 ms 10760 KB Output is correct
26 Correct 106 ms 10848 KB Output is correct
27 Correct 108 ms 11112 KB Output is correct
28 Correct 99 ms 10624 KB Output is correct
29 Correct 85 ms 10944 KB Output is correct
30 Correct 47 ms 10948 KB Output is correct
31 Correct 161 ms 10864 KB Output is correct
32 Correct 164 ms 11824 KB Output is correct
33 Correct 114 ms 11232 KB Output is correct
34 Correct 103 ms 10860 KB Output is correct
35 Correct 135 ms 10644 KB Output is correct
36 Correct 67 ms 11520 KB Output is correct
37 Correct 161 ms 10608 KB Output is correct
38 Correct 154 ms 10480 KB Output is correct
39 Incorrect 163 ms 15140 KB Output isn't correct
40 Halted 0 ms 0 KB -