답안 #758575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758575 2023-06-14T23:10:07 Z scanhex Segments (IZhO18_segments) C++17
75 / 100
5000 ms 35552 KB
#include <bits/stdc++.h>

using namespace std;
using nagai = long long;

struct dss {
	vector<pair<int,int>> segs;
	void insert(int l, int r) {
		segs.push_back({l, r});
	}
	int get(int l, int r, int k) {
		if (k == 0) return segs.size();
		int res = 0;
		for (auto& x : segs) {
			int ll = max(x.first, l), rr = min(x.second, r); 
			if (rr - ll + 1 >= k)
				++res;
		}
		return res;
	}
};

const int oo = 0x3f3f3f3f;
 
struct static1d {
	vector<int> coords;
	void clear() {
		coords.clear();
	}

	void add(int c) {
		coords.push_back(c);
	}

	void finalize() {
		sort(coords.begin(), coords.end());
	}

	int get(int l, int r) {
		if (l > r) return 0;
		auto itr = upper_bound(coords.begin(), coords.end(), r);
		auto itl = lower_bound(coords.begin(), coords.end(), l);
		//cerr << "coords\n";
		//for(auto& x : coords) 
			//cerr << x << ' ';
		//cerr << '\n';
		//cerr << l << ' ' << r << ' ' << itr - itl << '\n';
		return itr - itl;
	}
};

struct static2d {
	vector<static1d> v;
	vector<int> xs;

	void add(int x, int y) {
		for (++x; x < v.size(); x = (x | x - 1) + 1)
			v[x].add(y);
	}

	void build(vector<pair<int,int>> pts) {
		xs.clear();
		for (auto& x : v) 
			x.clear();
		for (auto& p : pts) 
			xs.push_back(p.first);
		sort(xs.begin(), xs.end());
		xs.erase(unique(xs.begin(), xs.end()), xs.end());
		v.resize(xs.size() + 1);
		for (auto p : pts) {
			add(lower_bound(xs.begin(), xs.end(), p.first) - xs.begin(), p.second);
		}
		for (int i = 0; i < v.size(); ++i) 
			v[i].finalize();
	}

	int get(int xr, int y1, int y2) {
		++xr;
		int xrr = xr;
		xr = lower_bound(xs.begin(), xs.end(), xr) - xs.begin();
		int res = 0;
		for (; xr; xr &= xr - 1) 
			res += v[xr].get(y1, y2);
		//cerr << xrr << ' ' << y1 << ' ' << y2 << ' ' << res << '\n';
		return res;
	}

	// all inclusive
	int get(int x1, int x2, int y1, int y2) {
		if (x1 > x2) return 0;
		return get(x2, y1, y2) - get(x1 - 1, y1, y2);
	}
};

const int BL = 2000;

struct rofl2d {
	vector<pair<int,int>> all;
	vector<pair<int,int>> block;
	static2d st;
	
	void insert(int x, int y) {
		block.push_back({x, y});
		if (block.size() >= BL) {
			 for (auto& x : block)
				 all.push_back(x);
			 block.clear();
			 st.build(all);
		}
	}

	int get(int x1, int x2, int y1, int y2) {
		int res = st.get(x1, x2, y1, y2);
		for (auto p : block) 
			if (x1 <= p.first && p.first <= x2 && y1 <= p.second && p.second <= y2) 
				++res;
		return res;
	}
};


struct ds {
	int tot = 0;
	rofl2d rofl_l, rofl_r;
	void insert(int l, int r) {
		++tot;
		rofl_l.insert(l, r - l);
		rofl_r.insert(r, r - l);
	}
	int get(int l, int r, int k) {
		if (r - l + 1 < k) return 0;
		if (k == 0) return tot;
		int res = tot;
		//cerr << "rofl_l" << '\n';
		res -= rofl_l.get(r - k + 2, oo, k - 1, oo);
		//cerr << "rofl_r" << '\n';
		res -= rofl_r.get(0, l + k - 2, k - 1, oo);
		//cerr << "rofl_l" << '\n';
		res -= rofl_l.get(0, oo, 0, k - 2);
		return res;
	}
};

