답안 #226010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
226010 2020-04-22T09:51:29 Z emil_physmath Segments (IZhO18_segments) C++17
100 / 100
2089 ms 12028 KB
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
struct Inter { int l, r; };
bool operator<(const Inter& a, const Inter& b) { return a.r - a.l < b.r - b.l; }
const int maxN = 200'000;
const int bl = 1450;

struct
{
    vector<int> ls[maxN / bl], rs[maxN / bl];
    vector<Inter> seg;
    vector<Inter> unProc;
    void add(int l, int r)
    {
        unProc.push_back({l, r});
        if (unProc.size() >= bl)
        {
            // Rebuild.
            vector<Inter> temp; temp.reserve(seg.size() + unProc.size());
            sort(unProc.begin(), unProc.end());
            merge(unProc.begin(), unProc.end(), seg.begin(), seg.end(), back_inserter(temp));
            seg.swap(temp);
            unProc.clear();
            for (int i = 0; i * bl < seg.size(); ++i)
            {
                ls[i].clear();
                rs[i].clear();
            }
            for (int i = 0; i < seg.size(); ++i)
            {
                ls[i / bl].push_back(seg[i].l);
                rs[i / bl].push_back(seg[i].r);
            }
            for (int i = 0; i * bl < seg.size(); ++i)
            {
                sort(ls[i].begin(), ls[i].end());
                sort(rs[i].begin(), rs[i].end());
            }
        }
    }
    int solve(int l, int r, int k)
    {
        if (r - l + 1 < k)
            return 0;
        int ans = 0;
        for (int i = 0; i < seg.size(); i += bl)
        {
            int e = min(i + bl - 1, (int)seg.size() - 1);
            if (seg[i].r - seg[i].l + 1 >= k)
            {
                ans += e - i + 1;
                ans -= lower_bound(rs[i / bl].begin(), rs[i / bl].end(), l + k - 1) - rs[i / bl].begin();
                ans -= ls[i / bl].end() - upper_bound(ls[i / bl].begin(), ls[i / bl].end(), r - (k - 1));
            }
            else if (seg[e].r - seg[e].l + 1 >= k)
                for (int j = i; j <= e; ++j)
                    ans += (min(seg[j].r, r) - max(seg[j].l, l) + 1 >= k);
        }
        for (auto p: unProc)
            if (min(r, p.r) - max(l, p.l) + 1 >= k)
                ++ans;
        return ans;
    }
} exist, del;

int main()
{
    int n, t;
    cin >> n >> t;
	int prevans = 0;
    vector<Inter> allSegs;
	while (n--)
	{
		int type, l, r, k, id;
		cin >> type;
		if (type == 1)
		{
			cin >> l >> r;
			l = (l ^ (t * prevans));
			r = (r ^ (t * prevans));
			if (l > r) swap(l, r);
            allSegs.push_back({l, r});
			exist.add(l, r);
		}
		else if (type == 2)
		{
			cin >> id; --id;
            del.add(allSegs[id].l, allSegs[id].r);
		}
		else if (type == 3)
		{
			cin >> l >> r >> k;
			l = (l ^ (t * prevans));
			r = (r ^ (t * prevans));
			if (l > r) swap(l, r);
            cout << (prevans = exist.solve(l, r, k) - del.solve(l, r, k)) << '\n';
#ifdef MANSON
            cout << flush;
#endif
		}
	}
}

Compilation message

segments.cpp: In member function 'void<unnamed struct>::add(int, int)':
segments.cpp:29:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i * bl < seg.size(); ++i)
                             ~~~~~~~^~~~~~~~~~~~
segments.cpp:34:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < seg.size(); ++i)
                             ~~^~~~~~~~~~~~
segments.cpp:39:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i * bl < seg.size(); ++i)
                             ~~~~~~~^~~~~~~~~~~~
segments.cpp: In member function 'int<unnamed struct>::solve(int, int, int)':
segments.cpp:51:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < seg.size(); i += bl)
                         ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 20 ms 384 KB Output is correct
