답안 #926274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926274 2024-02-12T18:13:08 Z OAleksa Examination (JOI19_examination) C++14
22 / 100
160 ms 9992 KB
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
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 860 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 0 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 4 ms 1112 KB Output is correct
8 Correct 4 ms 1368 KB Output is correct
9 Correct 4 ms 1116 KB Output is correct
10 Correct 3 ms 924 KB Output is correct
11 Correct 4 ms 1116 KB Output is correct
12 Correct 2 ms 992 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 3 ms 1112 KB Output is correct
15 Correct 4 ms 1116 KB Output is correct
16 Correct 3 ms 1112 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 8384 KB Output is correct
2 Correct 110 ms 8404 KB Output is correct
3 Correct 114 ms 8392 KB Output is correct
4 Correct 71 ms 7616 KB Output is correct
5 Correct 96 ms 7620 KB Output is correct
6 Correct 59 ms 6856 KB Output is correct
7 Correct 109 ms 8264 KB Output is correct
8 Correct 107 ms 8132 KB Output is correct
9 Correct 106 ms 8232 KB Output is correct
10 Correct 93 ms 7380 KB Output is correct
11 Correct 62 ms 7384 KB Output is correct
12 Correct 46 ms 6600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 8384 KB Output is correct
2 Correct 110 ms 8404 KB Output is correct
3 Correct 114 ms 8392 KB Output is correct
4 Correct 71 ms 7616 KB Output is correct
5 Correct 96 ms 7620 KB Output is correct
6 Correct 59 ms 6856 KB Output is correct
7 Correct 109 ms 8264 KB Output is correct
8 Correct 107 ms 8132 KB Output is correct
9 Correct 106 ms 8232 KB Output is correct
10 Correct 93 ms 7380 KB Output is correct
11 Correct 62 ms 7384 KB Output is correct
12 Correct 46 ms 6600 KB Output is correct
13 Correct 150 ms 8728 KB Output is correct
14 Correct 138 ms 8836 KB Output is correct
15 Correct 109 ms 8384 KB Output is correct
16 Correct 96 ms 7800 KB Output is correct
17 Correct 132 ms 7872 KB Output is correct
18 Correct 72 ms 7068 KB Output is correct
19 Correct 148 ms 8716 KB Output is correct
20 Correct 145 ms 8584 KB Output is correct
21 Incorrect 160 ms 9992 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 0 ms 860 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 0 ms 860 KB Output is correct
5 Correct 0 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 4 ms 1112 KB Output is correct
8 Correct 4 ms 1368 KB Output is correct
9 Correct 4 ms 1116 KB Output is correct
10 Correct 3 ms 924 KB Output is correct
11 Correct 4 ms 1116 KB Output is correct
12 Correct 2 ms 992 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 3 ms 1112 KB Output is correct
15 Correct 4 ms 1116 KB Output is correct
16 Correct 3 ms 1112 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 2 ms 860 KB Output is correct
19 Correct 116 ms 8384 KB Output is correct
20 Correct 110 ms 8404 KB Output is correct
21 Correct 114 ms 8392 KB Output is correct
22 Correct 71 ms 7616 KB Output is correct
23 Correct 96 ms 7620 KB Output is correct
24 Correct 59 ms 6856 KB Output is correct
25 Correct 109 ms 8264 KB Output is correct
26 Correct 107 ms 8132 KB Output is correct
27 Correct 106 ms 8232 KB Output is correct
28 Correct 93 ms 7380 KB Output is correct
29 Correct 62 ms 7384 KB Output is correct
30 Correct 46 ms 6600 KB Output is correct
31 Correct 150 ms 8728 KB Output is correct
32 Correct 138 ms 8836 KB Output is correct
33 Correct 109 ms 8384 KB Output is correct
34 Correct 96 ms 7800 KB Output is correct
35 Correct 132 ms 7872 KB Output is correct
36 Correct 72 ms 7068 KB Output is correct
37 Correct 148 ms 8716 KB Output is correct
38 Correct 145 ms 8584 KB Output is correct
39 Incorrect 160 ms 9992 KB Output isn't correct
40 Halted 0 ms 0 KB -