Submission #154961

# Submission time Handle Problem Language Result Execution time Memory
154961 2019-09-25T17:03:17 Z andrew Segments (IZhO18_segments) C++17
75 / 100
5000 ms 14268 KB
#include <bits/stdc++.h>

#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)

using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;
const ll inf = 3e18;
int buben = 1000;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

template <typename T> void vout(T s){cout << s << endl;exit(0);}

pii a[N + 3];
int stn;

int WD[N + 3];
int Wstn;

pii b[N + 3];
int Stn;

bool f_deleted[N + 3], will_deleted[N + 3];

int luk, ruk;

ll Len_Block, Len;

vector <ll> V[501], V1[501];

void clr(){
    if(!Len)return;
    for(int i = 0; i < Len; i++){
        V[i / Len_Block].clear();
        V1[i / Len_Block].clear();
    }
    Len = 0;
    Len_Block = 0;
}

void build(int Nt){
    Len_Block = 1;
    Len = Nt;
    while(sqr(Len_Block) < Len)Len_Block++;

    for(int i = 0; i < Len; i++){
        V[i / Len_Block].p_b(a[i + 1].se);
        V1[i / Len_Block].p_b(a[i + 1].se - a[i + 1].fi + 1);
    }
    for(int i = 0; i <= (Len - 1) / Len_Block; i++){
        sort(all(V[i]));
        sort(all(V1[i]));
    }
}

int Val;

int V_more(int l, int r){
    l--, r--;
    int ans = 0;
    for(int i = l; i <= r;){
        if(i % Len_Block == 0 && i + Len_Block - 1 <= r){
            ans += (int)V[i / Len_Block].size() - (lower_bound(all(V[i / Len_Block]), Val) - V[i / Len_Block].begin());
            i += Len_Block;
        }else{
            if(a[i + 1].se >= Val)ans++;
            i++;
        }
    }
    return ans;
}

int V1_more(int l, int r){
    l--, r--;
    int ans = 0;
    for(int i = l; i <= r;){
        if(i % Len_Block == 0 && i + Len_Block - 1 <= r){
            ans += (int)V1[i / Len_Block].size() - (lower_bound(all(V1[i / Len_Block]), Val) - V1[i / Len_Block].begin());
            i += Len_Block;
        }else{
            if(a[i + 1].se - a[i + 1].fi + 1 >= Val)ans++;
            i++;
        }
    }
    return ans;
}


struct qry{
    short t;
    int a, b, c, Id;
};