void stress() {
	int C = 5;
	for (int i = 0; i < 10000; ++i) {
		ds smart;
		dss stupid;
		stringstream ss;
		for (int i = 0; i < 10; ++i) {
			int x = rand() % C, y = rand() % C;
			if (x > y) swap(x, y);
			ss << "1 " << x << ' ' << y << '\n';
			smart.insert(x, y);
			stupid.insert(x, y);

			int a = rand() % C, b = rand() % C, k = rand() % C;
			if (a > b) swap(a, b);
			if (smart.get(a, b, k) != stupid.get(a, b, k)) {
				ss << smart.get(a, b, k) << ' ' << stupid.get(a, b, k) << '\n';
				ss << "3 " << a << ' ' << b << ' ' << k << '\n';
				cerr << ss.str();
				exit(1);
			}
		}
	}
	exit(0);
}


int main() {
	//stress();
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, t; 
	cin >> n >> t; 
	int lastans = 0;
	vector<pair<int, int>> segs;
	ds add, del;
	while (n--) {
		int tt;
		cin >> tt; 
		if (tt == 1) {
			int a, b;
			cin >> a >> b; 
			a ^= t * lastans;
			b ^= t * lastans;
			if (a > b) swap(a, b);
			segs.push_back({a, b});
			add.insert(a, b);
		}
		else if (tt == 2) {
			int id; 
			cin >> id; 
			--id;
			del.insert(segs[id].first, segs[id].second);
		}
		else {
			int a, b, k;
			cin >> a >> b >> k;
			a ^= t * lastans;
			b ^= t * lastans;
			if (a > b) swap(a, b);
			lastans = add.get(a, b, k) - del.get(a, b, k);
			cout << lastans << '\n';
		}
	}
}

Compilation message

segments.cpp: In member function 'void static2d::add(int, int)':
segments.cpp:57:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<static1d>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for (++x; x < v.size(); x = (x | x - 1) + 1)
      |             ~~^~~~~~~~~~
segments.cpp:57:38: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   57 |   for (++x; x < v.size(); x = (x | x - 1) + 1)
      |                                    ~~^~~
segments.cpp: In member function 'void static2d::build(std::vector<std::pair<int, int> >)':
segments.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<static1d>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for (int i = 0; i < v.size(); ++i)
      |                   ~~^~~~~~~~~~
segments.cpp: In member function 'int static2d::get(int, int, int)':
segments.cpp:79:7: warning: unused variable 'xrr' [-Wunused-variable]
   79 |   int xrr = xr;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 24 ms 436 KB Output is correct
