Submission #652155

# Submission time Handle Problem Language Result Execution time Memory
652155 2022-10-21T14:13:26 Z vovik Segments (IZhO18_segments) C++17
75 / 100
5000 ms 22568 KB
//Bitch, я поймал свой balance
//Теперь нихуя не надо делать
#include <bits/stdc++.h>

#define vc vector

using namespace std;
typedef long long ll;

#define X first
#define Y second

const int K = 2000, N = 2e5 + 5;

vc<int> ls[N / K + 1];
vc<int> rs[N / K + 1];
vc<int> self_l[N];
vc<int> self_r[N];

vc<int> e;
int get(int L, int R, int k) {
    int dl = R - k + 2, dr = L + k - 2;
    //for l [dl; inf]
    //for r [-inf; dr]
    int ans = 0;
    k = lower_bound(e.begin(), e.end(), k) - e.begin();
    for (int i = k / K + 1; i <= N / K; ++i) ans += ls[i].size();
    for (int i = k / K + 1; i <= N / K; ++i) ans -= ls[i].end() - lower_bound(ls[i].begin(), ls[i].end(), dl);
    for (int i = k / K + 1; i <= N / K; ++i) ans -= upper_bound(rs[i].begin(), rs[i].end(), dr) - rs[i].begin();
    for (int len = k; len < (k / K + 1) * K; ++len) ans += self_l[len].size();
    for (int len = k; len < (k / K + 1) * K; ++len) ans -= self_l[len].end() - lower_bound(self_l[len].begin(), self_l[len].end(), dl);
    for (int len = k; len < (k / K + 1) * K; ++len) ans -= upper_bound(self_r[len].begin(), self_r[len].end(), dr) - self_r[len].begin();
    return ans;
}

void rebuild(multiset<pair<int, int>> &x) {
    e.clear();
    for (auto &i : ls) i.clear();
    for (auto &i : rs) i.clear();
    for (auto &i : self_l) i.clear();
    for (auto &i : self_r) i.clear();
    for (auto [l, r] : x) e.push_back(r - l + 1);
    sort(e.begin(), e.end()), e.resize(unique(e.begin(), e.end()) - e.begin());
    for (auto [l, r] : x) {
        int len = r - l + 1;
        len = lower_bound(e.begin(), e.end(), len) - e.begin();
        ls[len / K].push_back(l), rs[len / K].push_back(r);
        self_l[len].push_back(l);
        self_r[len].push_back(r);
    }
    for (auto &i : self_l) sort(i.begin(), i.end());
    for (auto &i : self_r) sort(i.begin(), i.end());
    for (auto &i : ls) sort(i.begin(), i.end());
    for (auto &i : rs) sort(i.begin(), i.end());
}

const int E = 4000;