qry c[N + 3];

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    int n, t;
    cin >> n >> t;


    for(int i = 1; i <= n; i++){
        cin >> c[i].t;
        if(c[i].t == 1){
            cin >> c[i].a >> c[i].b;
        }else if(c[i].t == 2){
            cin >> c[i].a;
        }else{
            cin >> c[i].a >> c[i].b >> c[i].c;
        }
    }

    int l = 1, last_ans = 0, ans = 0, Le, Ri, L1, R1, L, R, mid, k, i, j;
    for(i = 1; i <= n; i++){
        if(i % buben == 0){
            Wstn = 0;
            for(j = i; j <= min(n, i + buben - 1); j++){
                if(c[j].t == 2){
                    will_deleted[c[j].a] = 1;
                    if(c[j].a <= Stn){
                        Wstn++;
                        WD[Wstn] = c[j].a;
                    }
                }
            }
            clr();
            stn = 0;
            for(j = 1; j <= Stn; j++)if(!will_deleted[j]){
                stn++;
                a[stn] = b[j];
            }

            if(stn){
                sort(a + 1, a + stn + 1);
                build(stn);
            }
            l = i;
        }

        if(c[i].t == 1){
            c[i].a ^= t * last_ans;
            c[i].b ^= t * last_ans;
            if(c[i].a > c[i].b)swap(c[i].a, c[i].b);
            Stn++;
            c[i].Id = Stn;
            b[Stn] = {c[i].a, c[i].b};

        }else if(c[i].t == 2){
            f_deleted[c[i].a] = 1;
            will_deleted[c[i].a] = 1;
        }else if(c[i].t == 3){
            c[i].a ^= t * last_ans;
            c[i].b ^= t * last_ans;
            if(c[i].a > c[i].b)swap(c[i].a, c[i].b);
            if(c[i].b - c[i].a + 1 < c[i].c){
                cout << "0\n";
                last_ans = 0;
                continue;
            }
            ans = 0;
            k = c[i].c;
            for(j = l; j < i; j++)if(c[j].t == 1 && !f_deleted[c[j].Id]){
                if(min(c[i].b, c[j].b) - max(c[i].a, c[j].a) + 1 >= c[i].c || c[i].c == 0)ans++;
            }

            for(j = 1; j <= Wstn; j++)if(!f_deleted[WD[j]]){
                if(min(c[i].b, b[WD[j]].se) - max(c[i].a, b[WD[j]].fi) + 1 >= c[i].c || c[i].c == 0)ans++;
            }

            if(!k)ans += stn;
            else{
                if(stn){
                    L = 1, R = stn;
                    while(L < R){
                        mid = (L + R) >> 1;
                        if(a[mid].fi < c[i].a)L = mid + 1; else R = mid;
                    }
                    if(a[L].fi < c[i].a)L++;
                    if(L != 1){
                        Val = k + c[i].a - 1;
                        ans += V_more(1, L - 1);
                    }
                    Le = L;
                    L = 1, R = stn;
                    while(L < R){
                        mid = (L + R) >> 1;
                        if(a[mid].fi <= c[i].b - k + 1)L = mid + 1; else R = mid;
                    }
                    if(a[L].fi <= c[i].b - k + 1)L++;
                    if(Le < L){
                        Val = k;
                        ans += V1_more(Le, L - 1);
                    }
                }

            }
            cout << ans << "\n";
            last_ans = ans;
        }

    }

    return 0;
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:129:43: warning: unused variable 'Ri' [-Wunused-variable]
     int l = 1, last_ans = 0, ans = 0, Le, Ri, L1, R1, L, R, mid, k, i, j;
                                           ^~
segments.cpp:129:47: warning: unused variable 'L1' [-Wunused-variable]
     int l = 1, last_ans = 0, ans = 0, Le, Ri, L1, R1, L, R, mid, k, i, j;
                                               ^~
segments.cpp:129:51: warning: unused variable 'R1' [-Wunused-variable]
     int l = 1, last_ans = 0, ans = 0, Le, Ri, L1, R1, L, R, mid, k, i, j;
                                                   ^~
