Submission #998239

# Submission time Handle Problem Language Result Execution time Memory
998239 2024-06-13T12:23:42 Z cowwycow Examination (JOI19_examination) C++14
100 / 100
865 ms 53400 KB
#include <bits/stdc++.h>
using namespace std;
#define name "aaaaaa"
using ll = long long;

void file(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	if(fopen(name".inp", "r")) {
		freopen(name".inp", "r", stdin);
		freopen(name".out", "w", stdout);
	}
}

struct node {
  int x, y, z, i, val;
};

const int maxn = 1e6 + 5;

struct BIT {
	int b[maxn], n;

	void build(int _n) {
		n = _n;
		fill(b, b + n + 1, 0);
	}
	int lowbit(int x){
		return x & (-x);
	}
	void update(int x, int v){
		for(int i = x; i <= n; i += lowbit(i)){
			b[i] += v;
		}
	}
	int query(int x) {
		int ans = 0;
		for(int i = x; i > 0; i -= lowbit(i)){
			ans += b[i];
		}
		return ans;
	}
} bit;

vector<node> v;
int n, q, ans[maxn];

void cdq(int l, int r) {
	if(l == r) return;
	int m = (l + r) / 2;
	cdq(l, m); cdq(m + 1, r);

	int a = l, b = m + 1, sum = 0;
	vector<pair<int, int>> record;
	vector<node> tmp;
	while(a <= m && b <= r){
		if(v[a].y >= v[b].y){
			int add = v[a].val;
			bit.update(v[a].z, add), sum += add, record.push_back({v[a].z, add}), tmp.push_back(v[a]);
			a++;
		}else{
			ans[v[b].i] += sum - bit.query(v[b].z - 1), tmp.push_back(v[b]);
			b++;
		}
	}
	while(a <= m){
		tmp.push_back(v[a]);
		a++;
	}
	while(b <= r){
		ans[v[b].i] += sum - bit.query(v[b].z - 1), tmp.push_back(v[b]);
		b++;
	}
	for(int i = l; i <= r; i++){
		v[i] = tmp[i - l];
	}
	for(auto i : record) bit.update(i.first, -i.second);
}	

bool comp(node a, node b){
	if(a.x == b.x){
		return a.val > b.val;
	}
	return (a.x == b.x ? (a.y == b.y ? a.z < b.z : a.y < b.y) : a.x > b.x);
}

map<int, int> mp;

void solve() {
	cin >> n >> q;
	for(int i = 0; i < n; i++){
		int a, b, c;
		cin >> a >> b;
		c = a + b;
		mp[a] = true;
		mp[b] = true;
		mp[c] = true;
		v.push_back({a, b, c, i, 1});
	}
	for(int i = n; i < n + q; i++){
		int x, y, z;
		cin >> x >> y >> z;
		mp[x] = true;
		mp[y] = true;
		mp[z] = true;
		v.push_back({x, y, z, i, 0});
	}
	int id = 1;
	for(auto i : mp){
		mp[i.first] = id;
		id++;
	}
	for(int i = 0; i < v.size(); i++){
		v[i].x = mp[v[i].x];
		v[i].y = mp[v[i].y];
		v[i].z = mp[v[i].z];
	}
	bit.build(id);
	sort(v.begin(), v.end(), comp);
	cdq(0, n + q - 1);
	for(int i = n; i < n + q; i++) cout << ans[i] << '\n';
}

int main() {
	file();
	solve();
}

Compilation message

