Submission #93892

# Submission time Handle Problem Language Result Execution time Memory
93892 2019-01-12T21:06:53 Z dalgerok Segments (IZhO18_segments) C++14
75 / 100
5000 ms 8064 KB
#include<bits/stdc++.h>
using namespace std;



const int N = 2e5 + 5, S = 500, M = N / S + 5;



int n, t, ans;
int sz, alive, L[N], R[N];
pair < int, int > a[N];
int add[S], sz_add, del[S], sz_del;
bool killed[N];
int sz_l[S], sz_r[S];
int b_l[S][S], b_r[S][S];
int m;

inline void rebuild(){
    m = 0;
    for(int i = 1; i <= sz; i++){
        if(killed[i] == false){
            a[m++] = make_pair(R[i] - L[i] + 1, i);
        }
    }
    sort(a, a + m);
    sz_add = sz_del = 0;
    for(int i = 0; i <= m / S; i++){
        sz_l[i] = sz_r[i] = 0;
    }
    for(int i = 0; i < m; i++){
        b_l[i / S][sz_l[i / S]++] = L[a[i].second];
        b_r[i / S][sz_r[i / S]++] = R[a[i].second];
    }
    for(int i = 0; i <= m / S; i++){
        sort(b_l[i], b_l[i] + sz_l[i]);
        sort(b_r[i], b_r[i] + sz_r[i]);
    }
}

inline int intersect(int l1, int r1, int l2, int r2){
    return max(0, min(r1, r2) - max(l1, l2) + 1);
}