# 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 7 ms 632 KB Output is correct
4 Correct 7 ms 632 KB Output is correct
5 Correct 10 ms 760 KB Output is correct
6 Correct 12 ms 760 KB Output is correct
7 Correct 11 ms 632 KB Output is correct
8 Correct 11 ms 632 KB Output is correct
9 Correct 12 ms 732 KB Output is correct
10 Correct 8 ms 760 KB Output is correct
11 Correct 16 ms 760 KB Output is correct
12 Correct 16 ms 888 KB Output is correct
13 Correct 9 ms 824 KB Output is correct
14 Correct 11 ms 632 KB Output is correct
15 Correct 6 ms 632 KB Output is correct
16 Correct 7 ms 632 KB Output is correct
17 Correct 12 ms 632 KB Output is correct
18 Correct 9 ms 760 KB Output is correct
19 Correct 12 ms 632 KB Output is correct
20 Correct 13 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1812 ms 7232 KB Output is correct
2 Correct 1798 ms 7208 KB Output is correct
3 Correct 1808 ms 7232 KB Output is correct
4 Correct 1822 ms 7076 KB Output is correct
5 Correct 1357 ms 8872 KB Output is correct
6 Correct 1275 ms 8776 KB Output is correct
7 Correct 1808 ms 7148 KB Output is correct
8 Correct 1812 ms 7120 KB Output is correct
9 Correct 1807 ms 7336 KB Output is correct
10 Correct 1252 ms 6776 KB Output is correct
11 Correct 1467 ms 6916 KB Output is correct
12 Correct 1778 ms 8484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 4740 KB Output is correct
2 Correct 99 ms 4608 KB Output is correct
3 Correct 134 ms 4600 KB Output is correct
4 Correct 102 ms 4660 KB Output is correct
5 Correct 1743 ms 8228 KB Output is correct
6 Correct 1808 ms 7052 KB Output is correct
7 Correct 1798 ms 8080 KB Output is correct
8 Correct 1327 ms 8756 KB Output is correct
9 Correct 1277 ms 8676 KB Output is correct
10 Correct 1354 ms 6892 KB Output is correct
11 Correct 303 ms 4728 KB Output is correct
12 Correct 1344 ms 8044 KB Output is correct
13 Correct 1333 ms 6708 KB Output is correct
14 Correct 1008 ms 6008 KB Output is correct
15 Correct 944 ms 5736 KB Output is correct
16 Correct 739 ms 5220 KB Output is correct
17 Correct 1821 ms 6796 KB Output is correct
18 Correct 1797 ms 6880 KB Output is correct
19 Correct 1800 ms 6864 KB Output is correct
20 Correct 1794 ms 6744 KB Output is correct
21 Correct 382 ms 4984 KB Output is correct
22 Correct 1114 ms 6116 KB Output is correct
23 Correct 1236 ms 6472 KB Output is correct
24 Correct 1150 ms 6116 KB Output is correct
25 Correct 119 ms 4728 KB Output is correct
26 Correct 104 ms 4728 KB Output is correct
27 Correct 116 ms 4600 KB Output is correct
28 Correct 107 ms 4600 KB Output is correct
29 Correct 1280 ms 6648 KB Output is correct
30 Correct 1296 ms 6648 KB Output is correct
31 Correct 1289 ms 8748 KB Output is correct
32 Correct 1368 ms 7080 KB Output is correct
33 Correct 1366 ms 6864 KB Output is correct
34 Correct 905 ms 5844 KB Output is correct
35 Correct 1275 ms 6524 KB Output is correct
36 Correct 1368 ms 6756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 4880 KB Output is correct
2 Correct 99 ms 4772 KB Output is correct
3 Correct 103 ms 4944 KB Output is correct
4 Correct 109 ms 4856 KB Output is correct
5 Correct 1682 ms 8632 KB Output is correct
6 Correct 1038 ms 6416 KB Output is correct
7 Correct 1582 ms 8576 KB Output is correct
8 Correct 1293 ms 6920 KB Output is correct
9 Correct 1072 ms 6264 KB Output is correct
10 Correct 1351 ms 8260 KB Output is correct
11 Correct 612 ms 5484 KB Output is correct
12 Correct 1238 ms 8788 KB Output is correct
13 Correct 1369 ms 6784 KB Output is correct
14 Correct 1078 ms 6220 KB Output is correct
15 Correct 1299 ms 8640 KB Output is correct
16 Correct 1376 ms 6868 KB Output is correct
17 Correct 1807 ms 7116 KB Output is correct
18 Correct 1801 ms 7216 KB Output is correct
19 Correct 1799 ms 7148 KB Output is correct
20 Correct 1808 ms 7108 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 7 ms 632 KB Output is correct
4 Correct 7 ms 632 KB Output is correct
5 Correct 10 ms 760 KB Output is correct
6 Correct 12 ms 760 KB Output is correct
7 Correct 11 ms 632 KB Output is correct
8 Correct 11 ms 632 KB Output is correct
9 Correct 12 ms 732 KB Output is correct
10 Correct 8 ms 760 KB Output is correct
11 Correct 16 ms 760 KB Output is correct
12 Correct 16 ms 888 KB Output is correct
13 Correct 9 ms 824 KB Output is correct
14 Correct 11 ms 632 KB Output is correct
15 Correct 6 ms 632 KB Output is correct
16 Correct 7 ms 632 KB Output is correct
17 Correct 12 ms 632 KB Output is correct
18 Correct 9 ms 760 KB Output is correct
19 Correct 12 ms 632 KB Output is correct
20 Correct 13 ms 632 KB Output is correct
21 Correct 1812 ms 7232 KB Output is correct
22 Correct 1798 ms 7208 KB Output is correct
23 Correct 1808 ms 7232 KB Output is correct
24 Correct 1822 ms 7076 KB Output is correct
25 Correct 1357 ms 8872 KB Output is correct
26 Correct 1275 ms 8776 KB Output is correct
27 Correct 1808 ms 7148 KB Output is correct
28 Correct 1812 ms 7120 KB Output is correct
29 Correct 1807 ms 7336 KB Output is correct
30 Correct 1252 ms 6776 KB Output is correct
31 Correct 1467 ms 6916 KB Output is correct
32 Correct 1778 ms 8484 KB Output is correct
33 Correct 97 ms 4880 KB Output is correct
34 Correct 99 ms 4772 KB Output is correct
35 Correct 103 ms 4944 KB Output is correct
36 Correct 109 ms 4856 KB Output is correct
37 Correct 1682 ms 8632 KB Output is correct
38 Correct 1038 ms 6416 KB Output is correct
39 Correct 1582 ms 8576 KB Output is correct
40 Correct 1293 ms 6920 KB Output is correct
41 Correct 1072 ms 6264 KB Output is correct
42 Correct 1351 ms 8260 KB Output is correct
43 Correct 612 ms 5484 KB Output is correct
44 Correct 1238 ms 8788 KB Output is correct
45 Correct 1369 ms 6784 KB Output is correct
46 Correct 1078 ms 6220 KB Output is correct
47 Correct 1299 ms 8640 KB Output is correct
48 Correct 1376 ms 6868 KB Output is correct
49 Correct 1807 ms 7116 KB Output is correct
50 Correct 1801 ms 7216 KB Output is correct
51 Correct 1799 ms 7148 KB Output is correct
52 Correct 1808 ms 7108 KB Output is correct
53 Correct 110 ms 4816 KB Output is correct
54 Correct 108 ms 4856 KB Output is correct
55 Correct 99 ms 4856 KB Output is correct
56 Correct 102 ms 4844 KB Output is correct
57 Correct 1577 ms 6820 KB Output is correct
58 Correct 805 ms 6140 KB Output is correct
59 Correct 1818 ms 7208 KB Output is correct
60 Correct 723 ms 6196 KB Output is correct
61 Correct 1330 ms 6788 KB Output is correct
62 Correct 1311 ms 8628 KB Output is correct
63 Correct 1265 ms 8872 KB Output is correct
64 Correct 1302 ms 8640 KB Output is correct
65 Correct 822 ms 5740 KB Output is correct
66 Correct 731 ms 5400 KB Output is correct
67 Correct 1383 ms 6876 KB Output is correct
68 Correct 1299 ms 6648 KB Output is correct
69 Correct 1802 ms 7276 KB Output is correct
70 Correct 1813 ms 7144 KB Output is correct
71 Correct 1809 ms 7144 KB Output is correct
72 Correct 1805 ms 7236 KB Output is correct
73 Correct 865 ms 6104 KB Output is correct
74 Correct 1232 ms 6636 KB Output is correct
75 Correct 1216 ms 8788 KB Output is correct
76 Correct 1257 ms 8904 KB Output is correct
77 Correct 106 ms 4860 KB Output is correct
78 Correct 101 ms 4892 KB Output is correct
79 Correct 110 ms 4984 KB Output is correct
80 Correct 101 ms 4888 KB Output is correct
81 Correct 1200 ms 6596 KB Output is correct
82 Correct 874 ms 6008 KB Output is correct
83 Correct 581 ms 5368 KB Output is correct
84 Correct 1226 ms 6528 KB Output is correct
85 Correct 1384 ms 7064 KB Output is correct
86 Correct 1403 ms 7048 KB Output is correct
87 Correct 1136 ms 6212 KB Output is correct
88 Correct 646 ms 5368 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 7 ms 632 KB Output is correct
4 Correct 7 ms 632 KB Output is correct
5 Correct 10 ms 760 KB Output is correct
6 Correct 12 ms 760 KB Output is correct
7 Correct 11 ms 632 KB Output is correct
8 Correct 11 ms 632 KB Output is correct
9 Correct 12 ms 732 KB Output is correct
10 Correct 8 ms 760 KB Output is correct
11 Correct 16 ms 760 KB Output is correct
12 Correct 16 ms 888 KB Output is correct
13 Correct 9 ms 824 KB Output is correct
14 Correct 11 ms 632 KB Output is correct
15 Correct 6 ms 632 KB Output is correct
16 Correct 7 ms 632 KB Output is correct
17 Correct 12 ms 632 KB Output is correct
18 Correct 9 ms 760 KB Output is correct
19 Correct 12 ms 632 KB Output is correct
20 Correct 13 ms 632 KB Output is correct
21 Correct 1812 ms 7232 KB Output is correct
22 Correct 1798 ms 7208 KB Output is correct
23 Correct 1808 ms 7232 KB Output is correct
24 Correct 1822 ms 7076 KB Output is correct
25 Correct 1357 ms 8872 KB Output is correct
26 Correct 1275 ms 8776 KB Output is correct
27 Correct 1808 ms 7148 KB Output is correct
28 Correct 1812 ms 7120 KB Output is correct
29 Correct 1807 ms 7336 KB Output is correct
30 Correct 1252 ms 6776 KB Output is correct
31 Correct 1467 ms 6916 KB Output is correct
32 Correct 1778 ms 8484 KB Output is correct
33 Correct 115 ms 4740 KB Output is correct
34 Correct 99 ms 4608 KB Output is correct
35 Correct 134 ms 4600 KB Output is correct
36 Correct 102 ms 4660 KB Output is correct
37 Correct 1743 ms 8228 KB Output is correct
38 Correct 1808 ms 7052 KB Output is correct
39 Correct 1798 ms 8080 KB Output is correct
40 Correct 1327 ms 8756 KB Output is correct
41 Correct 1277 ms 8676 KB Output is correct
42 Correct 1354 ms 6892 KB Output is correct
43 Correct 303 ms 4728 KB Output is correct
44 Correct 1344 ms 8044 KB Output is correct
45 Correct 1333 ms 6708 KB Output is correct
46 Correct 1008 ms 6008 KB Output is correct
47 Correct 944 ms 5736 KB Output is correct
48 Correct 739 ms 5220 KB Output is correct
49 Correct 1821 ms 6796 KB Output is correct
50 Correct 1797 ms 6880 KB Output is correct
51 Correct 1800 ms 6864 KB Output is correct
52 Correct 1794 ms 6744 KB Output is correct
53 Correct 382 ms 4984 KB Output is correct
54 Correct 1114 ms 6116 KB Output is correct
55 Correct 1236 ms 6472 KB Output is correct
56 Correct 1150 ms 6116 KB Output is correct
57 Correct 119 ms 4728 KB Output is correct
58 Correct 104 ms 4728 KB Output is correct
59 Correct 116 ms 4600 KB Output is correct
60 Correct 107 ms 4600 KB Output is correct
61 Correct 1280 ms 6648 KB Output is correct
62 Correct 1296 ms 6648 KB Output is correct
63 Correct 1289 ms 8748 KB Output is correct
64 Correct 1368 ms 7080 KB Output is correct
65 Correct 1366 ms 6864 KB Output is correct
66 Correct 905 ms 5844 KB Output is correct
67 Correct 1275 ms 6524 KB Output is correct
68 Correct 1368 ms 6756 KB Output is correct
69 Correct 97 ms 4880 KB Output is correct
70 Correct 99 ms 4772 KB Output is correct
71 Correct 103 ms 4944 KB Output is correct
72 Correct 109 ms 4856 KB Output is correct
73 Correct 1682 ms 8632 KB Output is correct
74 Correct 1038 ms 6416 KB Output is correct
75 Correct 1582 ms 8576 KB Output is correct
76 Correct 1293 ms 6920 KB Output is correct
77 Correct 1072 ms 6264 KB Output is correct
78 Correct 1351 ms 8260 KB Output is correct
79 Correct 612 ms 5484 KB Output is correct
80 Correct 1238 ms 8788 KB Output is correct
81 Correct 1369 ms 6784 KB Output is correct
82 Correct 1078 ms 6220 KB Output is correct
83 Correct 1299 ms 8640 KB Output is correct
84 Correct 1376 ms 6868 KB Output is correct
85 Correct 1807 ms 7116 KB Output is correct
86 Correct 1801 ms 7216 KB Output is correct
87 Correct 1799 ms 7148 KB Output is correct
88 Correct 1808 ms 7108 KB Output is correct
89 Correct 110 ms 4816 KB Output is correct
90 Correct 108 ms 4856 KB Output is correct
91 Correct 99 ms 4856 KB Output is correct
92 Correct 102 ms 4844 KB Output is correct
93 Correct 1577 ms 6820 KB Output is correct
94 Correct 805 ms 6140 KB Output is correct
95 Correct 1818 ms 7208 KB Output is correct
96 Correct 723 ms 6196 KB Output is correct
97 Correct 1330 ms 6788 KB Output is correct
98 Correct 1311 ms 8628 KB Output is correct
99 Correct 1265 ms 8872 KB Output is correct
100 Correct 1302 ms 8640 KB Output is correct
101 Correct 822 ms 5740 KB Output is correct
102 Correct 731 ms 5400 KB Output is correct
103 Correct 1383 ms 6876 KB Output is correct
104 Correct 1299 ms 6648 KB Output is correct
105 Correct 1802 ms 7276 KB Output is correct
106 Correct 1813 ms 7144 KB Output is correct
107 Correct 1809 ms 7144 KB Output is correct
108 Correct 1805 ms 7236 KB Output is correct
109 Correct 865 ms 6104 KB Output is correct
110 Correct 1232 ms 6636 KB Output is correct
111 Correct 1216 ms 8788 KB Output is correct
112 Correct 1257 ms 8904 KB Output is correct
113 Correct 106 ms 4860 KB Output is correct
114 Correct 101 ms 4892 KB Output is correct
115 Correct 110 ms 4984 KB Output is correct
116 Correct 101 ms 4888 KB Output is correct
117 Correct 1200 ms 6596 KB Output is correct
118 Correct 874 ms 6008 KB Output is correct
119 Correct 581 ms 5368 KB Output is correct
120 Correct 1226 ms 6528 KB Output is correct
121 Correct 1384 ms 7064 KB Output is correct
122 Correct 1403 ms 7048 KB Output is correct
123 Correct 1136 ms 6212 KB Output is correct
124 Correct 646 ms 5368 KB Output is correct
125 Correct 219 ms 9276 KB Output is correct
126 Correct 222 ms 9388 KB Output is correct
127 Correct 252 ms 9380 KB Output is correct
128 Correct 229 ms 9336 KB Output is correct
129 Correct 205 ms 9336 KB Output is correct
130 Correct 231 ms 9496 KB Output is correct
131 Correct 2796 ms 12260 KB Output is correct
132 Execution timed out 5074 ms 14268 KB Time limit exceeded
133 Halted 0 ms 0 KB -