examination.cpp: In function 'void solve()':
examination.cpp:112:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
examination.cpp: In function 'void file()':
examination.cpp:9:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   freopen(name".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:10:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |   freopen(name".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 12 ms 3728 KB Output is correct
8 Correct 11 ms 3648 KB Output is correct
9 Correct 11 ms 3664 KB Output is correct
10 Correct 9 ms 3372 KB Output is correct
11 Correct 9 ms 3388 KB Output is correct
12 Correct 4 ms 2848 KB Output is correct
13 Correct 13 ms 3536 KB Output is correct
14 Correct 10 ms 3532 KB Output is correct
15 Correct 11 ms 3592 KB Output is correct
16 Correct 7 ms 3132 KB Output is correct
17 Correct 8 ms 3292 KB Output is correct
18 Correct 3 ms 2844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 471 ms 27880 KB Output is correct
2 Correct 472 ms 28520 KB Output is correct
3 Correct 466 ms 29216 KB Output is correct
4 Correct 327 ms 26984 KB Output is correct
5 Correct 324 ms 26432 KB Output is correct
6 Correct 127 ms 19736 KB Output is correct
7 Correct 419 ms 29316 KB Output is correct
8 Correct 424 ms 28764 KB Output is correct
9 Correct 420 ms 29324 KB Output is correct
10 Correct 306 ms 24216 KB Output is correct
11 Correct 289 ms 24424 KB Output is correct
12 Correct 115 ms 19680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 471 ms 27880 KB Output is correct
2 Correct 472 ms 28520 KB Output is correct
3 Correct 466 ms 29216 KB Output is correct
4 Correct 327 ms 26984 KB Output is correct
5 Correct 324 ms 26432 KB Output is correct
6 Correct 127 ms 19736 KB Output is correct
7 Correct 419 ms 29316 KB Output is correct
8 Correct 424 ms 28764 KB Output is correct
9 Correct 420 ms 29324 KB Output is correct
10 Correct 306 ms 24216 KB Output is correct
11 Correct 289 ms 24424 KB Output is correct
12 Correct 115 ms 19680 KB Output is correct
13 Correct 485 ms 30364 KB Output is correct
14 Correct 518 ms 29380 KB Output is correct
15 Correct 483 ms 28936 KB Output is correct
16 Correct 375 ms 26972 KB Output is correct
17 Correct 354 ms 26852 KB Output is correct
18 Correct 144 ms 18992 KB Output is correct
19 Correct 496 ms 30444 KB Output is correct
20 Correct 482 ms 30568 KB Output is correct
21 Correct 485 ms 30764 KB Output is correct
22 Correct 293 ms 24344 KB Output is correct
23 Correct 297 ms 24372 KB Output is correct
24 Correct 103 ms 20288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 12 ms 3728 KB Output is correct
8 Correct 11 ms 3648 KB Output is correct
9 Correct 11 ms 3664 KB Output is correct
10 Correct 9 ms 3372 KB Output is correct
11 Correct 9 ms 3388 KB Output is correct
12 Correct 4 ms 2848 KB Output is correct
13 Correct 13 ms 3536 KB Output is correct
14 Correct 10 ms 3532 KB Output is correct
15 Correct 11 ms 3592 KB Output is correct
16 Correct 7 ms 3132 KB Output is correct
17 Correct 8 ms 3292 KB Output is correct
18 Correct 3 ms 2844 KB Output is correct
19 Correct 471 ms 27880 KB Output is correct
20 Correct 472 ms 28520 KB Output is correct
21 Correct 466 ms 29216 KB Output is correct
22 Correct 327 ms 26984 KB Output is correct
23 Correct 324 ms 26432 KB Output is correct
24 Correct 127 ms 19736 KB Output is correct
25 Correct 419 ms 29316 KB Output is correct
26 Correct 424 ms 28764 KB Output is correct
27 Correct 420 ms 29324 KB Output is correct
28 Correct 306 ms 24216 KB Output is correct
29 Correct 289 ms 24424 KB Output is correct
30 Correct 115 ms 19680 KB Output is correct
31 Correct 485 ms 30364 KB Output is correct
32 Correct 518 ms 29380 KB Output is correct
33 Correct 483 ms 28936 KB Output is correct
34 Correct 375 ms 26972 KB Output is correct
35 Correct 354 ms 26852 KB Output is correct
36 Correct 144 ms 18992 KB Output is correct
37 Correct 496 ms 30444 KB Output is correct
38 Correct 482 ms 30568 KB Output is correct
39 Correct 485 ms 30764 KB Output is correct
40 Correct 293 ms 24344 KB Output is correct
41 Correct 297 ms 24372 KB Output is correct
42 Correct 103 ms 20288 KB Output is correct
43 Correct 865 ms 53400 KB Output is correct
44 Correct 833 ms 52364 KB Output is correct
45 Correct 824 ms 52612 KB Output is correct
46 Correct 527 ms 41892 KB Output is correct
47 Correct 529 ms 42188 KB Output is correct
48 Correct 146 ms 19496 KB Output is correct
49 Correct 825 ms 52616 KB Output is correct
50 Correct 815 ms 52404 KB Output is correct
51 Correct 773 ms 52472 KB Output is correct
52 Correct 448 ms 37076 KB Output is correct
53 Correct 358 ms 32044 KB Output is correct