int main() {
    cin.tie(nullptr)->ios_base::sync_with_stdio(false);
    int n, T;
    cin >> n >> T;
    multiset<pair<int, int>> x;
    vc<pair<int, int>> f;
    vc<pair<int, int>> rec_add, rec_del;
    int lst = 0;
    for (int a, b, t, id, k; n--;) {
        if (n % E == 0) rec_add.clear(), rec_del.clear(), rebuild(x);
        cin >> t;
        if (t == 1) {
            cin >> a >> b;
            int l = (T * lst) ^ a, r = (T * lst) ^ b;
            if (l > r) swap(l, r);
            f.emplace_back(l, r);
            x.insert(f.back());
            rec_add.push_back(f.back());
        } else if (t == 2) {
            cin >> id, --id;
            x.erase(x.find(f[id]));
            rec_del.push_back(f[id]);
        } else if (t == 3) {
            cin >> a >> b >> k;
            int l = (T * lst) ^ a, r = (T * lst) ^ b;
            if (l > r) swap(l, r);
            lst = 0;
            int dl = r - k + 2, dr = l + k - 2;
            //for l [dl; inf]
            //for r [-inf; dr]

            lst = get(l, r, k);

            for (auto [l, r] : rec_add) if (r - l + 1 >= k) ++lst, lst -= (l >= dl), lst -= (r <= dr);
            for (auto [l, r] : rec_del) if (r - l + 1 >= k) --lst, lst += (l >= dl), lst += (r <= dr);
            cout << lst << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 39 ms 9720 KB Output is correct
4 Correct 35 ms 9752 KB Output is correct
5 Correct 33 ms 10204 KB Output is correct
6 Correct 49 ms 10188 KB Output is correct
7 Correct 34 ms 9812 KB Output is correct
8 Correct 28 ms 10136 KB Output is correct
9 Correct 29 ms 9996 KB Output is correct
10 Correct 18 ms 10220 KB Output is correct
11 Correct 56 ms 9956 KB Output is correct
12 Correct 58 ms 9948 KB Output is correct
13 Correct 19 ms 10324 KB Output is correct
14 Correct 29 ms 10060 KB Output is correct
15 Correct 37 ms 9740 KB Output is correct
16 Correct 34 ms 9780 KB Output is correct
17 Correct 33 ms 9876 KB Output is correct
18 Correct 27 ms 10232 KB Output is correct
19 Correct 30 ms 9944 KB Output is correct
20 Correct 42 ms 9940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1785 ms 16480 KB Output is correct
2 Correct 1626 ms 16500 KB Output is correct
3 Correct 1434 ms 16492 KB Output is correct
4 Correct 1461 ms 17160 KB Output is correct
5 Correct 831 ms 21948 KB Output is correct
6 Correct 813 ms 22240 KB Output is correct
7 Correct 1552 ms 16656 KB Output is correct
8 Correct 1534 ms 16476 KB Output is correct
9 Correct 1935 ms 16552 KB Output is correct
10 Correct 1963 ms 12576 KB Output is correct
11 Correct 1898 ms 13620 KB Output is correct
12 Correct 1646 ms 19020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 598 ms 10496 KB Output is correct
2 Correct 572 ms 10380 KB Output is correct
3 Correct 651 ms 10504 KB Output is correct
4 Correct 564 ms 10480 KB Output is correct
5 Correct 1735 ms 19176 KB Output is correct
6 Correct 2072 ms 17876 KB Output is correct
7 Correct 1872 ms 18576 KB Output is correct
8 Correct 976 ms 21992 KB Output is correct
9 Correct 885 ms 21540 KB Output is correct
10 Correct 1062 ms 18552 KB Output is correct
11 Correct 1289 ms 10944 KB Output is correct
12 Correct 1102 ms 18712 KB Output is correct
13 Correct 1286 ms 17844 KB Output is correct
14 Correct 1322 ms 13716 KB Output is correct
15 Correct 1230 ms 13276 KB Output is correct
16 Correct 1267 ms 12364 KB Output is correct
17 Correct 2175 ms 16556 KB Output is correct
18 Correct 2092 ms 16436 KB Output is correct
19 Correct 2115 ms 16672 KB Output is correct
20 Correct 2185 ms 16644 KB Output is correct
21 Correct 1128 ms 11256 KB Output is correct
22 Correct 1200 ms 14636 KB Output is correct
23 Correct 1168 ms 16776 KB Output is correct
24 Correct 1175 ms 15064 KB Output is correct
25 Correct 593 ms 10500 KB Output is correct
26 Correct 577 ms 10476 KB Output is correct
27 Correct 603 ms 10424 KB Output is correct
28 Correct 623 ms 10460 KB Output is correct
29 Correct 1133 ms 17428 KB Output is correct
30 Correct 1137 ms 17344 KB Output is correct
31 Correct 897 ms 21480 KB Output is correct
32 Correct 1014 ms 18584 KB Output is correct
33 Correct 1183 ms 18100 KB Output is correct
34 Correct 1078 ms 13220 KB Output is correct
35 Correct 1296 ms 16188 KB Output is correct
36 Correct 1093 ms 18476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 635 ms 10356 KB Output is correct
2 Correct 735 ms 10716 KB Output is correct
3 Correct 657 ms 10460 KB Output is correct
4 Correct 710 ms 10464 KB Output is correct
5 Correct 1336 ms 20048 KB Output is correct
6 Correct 1854 ms 12176 KB Output is correct
7 Correct 1167 ms 20724 KB Output is correct
8 Correct 1770 ms 13020 KB Output is correct
9 Correct 1046 ms 14520 KB Output is correct
10 Correct 1018 ms 19036 KB Output is correct
11 Correct 927 ms 11848 KB Output is correct
12 Correct 829 ms 22100 KB Output is correct
13 Correct 964 ms 17868 KB Output is correct
14 Correct 1018 ms 14048 KB Output is correct
15 Correct 977 ms 21344 KB Output is correct
16 Correct 1113 ms 18304 KB Output is correct
17 Correct 1951 ms 16472 KB Output is correct
18 Correct 2176 ms 16608 KB Output is correct
19 Correct 1922 ms 16496 KB Output is correct
20 Correct 1879 ms 16480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 39 ms 9720 KB Output is correct
4 Correct 35 ms 9752 KB Output is correct
5 Correct 33 ms 10204 KB Output is correct
6 Correct 49 ms 10188 KB Output is correct
7 Correct 34 ms 9812 KB Output is correct
8 Correct 28 ms 10136 KB Output is correct
9 Correct 29 ms 9996 KB Output is correct
10 Correct 18 ms 10220 KB Output is correct
11 Correct 56 ms 9956 KB Output is correct
12 Correct 58 ms 9948 KB Output is correct
13 Correct 19 ms 10324 KB Output is correct
14 Correct 29 ms 10060 KB Output is correct
15 Correct 37 ms 9740 KB Output is correct
16 Correct 34 ms 9780 KB Output is correct
17 Correct 33 ms 9876 KB Output is correct
18 Correct 27 ms 10232 KB Output is correct
19 Correct 30 ms 9944 KB Output is correct
20 Correct 42 ms 9940 KB Output is correct
21 Correct 1785 ms 16480 KB Output is correct
22 Correct 1626 ms 16500 KB Output is correct
23 Correct 1434 ms 16492 KB Output is correct
24 Correct 1461 ms 17160 KB Output is correct
25 Correct 831 ms 21948 KB Output is correct
26 Correct 813 ms 22240 KB Output is correct
27 Correct 1552 ms 16656 KB Output is correct
28 Correct 1534 ms 16476 KB Output is correct
29 Correct 1935 ms 16552 KB Output is correct
30 Correct 1963 ms 12576 KB Output is correct
31 Correct 1898 ms 13620 KB Output is correct
32 Correct 1646 ms 19020 KB Output is correct
33 Correct 635 ms 10356 KB Output is correct
34 Correct 735 ms 10716 KB Output is correct
35 Correct 657 ms 10460 KB Output is correct
36 Correct 710 ms 10464 KB Output is correct
37 Correct 1336 ms 20048 KB Output is correct
38 Correct 1854 ms 12176 KB Output is correct
39 Correct 1167 ms 20724 KB Output is correct
40 Correct 1770 ms 13020 KB Output is correct
41 Correct 1046 ms 14520 KB Output is correct
42 Correct 1018 ms 19036 KB Output is correct
43 Correct 927 ms 11848 KB Output is correct
44 Correct 829 ms 22100 KB Output is correct
45 Correct 964 ms 17868 KB Output is correct
46 Correct 1018 ms 14048 KB Output is correct
47 Correct 977 ms 21344 KB Output is correct
48 Correct 1113 ms 18304 KB Output is correct
49 Correct 1951 ms 16472 KB Output is correct
50 Correct 2176 ms 16608 KB Output is correct
51 Correct 1922 ms 16496 KB Output is correct
52 Correct 1879 ms 16480 KB Output is correct
53 Correct 662 ms 10460 KB Output is correct
54 Correct 643 ms 10460 KB Output is correct
55 Correct 652 ms 10380 KB Output is correct
56 Correct 751 ms 10472 KB Output is correct
57 Correct 1796 ms 14248 KB Output is correct
58 Correct 2188 ms 11256 KB Output is correct
59 Correct 1745 ms 17900 KB Output is correct
60 Correct 2009 ms 11052 KB Output is correct
61 Correct 1026 ms 17764 KB Output is correct
62 Correct 934 ms 20932 KB Output is correct
63 Correct 943 ms 21760 KB Output is correct
64 Correct 951 ms 21180 KB Output is correct
65 Correct 962 ms 12708 KB Output is correct
66 Correct 897 ms 12100 KB Output is correct
67 Correct 1020 ms 18464 KB Output is correct
68 Correct 1107 ms 16188 KB Output is correct
69 Correct 1738 ms 16608 KB Output is correct
70 Correct 1724 ms 16500 KB Output is correct
71 Correct 1740 ms 16484 KB Output is correct
72 Correct 1786 ms 16504 KB Output is correct
73 Correct 949 ms 13160 KB Output is correct
74 Correct 1069 ms 15968 KB Output is correct
75 Correct 782 ms 22432 KB Output is correct
76 Correct 807 ms 21868 KB Output is correct
77 Correct 641 ms 10480 KB Output is correct
78 Correct 639 ms 10476 KB Output is correct
79 Correct 633 ms 10504 KB Output is correct
80 Correct 634 ms 10424 KB Output is correct
81 Correct 1112 ms 15780 KB Output is correct
82 Correct 997 ms 13076 KB Output is correct
83 Correct 930 ms 11796 KB Output is correct
84 Correct 1050 ms 15784 KB Output is correct
85 Correct 983 ms 18532 KB Output is correct
86 Correct 1026 ms 18648 KB Output is correct
87 Correct 934 ms 14588 KB Output is correct
88 Correct 930 ms 11852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 39 ms 9720 KB Output is correct
4 Correct 35 ms 9752 KB Output is correct
5 Correct 33 ms 10204 KB Output is correct
6 Correct 49 ms 10188 KB Output is correct
7 Correct 34 ms 9812 KB Output is correct
8 Correct 28 ms 10136 KB Output is correct
9 Correct 29 ms 9996 KB Output is correct
10 Correct 18 ms 10220 KB Output is correct
11 Correct 56 ms 9956 KB Output is correct
12 Correct 58 ms 9948 KB Output is correct
13 Correct 19 ms 10324 KB Output is correct
14 Correct 29 ms 10060 KB Output is correct
15 Correct 37 ms 9740 KB Output is correct
16 Correct 34 ms 9780 KB Output is correct
17 Correct 33 ms 9876 KB Output is correct
18 Correct 27 ms 10232 KB Output is correct
19 Correct 30 ms 9944 KB Output is correct
20 Correct 42 ms 9940 KB Output is correct
21 Correct 1785 ms 16480 KB Output is correct
22 Correct 1626 ms 16500 KB Output is correct
23 Correct 1434 ms 16492 KB Output is correct
24 Correct 1461 ms 17160 KB Output is correct
25 Correct 831 ms 21948 KB Output is correct
26 Correct 813 ms 22240 KB Output is correct
27 Correct 1552 ms 16656 KB Output is correct
28 Correct 1534 ms 16476 KB Output is correct
29 Correct 1935 ms 16552 KB Output is correct
30 Correct 1963 ms 12576 KB Output is correct
31 Correct 1898 ms 13620 KB Output is correct
32 Correct 1646 ms 19020 KB Output is correct
33 Correct 598 ms 10496 KB Output is correct
34 Correct 572 ms 10380 KB Output is correct
35 Correct 651 ms 10504 KB Output is correct
36 Correct 564 ms 10480 KB Output is correct
37 Correct 1735 ms 19176 KB Output is correct
38 Correct 2072 ms 17876 KB Output is correct
39 Correct 1872 ms 18576 KB Output is correct
40 Correct 976 ms 21992 KB Output is correct
41 Correct 885 ms 21540 KB Output is correct
42 Correct 1062 ms 18552 KB Output is correct
43 Correct 1289 ms 10944 KB Output is correct
44 Correct 1102 ms 18712 KB Output is correct
45 Correct 1286 ms 17844 KB Output is correct
46 Correct 1322 ms 13716 KB Output is correct
47 Correct 1230 ms 13276 KB Output is correct
48 Correct 1267 ms 12364 KB Output is correct
49 Correct 2175 ms 16556 KB Output is correct
50 Correct 2092 ms 16436 KB Output is correct
51 Correct 2115 ms 16672 KB Output is correct
52 Correct 2185 ms 16644 KB Output is correct
53 Correct 1128 ms 11256 KB Output is correct
54 Correct 1200 ms 14636 KB Output is correct
55 Correct 1168 ms 16776 KB Output is correct
56 Correct 1175 ms 15064 KB Output is correct
57 Correct 593 ms 10500 KB Output is correct
58 Correct 577 ms 10476 KB Output is correct
59 Correct 603 ms 10424 KB Output is correct
60 Correct 623 ms 10460 KB Output is correct
61 Correct 1133 ms 17428 KB Output is correct
62 Correct 1137 ms 17344 KB Output is correct
63 Correct 897 ms 21480 KB Output is correct
64 Correct 1014 ms 18584 KB Output is correct
65 Correct 1183 ms 18100 KB Output is correct
66 Correct 1078 ms 13220 KB Output is correct
67 Correct 1296 ms 16188 KB Output is correct
68 Correct 1093 ms 18476 KB Output is correct
69 Correct 635 ms 10356 KB Output is correct
70 Correct 735 ms 10716 KB Output is correct
71 Correct 657 ms 10460 KB Output is correct
72 Correct 710 ms 10464 KB Output is correct
73 Correct 1336 ms 20048 KB Output is correct
74 Correct 1854 ms 12176 KB Output is correct
75 Correct 1167 ms 20724 KB Output is correct
76 Correct 1770 ms 13020 KB Output is correct
77 Correct 1046 ms 14520 KB Output is correct
78 Correct 1018 ms 19036 KB Output is correct
79 Correct 927 ms 11848 KB Output is correct
80 Correct 829 ms 22100 KB Output is correct
81 Correct 964 ms 17868 KB Output is correct
82 Correct 1018 ms 14048 KB Output is correct
83 Correct 977 ms 21344 KB Output is correct
84 Correct 1113 ms 18304 KB Output is correct
85 Correct 1951 ms 16472 KB Output is correct
86 Correct 2176 ms 16608 KB Output is correct
87 Correct 1922 ms 16496 KB Output is correct
88 Correct 1879 ms 16480 KB Output is correct
89 Correct 662 ms 10460 KB Output is correct
90 Correct 643 ms 10460 KB Output is correct
91 Correct 652 ms 10380 KB Output is correct
92 Correct 751 ms 10472 KB Output is correct
93 Correct 1796 ms 14248 KB Output is correct
94 Correct 2188 ms 11256 KB Output is correct
95 Correct 1745 ms 17900 KB Output is correct
96 Correct 2009 ms 11052 KB Output is correct
97 Correct 1026 ms 17764 KB Output is correct
98 Correct 934 ms 20932 KB Output is correct
99 Correct 943 ms 21760 KB Output is correct
100 Correct 951 ms 21180 KB Output is correct
101 Correct 962 ms 12708 KB Output is correct
102 Correct 897 ms 12100 KB Output is correct
103 Correct 1020 ms 18464 KB Output is correct
104 Correct 1107 ms 16188 KB Output is correct
105 Correct 1738 ms 16608 KB Output is correct
106 Correct 1724 ms 16500 KB Output is correct
107 Correct 1740 ms 16484 KB Output is correct
108 Correct 1786 ms 16504 KB Output is correct
109 Correct 949 ms 13160 KB Output is correct
110 Correct 1069 ms 15968 KB Output is correct
111 Correct 782 ms 22432 KB Output is correct
112 Correct 807 ms 21868 KB Output is correct
113 Correct 641 ms 10480 KB Output is correct
114 Correct 639 ms 10476 KB Output is correct
115 Correct 633 ms 10504 KB Output is correct
116 Correct 634 ms 10424 KB Output is correct
117 Correct 1112 ms 15780 KB Output is correct
118 Correct 997 ms 13076 KB Output is correct
119 Correct 930 ms 11796 KB Output is correct
120 Correct 1050 ms 15784 KB Output is correct
121 Correct 983 ms 18532 KB Output is correct
122 Correct 1026 ms 18648 KB Output is correct
123 Correct 934 ms 14588 KB Output is correct
124 Correct 930 ms 11852 KB Output is correct
125 Correct 1388 ms 10964 KB Output is correct
126 Correct 1363 ms 11056 KB Output is correct
127 Correct 1342 ms 11116 KB Output is correct
128 Correct 1320 ms 11044 KB Output is correct
129 Correct 1291 ms 10980 KB Output is correct
130 Correct 1384 ms 11084 KB Output is correct
131 Correct 4393 ms 13208 KB Output is correct
132 Execution timed out 5067 ms 22568 KB Time limit exceeded
133 Halted 0 ms 0 KB -