/// number of L > x from l to r
inline int calcL(int l, int r, int x){
    int res = 0;
    int bl = l / S, br = r / S;
    if(bl == br){
        for(int i = l; i <= r; i++){
            res += (L[a[i].second] > x);
        }
        return res;
    }
    for(int i = bl + 1; i <= br - 1; i++){
        int j = lower_bound(b_l[i], b_l[i] + sz_l[i], x + 1) - b_l[i];
        res += S - j;
    }
    for(int i = l; i < (bl + 1) * S; i++){
        res += (L[a[i].second] > x);
    }
    for(int i = br * S; i <= r; i++){
        res += (L[a[i].second] > x);
    }
    return res;
}
/// number of R < x from l to r
inline int calcR(int l, int r, int x){
    int res = 0;
    int bl = l / S, br = r / S;
    if(bl == br){
        for(int i = l; i <= r; i++){
            res += (R[a[i].second] < x);
        }
        return res;
    }
    for(int i = bl + 1; i <= br - 1; i++){
        int j = lower_bound(b_r[i], b_r[i] + sz_r[i], x) - b_r[i];
        res += j;
    }
    for(int i = l; i < (bl + 1) * S; i++){
        res += (R[a[i].second] < x);
    }
    for(int i = br * S; i <= r; i++){
        res += (R[a[i].second] < x);
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> t;
    for(int i = 1; i <= n; i++){
        if(i % S == 0){
            rebuild();
        }
        int type;
        cin >> type;
        if(type == 1){
            int l, r;
            cin >> l >> r;
            l ^= (1LL * t * ans);
            r ^= (1LL * t * ans);
            if(l > r){
                swap(l, r);
            }
            sz += 1;
            L[sz] = l;
            R[sz] = r;
            add[sz_add++] = sz;
            alive += 1;
        }
        else if(type == 2){
            int x;
            cin >> x;
            del[sz_del++] = x;
            killed[x] = true;
            alive -= 1;
        }
        else{
            int l, r, k;
            cin >> l >> r >> k;
            l ^= (1LL * t * ans);
            r ^= (1LL * t * ans);
            if(l > r){
                swap(l, r);
            }
            if(r - l + 1 < k){
                ans = 0;
                cout << "0\n";
                continue;
            }
            int res = 0;
            for(int j = 0; j < sz_add; j++){
                res += (intersect(l, r, L[add[j]], R[add[j]]) < k);
            }
            for(int j = 0; j < sz_del; j++){
                res -= (intersect(l, r, L[del[j]], R[del[j]]) < k);
            }
            int pos = lower_bound(a, a + m, make_pair(k, 0)) - a;
            res += pos;
            res += calcL(pos, m - 1, r - k + 1);
            res += calcR(pos, m - 1, l + k - 1);
            ans = alive - res;
            cout << ans << "\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 8 ms 632 KB Output is correct
6 Correct 9 ms 632 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 8 ms 504 KB Output is correct
9 Correct 7 ms 504 KB Output is correct
10 Correct 7 ms 632 KB Output is correct
11 Correct 10 ms 504 KB Output is correct
12 Correct 10 ms 504 KB Output is correct
13 Correct 8 ms 632 KB Output is correct
14 Correct 7 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 7 ms 632 KB Output is correct
19 Correct 7 ms 504 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1708 ms 1952 KB Output is correct
2 Correct 1692 ms 4764 KB Output is correct
3 Correct 1699 ms 4588 KB Output is correct
4 Correct 1754 ms 4600 KB Output is correct
5 Correct 1728 ms 4976 KB Output is correct
6 Correct 1624 ms 4984 KB Output is correct
7 Correct 1739 ms 4600 KB Output is correct
8 Correct 1723 ms 4728 KB Output is correct
9 Correct 1709 ms 4600 KB Output is correct
10 Correct 952 ms 4288 KB Output is correct
11 Correct 1131 ms 4324 KB Output is correct
12 Correct 1815 ms 4768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 760 KB Output is correct
2 Correct 51 ms 2660 KB Output is correct
3 Correct 82 ms 2660 KB Output is correct
4 Correct 51 ms 2592 KB Output is correct
5 Correct 1951 ms 4624 KB Output is correct
6 Correct 1876 ms 4428 KB Output is correct
7 Correct 1922 ms 4472 KB Output is correct
8 Correct 1741 ms 5148 KB Output is correct
9 Correct 1665 ms 5044 KB Output is correct
10 Correct 1607 ms 4384 KB Output is correct
11 Correct 226 ms 2808 KB Output is correct
12 Correct 1611 ms 4368 KB Output is correct
13 Correct 1465 ms 4088 KB Output is correct
14 Correct 976 ms 3448 KB Output is correct
15 Correct 855 ms 3388 KB Output is correct
16 Correct 624 ms 3256 KB Output is correct
17 Correct 1908 ms 4476 KB Output is correct
18 Correct 1929 ms 4472 KB Output is correct
19 Correct 1930 ms 4344 KB Output is correct
20 Correct 1913 ms 4436 KB Output is correct
21 Correct 302 ms 3100 KB Output is correct
22 Correct 1156 ms 3704 KB Output is correct
23 Correct 1395 ms 3960 KB Output is correct
24 Correct 1214 ms 3832 KB Output is correct
25 Correct 61 ms 2680 KB Output is correct
26 Correct 53 ms 2552 KB Output is correct
27 Correct 64 ms 2640 KB Output is correct
28 Correct 55 ms 2680 KB Output is correct
29 Correct 1444 ms 4060 KB Output is correct
30 Correct 1480 ms 4216 KB Output is correct
31 Correct 1678 ms 5152 KB Output is correct
32 Correct 1612 ms 4472 KB Output is correct
33 Correct 1480 ms 4344 KB Output is correct
34 Correct 802 ms 3420 KB Output is correct
35 Correct 1323 ms 3960 KB Output is correct
36 Correct 1543 ms 4332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 760 KB Output is correct
2 Correct 51 ms 2808 KB Output is correct
3 Correct 52 ms 2808 KB Output is correct
4 Correct 54 ms 2808 KB Output is correct
5 Correct 1833 ms 4768 KB Output is correct
6 Correct 711 ms 4136 KB Output is correct
7 Correct 1782 ms 5036 KB Output is correct
8 Correct 946 ms 4188 KB Output is correct
9 Correct 1069 ms 3856 KB Output is correct
10 Correct 1578 ms 4564 KB Output is correct
11 Correct 499 ms 3448 KB Output is correct
12 Correct 1634 ms 5240 KB Output is correct
13 Correct 1427 ms 4444 KB Output is correct
14 Correct 980 ms 3836 KB Output is correct
15 Correct 1641 ms 5172 KB Output is correct
16 Correct 1504 ms 4292 KB Output is correct
17 Correct 1709 ms 4704 KB Output is correct
18 Correct 1705 ms 4860 KB Output is correct
19 Correct 1709 ms 4600 KB Output is correct
20 Correct 1703 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 8 ms 632 KB Output is correct
6 Correct 9 ms 632 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 8 ms 504 KB Output is correct
9 Correct 7 ms 504 KB Output is correct
10 Correct 7 ms 632 KB Output is correct
11 Correct 10 ms 504 KB Output is correct
12 Correct 10 ms 504 KB Output is correct
13 Correct 8 ms 632 KB Output is correct
14 Correct 7 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 7 ms 632 KB Output is correct
19 Correct 7 ms 504 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
21 Correct 1708 ms 1952 KB Output is correct
22 Correct 1692 ms 4764 KB Output is correct
23 Correct 1699 ms 4588 KB Output is correct
24 Correct 1754 ms 4600 KB Output is correct
25 Correct 1728 ms 4976 KB Output is correct
26 Correct 1624 ms 4984 KB Output is correct
27 Correct 1739 ms 4600 KB Output is correct
28 Correct 1723 ms 4728 KB Output is correct
29 Correct 1709 ms 4600 KB Output is correct
30 Correct 952 ms 4288 KB Output is correct
31 Correct 1131 ms 4324 KB Output is correct
32 Correct 1815 ms 4768 KB Output is correct
33 Correct 50 ms 760 KB Output is correct
34 Correct 51 ms 2808 KB Output is correct
35 Correct 52 ms 2808 KB Output is correct
36 Correct 54 ms 2808 KB Output is correct
37 Correct 1833 ms 4768 KB Output is correct
38 Correct 711 ms 4136 KB Output is correct
39 Correct 1782 ms 5036 KB Output is correct
40 Correct 946 ms 4188 KB Output is correct
41 Correct 1069 ms 3856 KB Output is correct
42 Correct 1578 ms 4564 KB Output is correct
43 Correct 499 ms 3448 KB Output is correct
44 Correct 1634 ms 5240 KB Output is correct
45 Correct 1427 ms 4444 KB Output is correct
46 Correct 980 ms 3836 KB Output is correct
47 Correct 1641 ms 5172 KB Output is correct
48 Correct 1504 ms 4292 KB Output is correct
49 Correct 1709 ms 4704 KB Output is correct
50 Correct 1705 ms 4860 KB Output is correct
51 Correct 1709 ms 4600 KB Output is correct
52 Correct 1703 ms 4728 KB Output is correct
53 Correct 56 ms 2936 KB Output is correct
54 Correct 56 ms 2828 KB Output is correct
55 Correct 51 ms 2936 KB Output is correct
56 Correct 51 ms 2812 KB Output is correct
57 Correct 1344 ms 4596 KB Output is correct
58 Correct 481 ms 4088 KB Output is correct
59 Correct 1773 ms 4828 KB Output is correct
60 Correct 488 ms 4344 KB Output is correct
61 Correct 1470 ms 4344 KB Output is correct
62 Correct 1621 ms 4856 KB Output is correct
63 Correct 1626 ms 5176 KB Output is correct
64 Correct 1659 ms 5040 KB Output is correct
65 Correct 675 ms 3448 KB Output is correct
66 Correct 572 ms 3336 KB Output is correct
67 Correct 1489 ms 4460 KB Output is correct
68 Correct 1337 ms 4088 KB Output is correct
69 Correct 1708 ms 4752 KB Output is correct
70 Correct 1679 ms 4648 KB Output is correct
71 Correct 1700 ms 4600 KB Output is correct
72 Correct 1716 ms 4728 KB Output is correct
73 Correct 802 ms 3580 KB Output is correct
74 Correct 1299 ms 4088 KB Output is correct
75 Correct 1609 ms 5084 KB Output is correct
76 Correct 1634 ms 4952 KB Output is correct
77 Correct 55 ms 2936 KB Output is correct
78 Correct 51 ms 2808 KB Output is correct
79 Correct 56 ms 2936 KB Output is correct
80 Correct 52 ms 2912 KB Output is correct
81 Correct 1284 ms 4240 KB Output is correct
82 Correct 788 ms 3576 KB Output is correct
83 Correct 458 ms 3328 KB Output is correct
84 Correct 1261 ms 4088 KB Output is correct
85 Correct 1535 ms 4608 KB Output is correct
86 Correct 1559 ms 4628 KB Output is correct
87 Correct 1056 ms 3704 KB Output is correct
88 Correct 494 ms 3108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 8 ms 632 KB Output is correct
6 Correct 9 ms 632 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 8 ms 504 KB Output is correct
9 Correct 7 ms 504 KB Output is correct
10 Correct 7 ms 632 KB Output is correct
11 Correct 10 ms 504 KB Output is correct
12 Correct 10 ms 504 KB Output is correct
13 Correct 8 ms 632 KB Output is correct
14 Correct 7 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 7 ms 504 KB Output is correct
18 Correct 7 ms 632 KB Output is correct
19 Correct 7 ms 504 KB Output is correct
20 Correct 7 ms 504 KB Output is correct
21 Correct 1708 ms 1952 KB Output is correct
22 Correct 1692 ms 4764 KB Output is correct
23 Correct 1699 ms 4588 KB Output is correct
24 Correct 1754 ms 4600 KB Output is correct
25 Correct 1728 ms 4976 KB Output is correct
26 Correct 1624 ms 4984 KB Output is correct
27 Correct 1739 ms 4600 KB Output is correct
28 Correct 1723 ms 4728 KB Output is correct
29 Correct 1709 ms 4600 KB Output is correct
30 Correct 952 ms 4288 KB Output is correct
31 Correct 1131 ms 4324 KB Output is correct
32 Correct 1815 ms 4768 KB Output is correct
33 Correct 59 ms 760 KB Output is correct
34 Correct 51 ms 2660 KB Output is correct
35 Correct 82 ms 2660 KB Output is correct
36 Correct 51 ms 2592 KB Output is correct
37 Correct 1951 ms 4624 KB Output is correct
38 Correct 1876 ms 4428 KB Output is correct
39 Correct 1922 ms 4472 KB Output is correct
40 Correct 1741 ms 5148 KB Output is correct
41 Correct 1665 ms 5044 KB Output is correct
42 Correct 1607 ms 4384 KB Output is correct
43 Correct 226 ms 2808 KB Output is correct
44 Correct 1611 ms 4368 KB Output is correct
45 Correct 1465 ms 4088 KB Output is correct
46 Correct 976 ms 3448 KB Output is correct
47 Correct 855 ms 3388 KB Output is correct
48 Correct 624 ms 3256 KB Output is correct
49 Correct 1908 ms 4476 KB Output is correct
50 Correct 1929 ms 4472 KB Output is correct
51 Correct 1930 ms 4344 KB Output is correct
52 Correct 1913 ms 4436 KB Output is correct
53 Correct 302 ms 3100 KB Output is correct
54 Correct 1156 ms 3704 KB Output is correct
55 Correct 1395 ms 3960 KB Output is correct
56 Correct 1214 ms 3832 KB Output is correct
57 Correct 61 ms 2680 KB Output is correct
58 Correct 53 ms 2552 KB Output is correct
59 Correct 64 ms 2640 KB Output is correct
60 Correct 55 ms 2680 KB Output is correct
61 Correct 1444 ms 4060 KB Output is correct
62 Correct 1480 ms 4216 KB Output is correct
63 Correct 1678 ms 5152 KB Output is correct
64 Correct 1612 ms 4472 KB Output is correct
65 Correct 1480 ms 4344 KB Output is correct
66 Correct 802 ms 3420 KB Output is correct
67 Correct 1323 ms 3960 KB Output is correct
68 Correct 1543 ms 4332 KB Output is correct
69 Correct 50 ms 760 KB Output is correct
70 Correct 51 ms 2808 KB Output is correct
71 Correct 52 ms 2808 KB Output is correct
72 Correct 54 ms 2808 KB Output is correct
73 Correct 1833 ms 4768 KB Output is correct
74 Correct 711 ms 4136 KB Output is correct
75 Correct 1782 ms 5036 KB Output is correct
76 Correct 946 ms 4188 KB Output is correct
77 Correct 1069 ms 3856 KB Output is correct
78 Correct 1578 ms 4564 KB Output is correct
79 Correct 499 ms 3448 KB Output is correct
80 Correct 1634 ms 5240 KB Output is correct
81 Correct 1427 ms 4444 KB Output is correct
82 Correct 980 ms 3836 KB Output is correct
83 Correct 1641 ms 5172 KB Output is correct
84 Correct 1504 ms 4292 KB Output is correct
85 Correct 1709 ms 4704 KB Output is correct
86 Correct 1705 ms 4860 KB Output is correct
87 Correct 1709 ms 4600 KB Output is correct
88 Correct 1703 ms 4728 KB Output is correct
89 Correct 56 ms 2936 KB Output is correct
90 Correct 56 ms 2828 KB Output is correct
91 Correct 51 ms 2936 KB Output is correct
92 Correct 51 ms 2812 KB Output is correct
93 Correct 1344 ms 4596 KB Output is correct
94 Correct 481 ms 4088 KB Output is correct
95 Correct 1773 ms 4828 KB Output is correct
96 Correct 488 ms 4344 KB Output is correct
97 Correct 1470 ms 4344 KB Output is correct
98 Correct 1621 ms 4856 KB Output is correct
99 Correct 1626 ms 5176 KB Output is correct
100 Correct 1659 ms 5040 KB Output is correct
101 Correct 675 ms 3448 KB Output is correct
102 Correct 572 ms 3336 KB Output is correct
103 Correct 1489 ms 4460 KB Output is correct
104 Correct 1337 ms 4088 KB Output is correct
105 Correct 1708 ms 4752 KB Output is correct
106 Correct 1679 ms 4648 KB Output is correct
107 Correct 1700 ms 4600 KB Output is correct
108 Correct 1716 ms 4728 KB Output is correct
109 Correct 802 ms 3580 KB Output is correct
110 Correct 1299 ms 4088 KB Output is correct
111 Correct 1609 ms 5084 KB Output is correct
112 Correct 1634 ms 4952 KB Output is correct
113 Correct 55 ms 2936 KB Output is correct
114 Correct 51 ms 2808 KB Output is correct
115 Correct 56 ms 2936 KB Output is correct
116 Correct 52 ms 2912 KB Output is correct
117 Correct 1284 ms 4240 KB Output is correct
118 Correct 788 ms 3576 KB Output is correct
119 Correct 458 ms 3328 KB Output is correct
120 Correct 1261 ms 4088 KB Output is correct
121 Correct 1535 ms 4608 KB Output is correct
122 Correct 1559 ms 4628 KB Output is correct
123 Correct 1056 ms 3704 KB Output is correct
124 Correct 494 ms 3108 KB Output is correct
125 Correct 118 ms 5432 KB Output is correct
126 Correct 118 ms 5416 KB Output is correct
127 Correct 142 ms 5368 KB Output is correct
128 Correct 122 ms 5368 KB Output is correct
129 Correct 111 ms 5424 KB Output is correct
130 Correct 127 ms 5240 KB Output is correct
131 Correct 2113 ms 7944 KB Output is correct
132 Execution timed out 5004 ms 8064 KB Time limit exceeded
133 Halted 0 ms 0 KB -