Submission #440736

# Submission time Handle Problem Language Result Execution time Memory
440736 2021-07-02T19:57:12 Z leaked Segments (IZhO18_segments) C++14
100 / 100
3061 ms 12620 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC opimize(-O3)
//#pragma GCC opimize(Ofast)
//#pragma GCC opimize(unroll-loops)
//#pragma GCC target("avx,avx2,popcnt,sse,sse2,sse3,sse4,abm,tune=native")
#define m_p make_pair
#define vec vector
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)x.size()
#define pw(x) (1LL<<x)
#define f first
#define s second

using namespace std;
using namespace __gnu_pbds;
typedef long double ld;
typedef pair<int,int> pii;
const int K=2000;
const int B=K;
const int N=2e5+4;
template <class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
int l[N],r[N];
bool used[N];
struct mine{
    vec<pii>ls;
    vec<pii>fck;vec<pii>fck2;
    vec<pii>nw;
    vec<int>st1[N/K+1];vec<int>st[N/K+1];
    void build(){
        for(int i=0;i<=(sz(ls)-1)/K;i++){
            st[i].clear();st1[i].clear();
        }
        for(int i=0;i<sz(ls);i++){
            st[i/K].pb(r[ls[i].s]-l[ls[i].s]+1);
            st1[i/K].pb(r[ls[i].s]);
        }
        for(int i=0;i<=(sz(ls)-1)/K;i++){
            sort(all(st[i]));
            sort(all(st1[i]));
        }
    }
    void add(int i){
        fck.pb({l[i],i});
        if(sz(fck)==K){
            for(auto &z : fck) ls.pb(z);
            fck.clear();sort(all(ls));
            build();
        }
    }
    void del(int i){
//        cout<<"BLYA"<<endl;
        fck2.pb({l[i],i});
        used[i]=1;
//        assert(sz(fck2)==1);
        if(sz(fck2)==K){
            assert(!sz(nw));
            for(auto &z : fck) ls.pb(z);
            fck.clear();sort(all(ls));
            for(auto &z : ls){
                if(!used[z.s]){
                    nw.pb(z);
//                    cerr<<"ALO "<<z.f<<' '<<z.s<<endl;
                }
            }
            swap(ls,nw);nw.clear();fck2.clear();
            build();
        }
    }
    int fnd(int x){
        int id=lower_bound(all(ls),m_p(x,-2))-ls.begin();
        return id;
    }
    int get1(int l1,int r1,int x){
        int ans=0;
        for(int i=l1/K;i<=r1/K;i++){
            int l2=i*B,r2=l2+B-1;
            if(l2>=l1 && r2<=r1){
                int lung=lower_bound(all(st1[i]),x)-st1[i].begin();
                ans+=B-lung;
            }
            else{
                l2=max(l1,l2);r2=min(r1,r2);
                for(int j=l2;j<=r2;j++){
                    int id=ls[j].s;
                    ans+=(r[id]>=x);
                }
            }
        }
        return ans;
    }
    int get(int l1,int r1,int x){
        int ans=0;
        for(int i=l1/K;i<=r1/K;i++){
            int l2=i*B,r2=l2+B-1;
            if(l2>=l1 && r2<=r1){
                int lung=lower_bound(all(st[i]),x)-st[i].begin();
                ans+=B-lung;
            }
            else{
                l2=max(l1,l2);r2=min(r1,r2);
                for(int j=l2;j<=r2;j++){
                    int id=ls[j].s;
                    ans+=((r[id]-l[id]+1)>=x);
                }
            }
        }
        return ans;
    }
}kek;
int u=1;
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int q,t;
    cin>>q>>t;
    ///fuck this shit
    int lstans=0;
    while(q--){
        int tp;
        cin>>tp;
        if(tp==1){
            int a,b;
            cin>>a>>b;
            a=(a^(lstans*t));
            b=(b^(lstans*t));
            if(a>b) swap(a,b);
            l[u]=a;r[u]=b;
            kek.add(u);
            u++;
        }
        else if(tp==2){
            int id;
            cin>>id;
            kek.del(id);
        }
        else{
            int a,b,k;
            cin>>a>>b>>k;
            a=(a^(lstans*t));
            b=(b^(lstans*t));
            if(a>b) swap(a,b);
            if(b-a+1<k){
                lstans=0;
                cout<<0<<'\n';
                continue;
            }
            int lf=a,rt=b;
            int l1=kek.fnd(lf),r1=kek.fnd(rt-k+2)-1;
            int ans=kek.get(l1,r1,k);
            ans+=kek.get1(0,l1-1,k+lf-1);
            for(auto &z : kek.fck){
                if(z.f>=lf && z.f<=(rt-k+1) && r[z.s]-l[z.s]+1>=k) ans++;
                else if(z.f<lf && r[z.s]>=k+lf-1) ans++;
            }
            for(auto &z : kek.fck2){
                if(z.f>=lf && z.f<=(rt-k+1) && r[z.s]-l[z.s]+1>=k) ans--;
                else if(z.f<lf && r[z.s]>=k+lf-1) ans--;
            }
            cout<<ans<<'\n';
            lstans=ans;
        }
    }
    return 0;
}
/*
5 1
1 1 2
1 3 5
3 2 3 1
2 1
3 0 3 1

*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 22 ms 364 KB Output is correct
4 Correct 21 ms 404 KB Output is correct
5 Correct 7 ms 460 KB Output is correct
6 Correct 19 ms 424 KB Output is correct
7 Correct 21 ms 332 KB Output is correct
8 Correct 11 ms 420 KB Output is correct
9 Correct 12 ms 332 KB Output is correct
10 Correct 5 ms 460 KB Output is correct
11 Correct 17 ms 416 KB Output is correct
12 Correct 14 ms 416 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 11 ms 432 KB Output is correct
15 Correct 23 ms 388 KB Output is correct
16 Correct 20 ms 396 KB Output is correct
17 Correct 17 ms 440 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 14 ms 332 KB Output is correct
20 Correct 14 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1152 ms 1748 KB Output is correct
2 Correct 1218 ms 1756 KB Output is correct
3 Correct 1149 ms 1792 KB Output is correct
4 Correct 766 ms 1816 KB Output is correct
5 Correct 505 ms 2748 KB Output is correct
6 Correct 502 ms 2664 KB Output is correct
7 Correct 1162 ms 1736 KB Output is correct
8 Correct 1149 ms 1884 KB Output is correct
9 Correct 1121 ms 1724 KB Output is correct
10 Correct 1099 ms 1308 KB Output is correct
11 Correct 952 ms 1312 KB Output is correct
12 Correct 598 ms 2348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 495 ms 808 KB Output is correct
2 Correct 491 ms 764 KB Output is correct
3 Correct 488 ms 836 KB Output is correct
4 Correct 493 ms 964 KB Output is correct
5 Correct 816 ms 2364 KB Output is correct
6 Correct 670 ms 2128 KB Output is correct
7 Correct 920 ms 2020 KB Output is correct
8 Correct 506 ms 2612 KB Output is correct
9 Correct 516 ms 4264 KB Output is correct
10 Correct 577 ms 3568 KB Output is correct
11 Correct 565 ms 960 KB Output is correct
12 Correct 611 ms 3504 KB Output is correct
13 Correct 562 ms 2620 KB Output is correct
14 Correct 590 ms 1860 KB Output is correct
15 Correct 536 ms 1824 KB Output is correct
16 Correct 552 ms 1448 KB Output is correct
17 Correct 547 ms 1768 KB Output is correct
18 Correct 1198 ms 1904 KB Output is correct
19 Correct 1228 ms 1852 KB Output is correct
20 Correct 546 ms 2044 KB Output is correct
21 Correct 593 ms 1196 KB Output is correct
22 Correct 654 ms 2100 KB Output is correct
23 Correct 605 ms 2464 KB Output is correct
24 Correct 648 ms 2372 KB Output is correct
25 Correct 496 ms 840 KB Output is correct
26 Correct 481 ms 788 KB Output is correct
27 Correct 495 ms 772 KB Output is correct
28 Correct 489 ms 776 KB Output is correct
29 Correct 644 ms 2496 KB Output is correct
30 Correct 654 ms 2496 KB Output is correct
31 Correct 489 ms 4096 KB Output is correct
32 Correct 575 ms 3596 KB Output is correct
33 Correct 550 ms 2652 KB Output is correct
34 Correct 550 ms 1892 KB Output is correct
35 Correct 554 ms 2356 KB Output is correct
36 Correct 541 ms 2740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 471 ms 728 KB Output is correct
2 Correct 470 ms 780 KB Output is correct
3 Correct 504 ms 716 KB Output is correct
4 Correct 480 ms 792 KB Output is correct
5 Correct 637 ms 2364 KB Output is correct
6 Correct 1342 ms 1220 KB Output is correct
7 Correct 623 ms 2360 KB Output is correct
8 Correct 782 ms 1340 KB Output is correct
9 Correct 633 ms 2004 KB Output is correct
10 Correct 553 ms 3792 KB Output is correct
11 Correct 597 ms 1472 KB Output is correct
12 Correct 485 ms 2780 KB Output is correct
13 Correct 557 ms 2596 KB Output is correct
14 Correct 573 ms 1816 KB Output is correct
15 Correct 499 ms 4140 KB Output is correct
16 Correct 571 ms 2748 KB Output is correct
17 Correct 1155 ms 1692 KB Output is correct
18 Correct 1137 ms 1856 KB Output is correct
19 Correct 1151 ms 1804 KB Output is correct
20 Correct 1128 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 22 ms 364 KB Output is correct
4 Correct 21 ms 404 KB Output is correct
5 Correct 7 ms 460 KB Output is correct
6 Correct 19 ms 424 KB Output is correct
7 Correct 21 ms 332 KB Output is correct
8 Correct 11 ms 420 KB Output is correct
9 Correct 12 ms 332 KB Output is correct
10 Correct 5 ms 460 KB Output is correct
11 Correct 17 ms 416 KB Output is correct
12 Correct 14 ms 416 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 11 ms 432 KB Output is correct
15 Correct 23 ms 388 KB Output is correct
16 Correct 20 ms 396 KB Output is correct
17 Correct 17 ms 440 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 14 ms 332 KB Output is correct
20 Correct 14 ms 332 KB Output is correct
21 Correct 1152 ms 1748 KB Output is correct
22 Correct 1218 ms 1756 KB Output is correct
23 Correct 1149 ms 1792 KB Output is correct
24 Correct 766 ms 1816 KB Output is correct
25 Correct 505 ms 2748 KB Output is correct
26 Correct 502 ms 2664 KB Output is correct
27 Correct 1162 ms 1736 KB Output is correct
28 Correct 1149 ms 1884 KB Output is correct
29 Correct 1121 ms 1724 KB Output is correct
30 Correct 1099 ms 1308 KB Output is correct
31 Correct 952 ms 1312 KB Output is correct
32 Correct 598 ms 2348 KB Output is correct
33 Correct 471 ms 728 KB Output is correct
34 Correct 470 ms 780 KB Output is correct
35 Correct 504 ms 716 KB Output is correct
36 Correct 480 ms 792 KB Output is correct
37 Correct 637 ms 2364 KB Output is correct
38 Correct 1342 ms 1220 KB Output is correct
39 Correct 623 ms 2360 KB Output is correct
40 Correct 782 ms 1340 KB Output is correct
41 Correct 633 ms 2004 KB Output is correct
42 Correct 553 ms 3792 KB Output is correct
43 Correct 597 ms 1472 KB Output is correct
44 Correct 485 ms 2780 KB Output is correct
45 Correct 557 ms 2596 KB Output is correct
46 Correct 573 ms 1816 KB Output is correct
47 Correct 499 ms 4140 KB Output is correct
48 Correct 571 ms 2748 KB Output is correct
49 Correct 1155 ms 1692 KB Output is correct
50 Correct 1137 ms 1856 KB Output is correct
51 Correct 1151 ms 1804 KB Output is correct
52 Correct 1128 ms 1784 KB Output is correct
53 Correct 473 ms 832 KB Output is correct
54 Correct 473 ms 816 KB Output is correct
55 Correct 493 ms 748 KB Output is correct
56 Correct 466 ms 968 KB Output is correct
57 Correct 1287 ms 1648 KB Output is correct
58 Correct 907 ms 1136 KB Output is correct
59 Correct 811 ms 2272 KB Output is correct
60 Correct 1134 ms 988 KB Output is correct
61 Correct 604 ms 2656 KB Output is correct
62 Correct 518 ms 4148 KB Output is correct
63 Correct 487 ms 4152 KB Output is correct
64 Correct 501 ms 4160 KB Output is correct
65 Correct 572 ms 1472 KB Output is correct
66 Correct 550 ms 1340 KB Output is correct
67 Correct 552 ms 2900 KB Output is correct
68 Correct 570 ms 2308 KB Output is correct
69 Correct 1137 ms 1860 KB Output is correct
70 Correct 1126 ms 1852 KB Output is correct
71 Correct 1126 ms 1828 KB Output is correct
72 Correct 1131 ms 1952 KB Output is correct
73 Correct 605 ms 1620 KB Output is correct
74 Correct 574 ms 2492 KB Output is correct
75 Correct 470 ms 2744 KB Output is correct
76 Correct 502 ms 4264 KB Output is correct
77 Correct 472 ms 792 KB Output is correct
78 Correct 467 ms 708 KB Output is correct
79 Correct 474 ms 1116 KB Output is correct
80 Correct 476 ms 756 KB Output is correct
81 Correct 601 ms 2252 KB Output is correct
82 Correct 622 ms 1760 KB Output is correct
83 Correct 579 ms 1344 KB Output is correct
84 Correct 605 ms 2248 KB Output is correct
85 Correct 572 ms 2788 KB Output is correct
86 Correct 571 ms 3512 KB Output is correct
87 Correct 575 ms 2000 KB Output is correct
88 Correct 540 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 22 ms 364 KB Output is correct
4 Correct 21 ms 404 KB Output is correct
5 Correct 7 ms 460 KB Output is correct
6 Correct 19 ms 424 KB Output is correct
7 Correct 21 ms 332 KB Output is correct
8 Correct 11 ms 420 KB Output is correct
9 Correct 12 ms 332 KB Output is correct
10 Correct 5 ms 460 KB Output is correct
11 Correct 17 ms 416 KB Output is correct
12 Correct 14 ms 416 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 11 ms 432 KB Output is correct
15 Correct 23 ms 388 KB Output is correct
16 Correct 20 ms 396 KB Output is correct
17 Correct 17 ms 440 KB Output is correct
18 Correct 6 ms 460 KB Output is correct
19 Correct 14 ms 332 KB Output is correct
20 Correct 14 ms 332 KB Output is correct
21 Correct 1152 ms 1748 KB Output is correct
22 Correct 1218 ms 1756 KB Output is correct
23 Correct 1149 ms 1792 KB Output is correct
24 Correct 766 ms 1816 KB Output is correct
25 Correct 505 ms 2748 KB Output is correct
26 Correct 502 ms 2664 KB Output is correct
27 Correct 1162 ms 1736 KB Output is correct
28 Correct 1149 ms 1884 KB Output is correct
29 Correct 1121 ms 1724 KB Output is correct
30 Correct 1099 ms 1308 KB Output is correct
31 Correct 952 ms 1312 KB Output is correct
32 Correct 598 ms 2348 KB Output is correct
33 Correct 495 ms 808 KB Output is correct
34 Correct 491 ms 764 KB Output is correct
35 Correct 488 ms 836 KB Output is correct
36 Correct 493 ms 964 KB Output is correct
37 Correct 816 ms 2364 KB Output is correct
38 Correct 670 ms 2128 KB Output is correct
39 Correct 920 ms 2020 KB Output is correct
40 Correct 506 ms 2612 KB Output is correct
41 Correct 516 ms 4264 KB Output is correct
42 Correct 577 ms 3568 KB Output is correct
43 Correct 565 ms 960 KB Output is correct
44 Correct 611 ms 3504 KB Output is correct
45 Correct 562 ms 2620 KB Output is correct
46 Correct 590 ms 1860 KB Output is correct
47 Correct 536 ms 1824 KB Output is correct
48 Correct 552 ms 1448 KB Output is correct
49 Correct 547 ms 1768 KB Output is correct
50 Correct 1198 ms 1904 KB Output is correct
51 Correct 1228 ms 1852 KB Output is correct
52 Correct 546 ms 2044 KB Output is correct
53 Correct 593 ms 1196 KB Output is correct
54 Correct 654 ms 2100 KB Output is correct
55 Correct 605 ms 2464 KB Output is correct
56 Correct 648 ms 2372 KB Output is correct
57 Correct 496 ms 840 KB Output is correct
58 Correct 481 ms 788 KB Output is correct
59 Correct 495 ms 772 KB Output is correct
60 Correct 489 ms 776 KB Output is correct
61 Correct 644 ms 2496 KB Output is correct
62 Correct 654 ms 2496 KB Output is correct
63 Correct 489 ms 4096 KB Output is correct
64 Correct 575 ms 3596 KB Output is correct
65 Correct 550 ms 2652 KB Output is correct
66 Correct 550 ms 1892 KB Output is correct
67 Correct 554 ms 2356 KB Output is correct
68 Correct 541 ms 2740 KB Output is correct
69 Correct 471 ms 728 KB Output is correct
70 Correct 470 ms 780 KB Output is correct
71 Correct 504 ms 716 KB Output is correct
72 Correct 480 ms 792 KB Output is correct
73 Correct 637 ms 2364 KB Output is correct
74 Correct 1342 ms 1220 KB Output is correct
75 Correct 623 ms 2360 KB Output is correct
76 Correct 782 ms 1340 KB Output is correct
77 Correct 633 ms 2004 KB Output is correct
78 Correct 553 ms 3792 KB Output is correct
79 Correct 597 ms 1472 KB Output is correct
80 Correct 485 ms 2780 KB Output is correct
81 Correct 557 ms 2596 KB Output is correct
82 Correct 573 ms 1816 KB Output is correct
83 Correct 499 ms 4140 KB Output is correct
84 Correct 571 ms 2748 KB Output is correct
85 Correct 1155 ms 1692 KB Output is correct
86 Correct 1137 ms 1856 KB Output is correct
87 Correct 1151 ms 1804 KB Output is correct
88 Correct 1128 ms 1784 KB Output is correct
89 Correct 473 ms 832 KB Output is correct
90 Correct 473 ms 816 KB Output is correct
91 Correct 493 ms 748 KB Output is correct
92 Correct 466 ms 968 KB Output is correct
93 Correct 1287 ms 1648 KB Output is correct
94 Correct 907 ms 1136 KB Output is correct
95 Correct 811 ms 2272 KB Output is correct
96 Correct 1134 ms 988 KB Output is correct
97 Correct 604 ms 2656 KB Output is correct
98 Correct 518 ms 4148 KB Output is correct
99 Correct 487 ms 4152 KB Output is correct
100 Correct 501 ms 4160 KB Output is correct
101 Correct 572 ms 1472 KB Output is correct
102 Correct 550 ms 1340 KB Output is correct
103 Correct 552 ms 2900 KB Output is correct
104 Correct 570 ms 2308 KB Output is correct
105 Correct 1137 ms 1860 KB Output is correct
106 Correct 1126 ms 1852 KB Output is correct
107 Correct 1126 ms 1828 KB Output is correct
108 Correct 1131 ms 1952 KB Output is correct
109 Correct 605 ms 1620 KB Output is correct
110 Correct 574 ms 2492 KB Output is correct
111 Correct 470 ms 2744 KB Output is correct
112 Correct 502 ms 4264 KB Output is correct
113 Correct 472 ms 792 KB Output is correct
114 Correct 467 ms 708 KB Output is correct
115 Correct 474 ms 1116 KB Output is correct
116 Correct 476 ms 756 KB Output is correct
117 Correct 601 ms 2252 KB Output is correct
118 Correct 622 ms 1760 KB Output is correct
119 Correct 579 ms 1344 KB Output is correct
120 Correct 605 ms 2248 KB Output is correct
121 Correct 572 ms 2788 KB Output is correct
122 Correct 571 ms 3512 KB Output is correct
123 Correct 575 ms 2000 KB Output is correct
124 Correct 540 ms 1236 KB Output is correct
125 Correct 941 ms 1204 KB Output is correct
126 Correct 956 ms 1228 KB Output is correct
127 Correct 953 ms 1252 KB Output is correct
128 Correct 952 ms 1384 KB Output is correct
129 Correct 942 ms 1240 KB Output is correct
130 Correct 959 ms 1340 KB Output is correct
131 Correct 3061 ms 1808 KB Output is correct
132 Correct 2752 ms 4100 KB Output is correct
133 Correct 1687 ms 8904 KB Output is correct
134 Correct 1670 ms 7992 KB Output is correct
135 Correct 2421 ms 9272 KB Output is correct
136 Correct 2181 ms 7700 KB Output is correct
137 Correct 1866 ms 12068 KB Output is correct
138 Correct 1781 ms 8820 KB Output is correct
139 Correct 1872 ms 10408 KB Output is correct
140 Correct 1870 ms 11452 KB Output is correct
141 Correct 1850 ms 9372 KB Output is correct
142 Correct 1238 ms 5836 KB Output is correct
143 Correct 1382 ms 6736 KB Output is correct
144 Correct 1084 ms 5688 KB Output is correct
145 Correct 1814 ms 11632 KB Output is correct
146 Correct 1567 ms 7740 KB Output is correct
147 Correct 1425 ms 6908 KB Output is correct
148 Correct 1431 ms 6600 KB Output is correct
149 Correct 2825 ms 8800 KB Output is correct
150 Correct 1513 ms 8676 KB Output is correct
151 Correct 2854 ms 8788 KB Output is correct
152 Correct 2811 ms 8860 KB Output is correct
153 Correct 1526 ms 8952 KB Output is correct
154 Correct 2839 ms 8624 KB Output is correct
155 Correct 1377 ms 6256 KB Output is correct
156 Correct 1550 ms 6860 KB Output is correct
157 Correct 1849 ms 11704 KB Output is correct
158 Correct 1872 ms 12128 KB Output is correct
159 Correct 1742 ms 8996 KB Output is correct
160 Correct 1618 ms 7816 KB Output is correct
161 Correct 959 ms 5444 KB Output is correct
162 Correct 944 ms 5416 KB Output is correct
163 Correct 961 ms 5292 KB Output is correct
164 Correct 984 ms 5440 KB Output is correct
165 Correct 954 ms 5496 KB Output is correct
166 Correct 956 ms 5456 KB Output is correct
167 Correct 1839 ms 12560 KB Output is correct
168 Correct 1834 ms 12620 KB Output is correct
169 Correct 1876 ms 11696 KB Output is correct
170 Correct 1876 ms 11188 KB Output is correct
171 Correct 1835 ms 9312 KB Output is correct
172 Correct 1607 ms 7388 KB Output is correct
173 Correct 1892 ms 11852 KB Output is correct
174 Correct 1564 ms 7584 KB Output is correct
175 Correct 1835 ms 10088 KB Output is correct
176 Correct 1390 ms 6600 KB Output is correct
177 Correct 1775 ms 9052 KB Output is correct
178 Correct 1748 ms 8688 KB Output is correct