Submission #652156

# Submission time Handle Problem Language Result Execution time Memory
652156 2022-10-21T14:13:45 Z vovik Segments (IZhO18_segments) C++17
75 / 100
5000 ms 22528 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 = 3000;

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 9 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 35 ms 9776 KB Output is correct
4 Correct 35 ms 9752 KB Output is correct
5 Correct 46 ms 10276 KB Output is correct
6 Correct 54 ms 10188 KB Output is correct
7 Correct 39 ms 9784 KB Output is correct
8 Correct 29 ms 10068 KB Output is correct
9 Correct 31 ms 10040 KB Output is correct
10 Correct 20 ms 10324 KB Output is correct
11 Correct 58 ms 10028 KB Output is correct
12 Correct 58 ms 10060 KB Output is correct
13 Correct 20 ms 10332 KB Output is correct
14 Correct 39 ms 10020 KB Output is correct
15 Correct 37 ms 9744 KB Output is correct
16 Correct 38 ms 9768 KB Output is correct
17 Correct 43 ms 9932 KB Output is correct
18 Correct 22 ms 10252 KB Output is correct
19 Correct 33 ms 9940 KB Output is correct
20 Correct 37 ms 9940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1861 ms 16476 KB Output is correct
2 Correct 1874 ms 16616 KB Output is correct
3 Correct 1938 ms 16496 KB Output is correct
4 Correct 1934 ms 17124 KB Output is correct
5 Correct 1285 ms 21992 KB Output is correct
6 Correct 1157 ms 22528 KB Output is correct
7 Correct 1818 ms 16612 KB Output is correct
8 Correct 1956 ms 16440 KB Output is correct
9 Correct 2203 ms 16524 KB Output is correct
10 Correct 2199 ms 12588 KB Output is correct
11 Correct 2005 ms 13624 KB Output is correct
12 Correct 1592 ms 18972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 596 ms 10524 KB Output is correct
2 Correct 562 ms 10512 KB Output is correct
3 Correct 644 ms 10552 KB Output is correct
4 Correct 594 ms 10512 KB Output is correct
5 Correct 1790 ms 19268 KB Output is correct
6 Correct 2190 ms 17836 KB Output is correct
7 Correct 1961 ms 18600 KB Output is correct
8 Correct 1158 ms 22120 KB Output is correct
9 Correct 1100 ms 21388 KB Output is correct
10 Correct 1295 ms 18548 KB Output is correct
11 Correct 1075 ms 10932 KB Output is correct
12 Correct 1213 ms 18604 KB Output is correct
13 Correct 1251 ms 17844 KB Output is correct
14 Correct 1233 ms 13744 KB Output is correct
15 Correct 1196 ms 13368 KB Output is correct
16 Correct 1108 ms 12316 KB Output is correct
17 Correct 2335 ms 16524 KB Output is correct
18 Correct 2359 ms 16592 KB Output is correct
19 Correct 2316 ms 16600 KB Output is correct
20 Correct 2406 ms 16508 KB Output is correct
21 Correct 1197 ms 11080 KB Output is correct
22 Correct 1257 ms 14832 KB Output is correct
23 Correct 1220 ms 16772 KB Output is correct
24 Correct 1283 ms 15076 KB Output is correct
25 Correct 652 ms 10412 KB Output is correct
26 Correct 652 ms 10476 KB Output is correct
27 Correct 605 ms 10556 KB Output is correct
28 Correct 580 ms 10500 KB Output is correct
29 Correct 1266 ms 17340 KB Output is correct
30 Correct 1304 ms 17352 KB Output is correct
31 Correct 1141 ms 21520 KB Output is correct
32 Correct 1497 ms 18652 KB Output is correct
33 Correct 1572 ms 18044 KB Output is correct
34 Correct 1270 ms 13152 KB Output is correct
35 Correct 1348 ms 16188 KB Output is correct
36 Correct 1194 ms 18432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 614 ms 10436 KB Output is correct
2 Correct 616 ms 10440 KB Output is correct
3 Correct 624 ms 10492 KB Output is correct
4 Correct 711 ms 10508 KB Output is correct
5 Correct 1558 ms 19848 KB Output is correct
6 Correct 2113 ms 11964 KB Output is correct
7 Correct 1576 ms 20604 KB Output is correct
8 Correct 2001 ms 12800 KB Output is correct
9 Correct 1016 ms 14568 KB Output is correct
10 Correct 1124 ms 18988 KB Output is correct
11 Correct 947 ms 11900 KB Output is correct
12 Correct 1075 ms 22060 KB Output is correct
13 Correct 1220 ms 17696 KB Output is correct
14 Correct 1053 ms 14148 KB Output is correct
15 Correct 1080 ms 21420 KB Output is correct
16 Correct 1207 ms 18308 KB Output is correct
17 Correct 1831 ms 16548 KB Output is correct
18 Correct 1830 ms 16484 KB Output is correct
19 Correct 1853 ms 16644 KB Output is correct
20 Correct 1836 ms 16492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 35 ms 9776 KB Output is correct
4 Correct 35 ms 9752 KB Output is correct
5 Correct 46 ms 10276 KB Output is correct
6 Correct 54 ms 10188 KB Output is correct
7 Correct 39 ms 9784 KB Output is correct
8 Correct 29 ms 10068 KB Output is correct
9 Correct 31 ms 10040 KB Output is correct
10 Correct 20 ms 10324 KB Output is correct
11 Correct 58 ms 10028 KB Output is correct
12 Correct 58 ms 10060 KB Output is correct
13 Correct 20 ms 10332 KB Output is correct
14 Correct 39 ms 10020 KB Output is correct
15 Correct 37 ms 9744 KB Output is correct
16 Correct 38 ms 9768 KB Output is correct
17 Correct 43 ms 9932 KB Output is correct
18 Correct 22 ms 10252 KB Output is correct
19 Correct 33 ms 9940 KB Output is correct
20 Correct 37 ms 9940 KB Output is correct
21 Correct 1861 ms 16476 KB Output is correct
22 Correct 1874 ms 16616 KB Output is correct
23 Correct 1938 ms 16496 KB Output is correct
24 Correct 1934 ms 17124 KB Output is correct
25 Correct 1285 ms 21992 KB Output is correct
26 Correct 1157 ms 22528 KB Output is correct
27 Correct 1818 ms 16612 KB Output is correct
28 Correct 1956 ms 16440 KB Output is correct
29 Correct 2203 ms 16524 KB Output is correct
30 Correct 2199 ms 12588 KB Output is correct
31 Correct 2005 ms 13624 KB Output is correct
32 Correct 1592 ms 18972 KB Output is correct
33 Correct 614 ms 10436 KB Output is correct
34 Correct 616 ms 10440 KB Output is correct
35 Correct 624 ms 10492 KB Output is correct
36 Correct 711 ms 10508 KB Output is correct
37 Correct 1558 ms 19848 KB Output is correct
38 Correct 2113 ms 11964 KB Output is correct
39 Correct 1576 ms 20604 KB Output is correct
40 Correct 2001 ms 12800 KB Output is correct
41 Correct 1016 ms 14568 KB Output is correct
42 Correct 1124 ms 18988 KB Output is correct
43 Correct 947 ms 11900 KB Output is correct
44 Correct 1075 ms 22060 KB Output is correct
45 Correct 1220 ms 17696 KB Output is correct
46 Correct 1053 ms 14148 KB Output is correct
47 Correct 1080 ms 21420 KB Output is correct
48 Correct 1207 ms 18308 KB Output is correct
49 Correct 1831 ms 16548 KB Output is correct
50 Correct 1830 ms 16484 KB Output is correct
51 Correct 1853 ms 16644 KB Output is correct
52 Correct 1836 ms 16492 KB Output is correct
53 Correct 654 ms 10424 KB Output is correct
54 Correct 652 ms 10464 KB Output is correct
55 Correct 620 ms 10456 KB Output is correct
56 Correct 650 ms 10460 KB Output is correct
57 Correct 1983 ms 14252 KB Output is correct
58 Correct 1920 ms 11428 KB Output is correct
59 Correct 1916 ms 17912 KB Output is correct
60 Correct 1936 ms 11160 KB Output is correct
61 Correct 1210 ms 17844 KB Output is correct
62 Correct 1159 ms 20872 KB Output is correct
63 Correct 1100 ms 21756 KB Output is correct
64 Correct 1132 ms 20960 KB Output is correct
65 Correct 941 ms 12560 KB Output is correct
66 Correct 963 ms 12100 KB Output is correct
67 Correct 1170 ms 18372 KB Output is correct
68 Correct 1141 ms 16200 KB Output is correct
69 Correct 1729 ms 16460 KB Output is correct
70 Correct 1853 ms 16408 KB Output is correct
71 Correct 1961 ms 16608 KB Output is correct
72 Correct 1983 ms 16500 KB Output is correct
73 Correct 1146 ms 13088 KB Output is correct
74 Correct 1311 ms 16172 KB Output is correct
75 Correct 1086 ms 22364 KB Output is correct
76 Correct 1067 ms 21808 KB Output is correct
77 Correct 701 ms 10404 KB Output is correct
78 Correct 752 ms 10488 KB Output is correct
79 Correct 766 ms 10500 KB Output is correct
80 Correct 621 ms 10428 KB Output is correct
81 Correct 1270 ms 15820 KB Output is correct
82 Correct 1026 ms 13000 KB Output is correct
83 Correct 958 ms 11712 KB Output is correct
84 Correct 1253 ms 15928 KB Output is correct
85 Correct 1249 ms 18512 KB Output is correct
86 Correct 1267 ms 18568 KB Output is correct
87 Correct 1070 ms 14476 KB Output is correct
88 Correct 934 ms 11980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9684 KB Output is correct
2 Correct 7 ms 9684 KB Output is correct
3 Correct 35 ms 9776 KB Output is correct
4 Correct 35 ms 9752 KB Output is correct
5 Correct 46 ms 10276 KB Output is correct
6 Correct 54 ms 10188 KB Output is correct
7 Correct 39 ms 9784 KB Output is correct
8 Correct 29 ms 10068 KB Output is correct
9 Correct 31 ms 10040 KB Output is correct
10 Correct 20 ms 10324 KB Output is correct
11 Correct 58 ms 10028 KB Output is correct
12 Correct 58 ms 10060 KB Output is correct
13 Correct 20 ms 10332 KB Output is correct
14 Correct 39 ms 10020 KB Output is correct
15 Correct 37 ms 9744 KB Output is correct
16 Correct 38 ms 9768 KB Output is correct
17 Correct 43 ms 9932 KB Output is correct
18 Correct 22 ms 10252 KB Output is correct
19 Correct 33 ms 9940 KB Output is correct
20 Correct 37 ms 9940 KB Output is correct
21 Correct 1861 ms 16476 KB Output is correct
22 Correct 1874 ms 16616 KB Output is correct
23 Correct 1938 ms 16496 KB Output is correct
24 Correct 1934 ms 17124 KB Output is correct
25 Correct 1285 ms 21992 KB Output is correct
26 Correct 1157 ms 22528 KB Output is correct
27 Correct 1818 ms 16612 KB Output is correct
28 Correct 1956 ms 16440 KB Output is correct
29 Correct 2203 ms 16524 KB Output is correct
30 Correct 2199 ms 12588 KB Output is correct
31 Correct 2005 ms 13624 KB Output is correct
32 Correct 1592 ms 18972 KB Output is correct
33 Correct 596 ms 10524 KB Output is correct
34 Correct 562 ms 10512 KB Output is correct
35 Correct 644 ms 10552 KB Output is correct
36 Correct 594 ms 10512 KB Output is correct
37 Correct 1790 ms 19268 KB Output is correct
38 Correct 2190 ms 17836 KB Output is correct
39 Correct 1961 ms 18600 KB Output is correct
40 Correct 1158 ms 22120 KB Output is correct
41 Correct 1100 ms 21388 KB Output is correct
42 Correct 1295 ms 18548 KB Output is correct
43 Correct 1075 ms 10932 KB Output is correct
44 Correct 1213 ms 18604 KB Output is correct
45 Correct 1251 ms 17844 KB Output is correct
46 Correct 1233 ms 13744 KB Output is correct
47 Correct 1196 ms 13368 KB Output is correct
48 Correct 1108 ms 12316 KB Output is correct
49 Correct 2335 ms 16524 KB Output is correct
50 Correct 2359 ms 16592 KB Output is correct
51 Correct 2316 ms 16600 KB Output is correct
52 Correct 2406 ms 16508 KB Output is correct
53 Correct 1197 ms 11080 KB Output is correct
54 Correct 1257 ms 14832 KB Output is correct
55 Correct 1220 ms 16772 KB Output is correct
56 Correct 1283 ms 15076 KB Output is correct
57 Correct 652 ms 10412 KB Output is correct
58 Correct 652 ms 10476 KB Output is correct
59 Correct 605 ms 10556 KB Output is correct
60 Correct 580 ms 10500 KB Output is correct
61 Correct 1266 ms 17340 KB Output is correct
62 Correct 1304 ms 17352 KB Output is correct
63 Correct 1141 ms 21520 KB Output is correct
64 Correct 1497 ms 18652 KB Output is correct
65 Correct 1572 ms 18044 KB Output is correct
66 Correct 1270 ms 13152 KB Output is correct
67 Correct 1348 ms 16188 KB Output is correct
68 Correct 1194 ms 18432 KB Output is correct
69 Correct 614 ms 10436 KB Output is correct
70 Correct 616 ms 10440 KB Output is correct
71 Correct 624 ms 10492 KB Output is correct
72 Correct 711 ms 10508 KB Output is correct
73 Correct 1558 ms 19848 KB Output is correct
74 Correct 2113 ms 11964 KB Output is correct
75 Correct 1576 ms 20604 KB Output is correct
76 Correct 2001 ms 12800 KB Output is correct
77 Correct 1016 ms 14568 KB Output is correct
78 Correct 1124 ms 18988 KB Output is correct
79 Correct 947 ms 11900 KB Output is correct
80 Correct 1075 ms 22060 KB Output is correct
81 Correct 1220 ms 17696 KB Output is correct
82 Correct 1053 ms 14148 KB Output is correct
83 Correct 1080 ms 21420 KB Output is correct
84 Correct 1207 ms 18308 KB Output is correct
85 Correct 1831 ms 16548 KB Output is correct
86 Correct 1830 ms 16484 KB Output is correct
87 Correct 1853 ms 16644 KB Output is correct
88 Correct 1836 ms 16492 KB Output is correct
89 Correct 654 ms 10424 KB Output is correct
90 Correct 652 ms 10464 KB Output is correct
91 Correct 620 ms 10456 KB Output is correct
92 Correct 650 ms 10460 KB Output is correct
93 Correct 1983 ms 14252 KB Output is correct
94 Correct 1920 ms 11428 KB Output is correct
95 Correct 1916 ms 17912 KB Output is correct
96 Correct 1936 ms 11160 KB Output is correct
97 Correct 1210 ms 17844 KB Output is correct
98 Correct 1159 ms 20872 KB Output is correct
99 Correct 1100 ms 21756 KB Output is correct
100 Correct 1132 ms 20960 KB Output is correct
101 Correct 941 ms 12560 KB Output is correct
102 Correct 963 ms 12100 KB Output is correct
103 Correct 1170 ms 18372 KB Output is correct
104 Correct 1141 ms 16200 KB Output is correct
105 Correct 1729 ms 16460 KB Output is correct
106 Correct 1853 ms 16408 KB Output is correct
107 Correct 1961 ms 16608 KB Output is correct
108 Correct 1983 ms 16500 KB Output is correct
109 Correct 1146 ms 13088 KB Output is correct
110 Correct 1311 ms 16172 KB Output is correct
111 Correct 1086 ms 22364 KB Output is correct
112 Correct 1067 ms 21808 KB Output is correct
113 Correct 701 ms 10404 KB Output is correct
114 Correct 752 ms 10488 KB Output is correct
115 Correct 766 ms 10500 KB Output is correct
116 Correct 621 ms 10428 KB Output is correct
117 Correct 1270 ms 15820 KB Output is correct
118 Correct 1026 ms 13000 KB Output is correct
119 Correct 958 ms 11712 KB Output is correct
120 Correct 1253 ms 15928 KB Output is correct
121 Correct 1249 ms 18512 KB Output is correct
122 Correct 1267 ms 18568 KB Output is correct
123 Correct 1070 ms 14476 KB Output is correct
124 Correct 934 ms 11980 KB Output is correct
125 Correct 1275 ms 11080 KB Output is correct
126 Correct 1624 ms 11112 KB Output is correct
127 Correct 1437 ms 11008 KB Output is correct
128 Correct 1301 ms 11096 KB Output is correct
129 Correct 1315 ms 11100 KB Output is correct
130 Correct 1285 ms 11096 KB Output is correct
131 Correct 4517 ms 13164 KB Output is correct
132 Execution timed out 5058 ms 21592 KB Time limit exceeded
133 Halted 0 ms 0 KB -