4 Correct 26 ms 340 KB Output is correct
5 Correct 9 ms 1108 KB Output is correct
6 Correct 24 ms 724 KB Output is correct
7 Correct 29 ms 764 KB Output is correct
8 Correct 15 ms 724 KB Output is correct
9 Correct 12 ms 844 KB Output is correct
10 Correct 8 ms 1108 KB Output is correct
11 Correct 18 ms 868 KB Output is correct
12 Correct 19 ms 984 KB Output is correct
13 Correct 8 ms 1108 KB Output is correct
14 Correct 14 ms 844 KB Output is correct
15 Correct 25 ms 468 KB Output is correct
16 Correct 25 ms 536 KB Output is correct
17 Correct 25 ms 836 KB Output is correct
18 Correct 12 ms 1108 KB Output is correct
19 Correct 18 ms 852 KB Output is correct
20 Correct 16 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1636 ms 10712 KB Output is correct
2 Correct 1671 ms 10756 KB Output is correct
3 Correct 1644 ms 10812 KB Output is correct
4 Correct 1282 ms 11996 KB Output is correct
5 Correct 2506 ms 20880 KB Output is correct
6 Correct 2671 ms 23788 KB Output is correct
7 Correct 1666 ms 13068 KB Output is correct
8 Correct 1620 ms 13348 KB Output is correct
9 Correct 1647 ms 13456 KB Output is correct
10 Correct 1334 ms 7496 KB Output is correct
11 Correct 1045 ms 8788 KB Output is correct
12 Correct 1465 ms 18936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1020 ms 13016 KB Output is correct
2 Correct 1030 ms 12744 KB Output is correct
3 Correct 1077 ms 12928 KB Output is correct
4 Correct 1029 ms 12920 KB Output is correct
5 Correct 1639 ms 16912 KB Output is correct
6 Correct 1106 ms 13088 KB Output is correct
7 Correct 1515 ms 14348 KB Output is correct
8 Correct 2525 ms 20864 KB Output is correct
9 Correct 2374 ms 21028 KB Output is correct
10 Correct 1780 ms 18420 KB Output is correct
11 Correct 1044 ms 14012 KB Output is correct
12 Correct 1723 ms 18952 KB Output is correct
13 Correct 1583 ms 17564 KB Output is correct
14 Correct 1136 ms 15088 KB Output is correct
15 Correct 1058 ms 14592 KB Output is correct
16 Correct 1091 ms 14548 KB Output is correct
17 Correct 735 ms 11268 KB Output is correct
18 Correct 1395 ms 10560 KB Output is correct
19 Correct 1358 ms 10880 KB Output is correct
20 Correct 756 ms 11196 KB Output is correct
21 Correct 1037 ms 13640 KB Output is correct
22 Correct 1207 ms 16356 KB Output is correct
23 Correct 1453 ms 17108 KB Output is correct
24 Correct 1294 ms 16508 KB Output is correct
25 Correct 1026 ms 12692 KB Output is correct
26 Correct 1022 ms 12852 KB Output is correct
27 Correct 1030 ms 12736 KB Output is correct
28 Correct 1012 ms 12896 KB Output is correct
29 Correct 1545 ms 19088 KB Output is correct
30 Correct 1524 ms 19088 KB Output is correct
31 Correct 2515 ms 20476 KB Output is correct
32 Correct 1804 ms 18760 KB Output is correct
33 Correct 1584 ms 18332 KB Output is correct
34 Correct 1078 ms 14656 KB Output is correct
35 Correct 1329 ms 16240 KB Output is correct
36 Correct 1708 ms 18300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1261 ms 13184 KB Output is correct
2 Correct 1219 ms 12772 KB Output is correct
3 Correct 1239 ms 12700 KB Output is correct
4 Correct 1287 ms 12852 KB Output is correct
5 Correct 1827 ms 17264 KB Output is correct
6 Correct 1537 ms 3252 KB Output is correct
7 Correct 2055 ms 20892 KB Output is correct
8 Correct 733 ms 7548 KB Output is correct
9 Correct 1394 ms 18124 KB Output is correct
10 Correct 1944 ms 21340 KB Output is correct
11 Correct 1272 ms 15924 KB Output is correct
12 Correct 2553 ms 23020 KB Output is correct
13 Correct 1630 ms 19348 KB Output is correct
14 Correct 1221 ms 16832 KB Output is correct
15 Correct 2380 ms 21624 KB Output is correct
16 Correct 1712 ms 20172 KB Output is correct
17 Correct 1565 ms 13504 KB Output is correct
18 Correct 1569 ms 13384 KB Output is correct
19 Correct 1549 ms 13276 KB Output is correct
20 Correct 1529 ms 13596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 24 ms 436 KB Output is correct
4 Correct 26 ms 340 KB Output is correct
5 Correct 9 ms 1108 KB Output is correct
6 Correct 24 ms 724 KB Output is correct
7 Correct 29 ms 764 KB Output is correct
8 Correct 15 ms 724 KB Output is correct
9 Correct 12 ms 844 KB Output is correct
10 Correct 8 ms 1108 KB Output is correct
11 Correct 18 ms 868 KB Output is correct
12 Correct 19 ms 984 KB Output is correct
13 Correct 8 ms 1108 KB Output is correct
14 Correct 14 ms 844 KB Output is correct
15 Correct 25 ms 468 KB Output is correct
16 Correct 25 ms 536 KB Output is correct
17 Correct 25 ms 836 KB Output is correct
18 Correct 12 ms 1108 KB Output is correct
19 Correct 18 ms 852 KB Output is correct
20 Correct 16 ms 844 KB Output is correct
21 Correct 1636 ms 10712 KB Output is correct
22 Correct 1671 ms 10756 KB Output is correct
23 Correct 1644 ms 10812 KB Output is correct
24 Correct 1282 ms 11996 KB Output is correct
25 Correct 2506 ms 20880 KB Output is correct
26 Correct 2671 ms 23788 KB Output is correct
27 Correct 1666 ms 13068 KB Output is correct
28 Correct 1620 ms 13348 KB Output is correct
29 Correct 1647 ms 13456 KB Output is correct
30 Correct 1334 ms 7496 KB Output is correct
31 Correct 1045 ms 8788 KB Output is correct
32 Correct 1465 ms 18936 KB Output is correct
33 Correct 1261 ms 13184 KB Output is correct
34 Correct 1219 ms 12772 KB Output is correct
35 Correct 1239 ms 12700 KB Output is correct
36 Correct 1287 ms 12852 KB Output is correct
37 Correct 1827 ms 17264 KB Output is correct
38 Correct 1537 ms 3252 KB Output is correct
39 Correct 2055 ms 20892 KB Output is correct
40 Correct 733 ms 7548 KB Output is correct
41 Correct 1394 ms 18124 KB Output is correct
42 Correct 1944 ms 21340 KB Output is correct
43 Correct 1272 ms 15924 KB Output is correct
44 Correct 2553 ms 23020 KB Output is correct
45 Correct 1630 ms 19348 KB Output is correct
46 Correct 1221 ms 16832 KB Output is correct
47 Correct 2380 ms 21624 KB Output is correct
48 Correct 1712 ms 20172 KB Output is correct
49 Correct 1565 ms 13504 KB Output is correct
50 Correct 1569 ms 13384 KB Output is correct
51 Correct 1549 ms 13276 KB Output is correct
52 Correct 1529 ms 13596 KB Output is correct
53 Correct 1204 ms 14828 KB Output is correct
54 Correct 1181 ms 15000 KB Output is correct
55 Correct 1190 ms 14668 KB Output is correct
56 Correct 1196 ms 14888 KB Output is correct
57 Correct 1522 ms 9660 KB Output is correct
58 Correct 1024 ms 5476 KB Output is correct
59 Correct 1459 ms 15652 KB Output is correct
60 Correct 1300 ms 5308 KB Output is correct
61 Correct 1624 ms 20000 KB Output is correct
62 Correct 2309 ms 22716 KB Output is correct
63 Correct 2447 ms 23344 KB Output is correct
64 Correct 2288 ms 22484 KB Output is correct
65 Correct 1146 ms 16092 KB Output is correct
66 Correct 1178 ms 16096 KB Output is correct
67 Correct 1703 ms 19980 KB Output is correct
68 Correct 1469 ms 17904 KB Output is correct
69 Correct 1629 ms 13324 KB Output is correct
70 Correct 1586 ms 13120 KB Output is correct
71 Correct 1597 ms 13628 KB Output is correct
72 Correct 1564 ms 13248 KB Output is correct
73 Correct 1270 ms 16720 KB Output is correct
74 Correct 1489 ms 18272 KB Output is correct
75 Correct 2589 ms 23868 KB Output is correct
76 Correct 2437 ms 23180 KB Output is correct
77 Correct 1189 ms 15056 KB Output is correct
78 Correct 1204 ms 15092 KB Output is correct
79 Correct 1193 ms 14840 KB Output is correct
80 Correct 1168 ms 14636 KB Output is correct
81 Correct 1449 ms 19040 KB Output is correct
82 Correct 1282 ms 17036 KB Output is correct
83 Correct 1203 ms 16380 KB Output is correct
84 Correct 1448 ms 18992 KB Output is correct
85 Correct 1683 ms 20100 KB Output is correct
86 Correct 1761 ms 20540 KB Output is correct
87 Correct 1282 ms 17688 KB Output is correct
88 Correct 1132 ms 15636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 24 ms 436 KB Output is correct
4 Correct 26 ms 340 KB Output is correct
5 Correct 9 ms 1108 KB Output is correct
6 Correct 24 ms 724 KB Output is correct
7 Correct 29 ms 764 KB Output is correct
8 Correct 15 ms 724 KB Output is correct
9 Correct 12 ms 844 KB Output is correct
10 Correct 8 ms 1108 KB Output is correct
11 Correct 18 ms 868 KB Output is correct
12 Correct 19 ms 984 KB Output is correct
13 Correct 8 ms 1108 KB Output is correct
14 Correct 14 ms 844 KB Output is correct
15 Correct 25 ms 468 KB Output is correct
16 Correct 25 ms 536 KB Output is correct
17 Correct 25 ms 836 KB Output is correct
18 Correct 12 ms 1108 KB Output is correct
19 Correct 18 ms 852 KB Output is correct
20 Correct 16 ms 844 KB Output is correct
21 Correct 1636 ms 10712 KB Output is correct
22 Correct 1671 ms 10756 KB Output is correct
23 Correct 1644 ms 10812 KB Output is correct
24 Correct 1282 ms 11996 KB Output is correct
25 Correct 2506 ms 20880 KB Output is correct
26 Correct 2671 ms 23788 KB Output is correct
27 Correct 1666 ms 13068 KB Output is correct
28 Correct 1620 ms 13348 KB Output is correct
29 Correct 1647 ms 13456 KB Output is correct
30 Correct 1334 ms 7496 KB Output is correct
31 Correct 1045 ms 8788 KB Output is correct
32 Correct 1465 ms 18936 KB Output is correct
33 Correct 1020 ms 13016 KB Output is correct
34 Correct 1030 ms 12744 KB Output is correct
35 Correct 1077 ms 12928 KB Output is correct
36 Correct 1029 ms 12920 KB Output is correct
37 Correct 1639 ms 16912 KB Output is correct
38 Correct 1106 ms 13088 KB Output is correct
39 Correct 1515 ms 14348 KB Output is correct
40 Correct 2525 ms 20864 KB Output is correct
41 Correct 2374 ms 21028 KB Output is correct
42 Correct 1780 ms 18420 KB Output is correct
43 Correct 1044 ms 14012 KB Output is correct
44 Correct 1723 ms 18952 KB Output is correct
45 Correct 1583 ms 17564 KB Output is correct
46 Correct 1136 ms 15088 KB Output is correct
47 Correct 1058 ms 14592 KB Output is correct
48 Correct 1091 ms 14548 KB Output is correct
49 Correct 735 ms 11268 KB Output is correct
50 Correct 1395 ms 10560 KB Output is correct
51 Correct 1358 ms 10880 KB Output is correct
52 Correct 756 ms 11196 KB Output is correct
53 Correct 1037 ms 13640 KB Output is correct
54 Correct 1207 ms 16356 KB Output is correct
55 Correct 1453 ms 17108 KB Output is correct
56 Correct 1294 ms 16508 KB Output is correct
57 Correct 1026 ms 12692 KB Output is correct
58 Correct 1022 ms 12852 KB Output is correct
59 Correct 1030 ms 12736 KB Output is correct
60 Correct 1012 ms 12896 KB Output is correct
61 Correct 1545 ms 19088 KB Output is correct
62 Correct 1524 ms 19088 KB Output is correct
63 Correct 2515 ms 20476 KB Output is correct
64 Correct 1804 ms 18760 KB Output is correct
65 Correct 1584 ms 18332 KB Output is correct
66 Correct 1078 ms 14656 KB Output is correct
67 Correct 1329 ms 16240 KB Output is correct
68 Correct 1708 ms 18300 KB Output is correct
69 Correct 1261 ms 13184 KB Output is correct
70 Correct 1219 ms 12772 KB Output is correct
71 Correct 1239 ms 12700 KB Output is correct
72 Correct 1287 ms 12852 KB Output is correct
73 Correct 1827 ms 17264 KB Output is correct
74 Correct 1537 ms 3252 KB Output is correct
75 Correct 2055 ms 20892 KB Output is correct
76 Correct 733 ms 7548 KB Output is correct
77 Correct 1394 ms 18124 KB Output is correct
78 Correct 1944 ms 21340 KB Output is correct
79 Correct 1272 ms 15924 KB Output is correct
80 Correct 2553 ms 23020 KB Output is correct
81 Correct 1630 ms 19348 KB Output is correct
82 Correct 1221 ms 16832 KB Output is correct
83 Correct 2380 ms 21624 KB Output is correct
84 Correct 1712 ms 20172 KB Output is correct
85 Correct 1565 ms 13504 KB Output is correct
86 Correct 1569 ms 13384 KB Output is correct
87 Correct 1549 ms 13276 KB Output is correct
88 Correct 1529 ms 13596 KB Output is correct
89 Correct 1204 ms 14828 KB Output is correct
90 Correct 1181 ms 15000 KB Output is correct
91 Correct 1190 ms 14668 KB Output is correct
92 Correct 1196 ms 14888 KB Output is correct
93 Correct 1522 ms 9660 KB Output is correct
94 Correct 1024 ms 5476 KB Output is correct
95 Correct 1459 ms 15652 KB Output is correct
96 Correct 1300 ms 5308 KB Output is correct
97 Correct 1624 ms 20000 KB Output is correct
98 Correct 2309 ms 22716 KB Output is correct
99 Correct 2447 ms 23344 KB Output is correct
100 Correct 2288 ms 22484 KB Output is correct
101 Correct 1146 ms 16092 KB Output is correct
102 Correct 1178 ms 16096 KB Output is correct
103 Correct 1703 ms 19980 KB Output is correct
104 Correct 1469 ms 17904 KB Output is correct
105 Correct 1629 ms 13324 KB Output is correct
106 Correct 1586 ms 13120 KB Output is correct
107 Correct 1597 ms 13628 KB Output is correct
108 Correct 1564 ms 13248 KB Output is correct
109 Correct 1270 ms 16720 KB Output is correct
110 Correct 1489 ms 18272 KB Output is correct
111 Correct 2589 ms 23868 KB Output is correct
112 Correct 2437 ms 23180 KB Output is correct
113 Correct 1189 ms 15056 KB Output is correct
114 Correct 1204 ms 15092 KB Output is correct
115 Correct 1193 ms 14840 KB Output is correct
116 Correct 1168 ms 14636 KB Output is correct
117 Correct 1449 ms 19040 KB Output is correct
118 Correct 1282 ms 17036 KB Output is correct
119 Correct 1203 ms 16380 KB Output is correct
120 Correct 1448 ms 18992 KB Output is correct
121 Correct 1683 ms 20100 KB Output is correct
122 Correct 1761 ms 20540 KB Output is correct
123 Correct 1282 ms 17688 KB Output is correct
124 Correct 1132 ms 15636 KB Output is correct
125 Correct 3679 ms 35080 KB Output is correct
126 Correct 3662 ms 35436 KB Output is correct
127 Correct 3685 ms 33680 KB Output is correct
128 Correct 3640 ms 34352 KB Output is correct
129 Correct 3718 ms 34432 KB Output is correct
130 Correct 3714 ms 34412 KB Output is correct
131 Correct 3340 ms 11156 KB Output is correct
132 Correct 4053 ms 25132 KB Output is correct
133 Execution timed out 5040 ms 35552 KB Time limit exceeded
134 Halted 0 ms 0 KB -