4 Correct 20 ms 512 KB Output is correct
5 Correct 19 ms 512 KB Output is correct
6 Correct 21 ms 512 KB Output is correct
7 Correct 21 ms 512 KB Output is correct
8 Correct 17 ms 384 KB Output is correct
9 Correct 18 ms 512 KB Output is correct
10 Correct 14 ms 544 KB Output is correct
11 Correct 37 ms 384 KB Output is correct
12 Correct 31 ms 604 KB Output is correct
13 Correct 14 ms 512 KB Output is correct
14 Correct 18 ms 384 KB Output is correct
15 Correct 20 ms 384 KB Output is correct
16 Correct 20 ms 504 KB Output is correct
17 Correct 20 ms 384 KB Output is correct
18 Correct 15 ms 512 KB Output is correct
19 Correct 22 ms 384 KB Output is correct
20 Correct 20 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 739 ms 3372 KB Output is correct
2 Correct 741 ms 4152 KB Output is correct
3 Correct 746 ms 4424 KB Output is correct
4 Correct 751 ms 4116 KB Output is correct
5 Correct 575 ms 5620 KB Output is correct
6 Correct 568 ms 5592 KB Output is correct
7 Correct 741 ms 4292 KB Output is correct
8 Correct 732 ms 4272 KB Output is correct
9 Correct 726 ms 4276 KB Output is correct
10 Correct 769 ms 4148 KB Output is correct
11 Correct 821 ms 4460 KB Output is correct
12 Correct 673 ms 4716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 487 ms 3088 KB Output is correct
2 Correct 475 ms 4064 KB Output is correct
3 Correct 483 ms 4012 KB Output is correct
4 Correct 478 ms 3992 KB Output is correct
5 Correct 622 ms 4572 KB Output is correct
6 Correct 672 ms 4392 KB Output is correct
7 Correct 621 ms 4488 KB Output is correct
8 Correct 573 ms 5876 KB Output is correct
9 Correct 548 ms 5832 KB Output is correct
10 Correct 524 ms 5216 KB Output is correct
11 Correct 483 ms 4520 KB Output is correct
12 Correct 541 ms 5448 KB Output is correct
13 Correct 499 ms 5124 KB Output is correct
14 Correct 472 ms 4944 KB Output is correct
15 Correct 468 ms 4488 KB Output is correct
16 Correct 465 ms 4792 KB Output is correct
17 Correct 646 ms 4164 KB Output is correct
18 Correct 652 ms 4164 KB Output is correct
19 Correct 644 ms 4036 KB Output is correct
20 Correct 642 ms 4084 KB Output is correct
21 Correct 489 ms 4272 KB Output is correct
22 Correct 515 ms 4844 KB Output is correct
23 Correct 511 ms 5436 KB Output is correct
24 Correct 509 ms 5296 KB Output is correct
25 Correct 489 ms 4296 KB Output is correct
26 Correct 485 ms 4380 KB Output is correct
27 Correct 482 ms 4376 KB Output is correct
28 Correct 484 ms 4268 KB Output is correct
29 Correct 515 ms 5344 KB Output is correct
30 Correct 520 ms 5272 KB Output is correct
31 Correct 535 ms 5840 KB Output is correct
32 Correct 525 ms 5544 KB Output is correct
33 Correct 504 ms 5596 KB Output is correct
34 Correct 458 ms 4860 KB Output is correct
35 Correct 481 ms 5332 KB Output is correct
36 Correct 486 ms 5176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 633 ms 3100 KB Output is correct
2 Correct 636 ms 4276 KB Output is correct
3 Correct 638 ms 4164 KB Output is correct
4 Correct 626 ms 3992 KB Output is correct
5 Correct 628 ms 4460 KB Output is correct
6 Correct 800 ms 4216 KB Output is correct
7 Correct 628 ms 5180 KB Output is correct
8 Correct 754 ms 4704 KB Output is correct
9 Correct 585 ms 5316 KB Output is correct
10 Correct 562 ms 5688 KB Output is correct
11 Correct 612 ms 5004 KB Output is correct
12 Correct 547 ms 5780 KB Output is correct
13 Correct 566 ms 5504 KB Output is correct
14 Correct 588 ms 5160 KB Output is correct
15 Correct 546 ms 5920 KB Output is correct
16 Correct 567 ms 5440 KB Output is correct
17 Correct 740 ms 4536 KB Output is correct
18 Correct 729 ms 4456 KB Output is correct
19 Correct 731 ms 4676 KB Output is correct
20 Correct 745 ms 4804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 20 ms 384 KB Output is correct
4 Correct 20 ms 512 KB Output is correct
5 Correct 19 ms 512 KB Output is correct
6 Correct 21 ms 512 KB Output is correct
7 Correct 21 ms 512 KB Output is correct
8 Correct 17 ms 384 KB Output is correct
9 Correct 18 ms 512 KB Output is correct
10 Correct 14 ms 544 KB Output is correct
11 Correct 37 ms 384 KB Output is correct
12 Correct 31 ms 604 KB Output is correct
13 Correct 14 ms 512 KB Output is correct
14 Correct 18 ms 384 KB Output is correct
15 Correct 20 ms 384 KB Output is correct
16 Correct 20 ms 504 KB Output is correct
17 Correct 20 ms 384 KB Output is correct
18 Correct 15 ms 512 KB Output is correct
19 Correct 22 ms 384 KB Output is correct
20 Correct 20 ms 512 KB Output is correct
21 Correct 739 ms 3372 KB Output is correct
22 Correct 741 ms 4152 KB Output is correct
23 Correct 746 ms 4424 KB Output is correct
24 Correct 751 ms 4116 KB Output is correct
25 Correct 575 ms 5620 KB Output is correct
26 Correct 568 ms 5592 KB Output is correct
27 Correct 741 ms 4292 KB Output is correct
28 Correct 732 ms 4272 KB Output is correct
29 Correct 726 ms 4276 KB Output is correct
30 Correct 769 ms 4148 KB Output is correct
31 Correct 821 ms 4460 KB Output is correct
32 Correct 673 ms 4716 KB Output is correct
33 Correct 633 ms 3100 KB Output is correct
34 Correct 636 ms 4276 KB Output is correct
35 Correct 638 ms 4164 KB Output is correct
36 Correct 626 ms 3992 KB Output is correct
37 Correct 628 ms 4460 KB Output is correct
38 Correct 800 ms 4216 KB Output is correct
39 Correct 628 ms 5180 KB Output is correct
40 Correct 754 ms 4704 KB Output is correct
41 Correct 585 ms 5316 KB Output is correct
42 Correct 562 ms 5688 KB Output is correct
43 Correct 612 ms 5004 KB Output is correct
44 Correct 547 ms 5780 KB Output is correct
45 Correct 566 ms 5504 KB Output is correct
46 Correct 588 ms 5160 KB Output is correct
47 Correct 546 ms 5920 KB Output is correct
48 Correct 567 ms 5440 KB Output is correct
49 Correct 740 ms 4536 KB Output is correct
50 Correct 729 ms 4456 KB Output is correct
51 Correct 731 ms 4676 KB Output is correct
52 Correct 745 ms 4804 KB Output is correct
53 Correct 629 ms 4764 KB Output is correct
54 Correct 638 ms 4952 KB Output is correct
55 Correct 618 ms 4628 KB Output is correct
56 Correct 629 ms 4684 KB Output is correct
57 Correct 686 ms 4508 KB Output is correct
58 Correct 728 ms 4344 KB Output is correct
59 Correct 686 ms 5076 KB Output is correct
60 Correct 707 ms 4216 KB Output is correct
61 Correct 565 ms 5520 KB Output is correct
62 Correct 555 ms 6112 KB Output is correct
63 Correct 546 ms 5900 KB Output is correct
64 Correct 545 ms 5976 KB Output is correct
65 Correct 595 ms 5404 KB Output is correct
66 Correct 607 ms 5228 KB Output is correct
67 Correct 544 ms 5436 KB Output is correct
68 Correct 573 ms 5360 KB Output is correct
69 Correct 738 ms 4884 KB Output is correct
70 Correct 733 ms 4656 KB Output is correct
71 Correct 732 ms 4804 KB Output is correct
72 Correct 727 ms 4832 KB Output is correct
73 Correct 601 ms 4988 KB Output is correct
74 Correct 577 ms 5504 KB Output is correct
75 Correct 539 ms 6004 KB Output is correct
76 Correct 548 ms 5864 KB Output is correct
77 Correct 633 ms 4396 KB Output is correct
78 Correct 618 ms 4632 KB Output is correct
79 Correct 626 ms 4624 KB Output is correct
80 Correct 629 ms 4892 KB Output is correct
81 Correct 574 ms 5600 KB Output is correct
82 Correct 607 ms 5016 KB Output is correct
83 Correct 615 ms 4760 KB Output is correct
84 Correct 576 ms 5304 KB Output is correct
85 Correct 566 ms 5756 KB Output is correct
86 Correct 558 ms 5656 KB Output is correct
87 Correct 580 ms 5248 KB Output is correct
88 Correct 607 ms 5040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 20 ms 384 KB Output is correct
4 Correct 20 ms 512 KB Output is correct
5 Correct 19 ms 512 KB Output is correct
6 Correct 21 ms 512 KB Output is correct
7 Correct 21 ms 512 KB Output is correct
8 Correct 17 ms 384 KB Output is correct
9 Correct 18 ms 512 KB Output is correct
10 Correct 14 ms 544 KB Output is correct
11 Correct 37 ms 384 KB Output is correct
12 Correct 31 ms 604 KB Output is correct
13 Correct 14 ms 512 KB Output is correct
14 Correct 18 ms 384 KB Output is correct
15 Correct 20 ms 384 KB Output is correct
16 Correct 20 ms 504 KB Output is correct
17 Correct 20 ms 384 KB Output is correct
18 Correct 15 ms 512 KB Output is correct
19 Correct 22 ms 384 KB Output is correct
20 Correct 20 ms 512 KB Output is correct
21 Correct 739 ms 3372 KB Output is correct
22 Correct 741 ms 4152 KB Output is correct
23 Correct 746 ms 4424 KB Output is correct
24 Correct 751 ms 4116 KB Output is correct
25 Correct 575 ms 5620 KB Output is correct
26 Correct 568 ms 5592 KB Output is correct
27 Correct 741 ms 4292 KB Output is correct
28 Correct 732 ms 4272 KB Output is correct
29 Correct 726 ms 4276 KB Output is correct
30 Correct 769 ms 4148 KB Output is correct
31 Correct 821 ms 4460 KB Output is correct
32 Correct 673 ms 4716 KB Output is correct
33 Correct 487 ms 3088 KB Output is correct
34 Correct 475 ms 4064 KB Output is correct
35 Correct 483 ms 4012 KB Output is correct
36 Correct 478 ms 3992 KB Output is correct
37 Correct 622 ms 4572 KB Output is correct
38 Correct 672 ms 4392 KB Output is correct
39 Correct 621 ms 4488 KB Output is correct
40 Correct 573 ms 5876 KB Output is correct
41 Correct 548 ms 5832 KB Output is correct
42 Correct 524 ms 5216 KB Output is correct
43 Correct 483 ms 4520 KB Output is correct
44 Correct 541 ms 5448 KB Output is correct
45 Correct 499 ms 5124 KB Output is correct
46 Correct 472 ms 4944 KB Output is correct
47 Correct 468 ms 4488 KB Output is correct
48 Correct 465 ms 4792 KB Output is correct
49 Correct 646 ms 4164 KB Output is correct
50 Correct 652 ms 4164 KB Output is correct
51 Correct 644 ms 4036 KB Output is correct
52 Correct 642 ms 4084 KB Output is correct
53 Correct 489 ms 4272 KB Output is correct
54 Correct 515 ms 4844 KB Output is correct
55 Correct 511 ms 5436 KB Output is correct
56 Correct 509 ms 5296 KB Output is correct
57 Correct 489 ms 4296 KB Output is correct
58 Correct 485 ms 4380 KB Output is correct
59 Correct 482 ms 4376 KB Output is correct
60 Correct 484 ms 4268 KB Output is correct
61 Correct 515 ms 5344 KB Output is correct
62 Correct 520 ms 5272 KB Output is correct
63 Correct 535 ms 5840 KB Output is correct
64 Correct 525 ms 5544 KB Output is correct
65 Correct 504 ms 5596 KB Output is correct
66 Correct 458 ms 4860 KB Output is correct
67 Correct 481 ms 5332 KB Output is correct
68 Correct 486 ms 5176 KB Output is correct
69 Correct 633 ms 3100 KB Output is correct
70 Correct 636 ms 4276 KB Output is correct
71 Correct 638 ms 4164 KB Output is correct
72 Correct 626 ms 3992 KB Output is correct
73 Correct 628 ms 4460 KB Output is correct
74 Correct 800 ms 4216 KB Output is correct
75 Correct 628 ms 5180 KB Output is correct
76 Correct 754 ms 4704 KB Output is correct
77 Correct 585 ms 5316 KB Output is correct
78 Correct 562 ms 5688 KB Output is correct
79 Correct 612 ms 5004 KB Output is correct
80 Correct 547 ms 5780 KB Output is correct
81 Correct 566 ms 5504 KB Output is correct
82 Correct 588 ms 5160 KB Output is correct
83 Correct 546 ms 5920 KB Output is correct
84 Correct 567 ms 5440 KB Output is correct
85 Correct 740 ms 4536 KB Output is correct
86 Correct 729 ms 4456 KB Output is correct
87 Correct 731 ms 4676 KB Output is correct
88 Correct 745 ms 4804 KB Output is correct
89 Correct 629 ms 4764 KB Output is correct
90 Correct 638 ms 4952 KB Output is correct
91 Correct 618 ms 4628 KB Output is correct
92 Correct 629 ms 4684 KB Output is correct
93 Correct 686 ms 4508 KB Output is correct
94 Correct 728 ms 4344 KB Output is correct
95 Correct 686 ms 5076 KB Output is correct
96 Correct 707 ms 4216 KB Output is correct
97 Correct 565 ms 5520 KB Output is correct
98 Correct 555 ms 6112 KB Output is correct
99 Correct 546 ms 5900 KB Output is correct
100 Correct 545 ms 5976 KB Output is correct
101 Correct 595 ms 5404 KB Output is correct
102 Correct 607 ms 5228 KB Output is correct
103 Correct 544 ms 5436 KB Output is correct
104 Correct 573 ms 5360 KB Output is correct
105 Correct 738 ms 4884 KB Output is correct
106 Correct 733 ms 4656 KB Output is correct
107 Correct 732 ms 4804 KB Output is correct
108 Correct 727 ms 4832 KB Output is correct
109 Correct 601 ms 4988 KB Output is correct
110 Correct 577 ms 5504 KB Output is correct
111 Correct 539 ms 6004 KB Output is correct
112 Correct 548 ms 5864 KB Output is correct
113 Correct 633 ms 4396 KB Output is correct
114 Correct 618 ms 4632 KB Output is correct
115 Correct 626 ms 4624 KB Output is correct
116 Correct 629 ms 4892 KB Output is correct
117 Correct 574 ms 5600 KB Output is correct
118 Correct 607 ms 5016 KB Output is correct
119 Correct 615 ms 4760 KB Output is correct
120 Correct 576 ms 5304 KB Output is correct
121 Correct 566 ms 5756 KB Output is correct
122 Correct 558 ms 5656 KB Output is correct
123 Correct 580 ms 5248 KB Output is correct
124 Correct 607 ms 5040 KB Output is correct
125 Correct 1599 ms 7892 KB Output is correct
126 Correct 1573 ms 8556 KB Output is correct
127 Correct 1593 ms 8388 KB Output is correct
128 Correct 1574 ms 8524 KB Output is correct
129 Correct 1578 ms 8676 KB Output is correct
130 Correct 1578 ms 8660 KB Output is correct
131 Correct 1876 ms 8172 KB Output is correct
132 Correct 1960 ms 9064 KB Output is correct
133 Correct 2037 ms 9676 KB Output is correct
134 Correct 1796 ms 8692 KB Output is correct
135 Correct 2001 ms 9844 KB Output is correct
136 Correct 1547 ms 7756 KB Output is correct
137 Correct 1806 ms 11656 KB Output is correct
138 Correct 1658 ms 11032 KB Output is correct
139 Correct 1723 ms 11372 KB Output is correct
140 Correct 1775 ms 11564 KB Output is correct
141 Correct 1707 ms 11128 KB Output is correct
142 Correct 1592 ms 10888 KB Output is correct
143 Correct 1608 ms 10636 KB Output is correct
144 Correct 1578 ms 11988 KB Output is correct
145 Correct 1774 ms 11496 KB Output is correct
146 Correct 1612 ms 10404 KB Output is correct
147 Correct 1593 ms 10828 KB Output is correct
148 Correct 1597 ms 11028 KB Output is correct
149 Correct 2089 ms 9348 KB Output is correct
150 Correct 2078 ms 9292 KB Output is correct
151 Correct 2085 ms 9460 KB Output is correct
152 Correct 2072 ms 9204 KB Output is correct
153 Correct 2073 ms 9300 KB Output is correct
154 Correct 2065 ms 9208 KB Output is correct
155 Correct 1601 ms 11992 KB Output is correct
156 Correct 1612 ms 10576 KB Output is correct
157 Correct 1801 ms 11740 KB Output is correct
158 Correct 1793 ms 11612 KB Output is correct
159 Correct 1669 ms 10788 KB Output is correct
160 Correct 1620 ms 10936 KB Output is correct
161 Correct 1584 ms 8672 KB Output is correct
162 Correct 1596 ms 8816 KB Output is correct
163 Correct 1579 ms 8400 KB Output is correct
164 Correct 1582 ms 8712 KB Output is correct
165 Correct 1576 ms 8680 KB Output is correct
166 Correct 1586 ms 8604 KB Output is correct
167 Correct 1857 ms 11740 KB Output is correct
168 Correct 1833 ms 12028 KB Output is correct
169 Correct 1778 ms 11736 KB Output is correct
170 Correct 1757 ms 11784 KB Output is correct
171 Correct 1714 ms 11068 KB Output is correct
172 Correct 1613 ms 10404 KB Output is correct
173 Correct 1818 ms 11480 KB Output is correct
174 Correct 1629 ms 10224 KB Output is correct
175 Correct 1702 ms 11120 KB Output is correct
176 Correct 1601 ms 10904 KB Output is correct
177 Correct 1692 ms 11036 KB Output is correct
178 Correct 1697 ms 10968 KB Output is correct