Submission #1025280

# Submission time Handle Problem Language Result Execution time Memory
1025280 2024-07-16T19:12:45 Z Vanio Segments (IZhO18_segments) C++17
75 / 100
5000 ms 17744 KB
#include<bits/stdc++.h>
using namespace std;

struct segment{
    int l,r;
};
segment seg[200001],tseg[200001];
bool fff(segment p, segment q){
    return p.r-p.l>q.r-q.l;
}

struct block{
    int mi=INT_MAX,ma=-1;
    vector<int> vl,vr;
};
block b[501];

struct query{
    int qt,id,l,r,k;
};
query qs[200001];

int n,segbr,t,nextSegmentId,lastans,bsz,bbr,qbStart=1;
set<int> segmentIds;

void buildStructure(){
    int i=1;
    segbr=segmentIds.size();
    for(int it : segmentIds){
        tseg[i]=seg[it];
        i++;
    }

    sort(tseg+1,tseg+1+segbr,fff);
    bsz=sqrt(segbr)+1;
    bbr=segbr/bsz;
    if(segbr%bsz>0) bbr++;
    int bindx=0;
    for(i=1;i<=segbr;i++){
        if(i%bsz==1) bindx++;
        b[bindx].mi=INT_MAX;
        b[bindx].ma=-1;
        b[bindx].vl.clear();
        b[bindx].vr.clear();
    }
    bindx=0;
    for(i=1;i<=segbr;i++){
        if(i%bsz==1) bindx++;
        //cout<<bindx<<" "<<seg[i].l<<" "<<seg[i].r<<'\n';
        b[bindx].mi=min(b[bindx].mi,tseg[i].r-tseg[i].l+1);
        b[bindx].ma=max(b[bindx].ma,tseg[i].r-tseg[i].l+1);
        b[bindx].vl.push_back(tseg[i].l);
        b[bindx].vr.push_back(tseg[i].r);
    }

    for(i=1;i<=bbr;i++){
        sort(b[i].vl.begin(),b[i].vl.end());
        sort(b[i].vr.begin(),b[i].vr.end());
    }
}

void handleQt1(int k){
    nextSegmentId++;
    qs[k].qt=1;
    qs[k].id=nextSegmentId;
    cin>>seg[nextSegmentId].l>>seg[nextSegmentId].r;
    seg[nextSegmentId].l^=lastans*t;
    seg[nextSegmentId].r^=lastans*t;
    if(seg[nextSegmentId].l>seg[nextSegmentId].r) swap(seg[nextSegmentId].l,seg[nextSegmentId].r);
    segmentIds.insert(nextSegmentId);
}

void handleQt2(int k){
    qs[k].qt=2;
    cin>>qs[k].id;
    segmentIds.erase(qs[k].id);
}

void handleQt3(int ti){
    int l,r,k,ans=0,j,i;
    cin>>l>>r>>k;

    ans=segbr;
    l^=lastans*t;
    r^=lastans*t;
    if(l>r) swap(l,r);

    //cout<<"qt3 "<<l<<" "<<r<<" "<<k<<endl;
    for(i=1;i<=bbr;i++){
        if(b[i].mi>=k){
            auto it = lower_bound(b[i].vl.begin(),b[i].vl.end(),r-k+2);
            //cout<<"1 "<<b[i].vl.end()-it<<endl;
            ans-=b[i].vl.end()-it;
            auto it2 = upper_bound(b[i].vr.begin(),b[i].vr.end(),l+k-2);
            //cout<<"1 "<<it2-b[i].vr.begin()<<endl;
            ans-=it2-b[i].vr.begin();
        }
        else if(b[i].mi<k && k<=b[i].ma){
            for(j=(i-1)*bsz+1;j<=i*bsz && j<=segbr;j++){
                if(tseg[j].r-tseg[j].l+1<k || tseg[j].l>=r-k+2 || tseg[j].r<=l+k-2){ans--; /*cout<<"2 "<<j<<" "<<seg[j].l<<" "<<seg[j].r<<endl;*/}
            }
        }
        else{
            ans-=segbr-bsz*(i-1);
            //cout<<segbr-bsz*(i-1)<<endl;
            break;
        }
    }

    int segId;
    for(i=ti-1;i>=qbStart;i--){
        if(qs[i].qt==1){
            segId=qs[i].id;
            if(min(r,seg[segId].r)-max(l,seg[segId].l)+1>=k) ans++;
        }
        if(qs[i].qt==2){
            segId=qs[i].id;
            if(min(r,seg[segId].r)-max(l,seg[segId].l)+1>=k) ans--;
        }
    }

    lastans=ans;
    cout<<ans<<'\n';
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int i,qt,l,r,id,k,f=0,qbsz;
cin>>n>>t;
qbsz=sqrt(n);

for(i=1;i<=n;i++){
    if(i%qbsz==1){
        buildStructure();
        qbStart=i;
        //cout<<"new query block "<<i<<" "<<segbr<<endl;
    }

    cin>>qt;
    if(qt==1) handleQt1(i);
    if(qt==2) handleQt2(i);
    if(qt==3) handleQt3(i);
}

return 0;
}
/*
6 1
1 1 2
1 3 8
1 5 8
1 2 4
1 8 10
3 3 7 2

25 1
1 97 61
1 21 92
1 57 10
1 77 46
1 60 54
1 34 35
1 7 66
1 71 61
1 64 19
1 22 80
1 81 39
1 57 52
1 9 4
1 17 28
1 16 51
1 67 2
1 25 51
1 42 83
1 61 65
1 37 45
3 31 34 2
3 36 37 1
3 44 62 8
3 65 67 3
3 84 92 6

8   8
11  11
16  11
3   6
2   2
*/

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:132:10: warning: unused variable 'l' [-Wunused-variable]
  132 | int i,qt,l,r,id,k,f=0,qbsz;
      |          ^
segments.cpp:132:12: warning: unused variable 'r' [-Wunused-variable]
  132 | int i,qt,l,r,id,k,f=0,qbsz;
      |            ^
segments.cpp:132:14: warning: unused variable 'id' [-Wunused-variable]
  132 | int i,qt,l,r,id,k,f=0,qbsz;
      |              ^~
segments.cpp:132:17: warning: unused variable 'k' [-Wunused-variable]
  132 | int i,qt,l,r,id,k,f=0,qbsz;
      |                 ^
segments.cpp:132:19: warning: unused variable 'f' [-Wunused-variable]
  132 | int i,qt,l,r,id,k,f=0,qbsz;
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4632 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 25 ms 5036 KB Output is correct
6 Correct 22 ms 4956 KB Output is correct
7 Correct 7 ms 4700 KB Output is correct
8 Correct 19 ms 4912 KB Output is correct
9 Correct 19 ms 4696 KB Output is correct
10 Correct 22 ms 4976 KB Output is correct
11 Correct 21 ms 4696 KB Output is correct
12 Correct 19 ms 4848 KB Output is correct
13 Correct 24 ms 4868 KB Output is correct
14 Correct 20 ms 4700 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 3 ms 4696 KB Output is correct
17 Correct 11 ms 4724 KB Output is correct
18 Correct 22 ms 4956 KB Output is correct
19 Correct 16 ms 4700 KB Output is correct
20 Correct 14 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2033 ms 9812 KB Output is correct
2 Correct 2025 ms 12368 KB Output is correct
3 Correct 1998 ms 12372 KB Output is correct
4 Correct 2140 ms 12628 KB Output is correct
5 Correct 2260 ms 14640 KB Output is correct
6 Correct 2196 ms 14752 KB Output is correct
7 Correct 2035 ms 12540 KB Output is correct
8 Correct 1979 ms 12536 KB Output is correct
9 Correct 1994 ms 12500 KB Output is correct
10 Correct 1141 ms 11348 KB Output is correct
11 Correct 1438 ms 11600 KB Output is correct
12 Correct 2281 ms 13640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 6744 KB Output is correct
2 Correct 33 ms 6744 KB Output is correct
3 Correct 57 ms 6748 KB Output is correct
4 Correct 34 ms 6744 KB Output is correct
5 Correct 2330 ms 11348 KB Output is correct
6 Correct 2290 ms 10276 KB Output is correct
7 Correct 2318 ms 10980 KB Output is correct
8 Correct 2244 ms 12316 KB Output is correct
9 Correct 2160 ms 12112 KB Output is correct
10 Correct 2062 ms 10324 KB Output is correct
11 Correct 239 ms 7000 KB Output is correct
12 Correct 2017 ms 10848 KB Output is correct
13 Correct 1909 ms 9904 KB Output is correct
14 Correct 1128 ms 8600 KB Output is correct
15 Correct 980 ms 8272 KB Output is correct
16 Correct 728 ms 7568 KB Output is correct
17 Correct 2021 ms 9728 KB Output is correct
18 Correct 2185 ms 9848 KB Output is correct
19 Correct 2415 ms 9884 KB Output is correct
20 Correct 2211 ms 9844 KB Output is correct
21 Correct 336 ms 7388 KB Output is correct
22 Correct 1673 ms 8968 KB Output is correct
23 Correct 1977 ms 9524 KB Output is correct
24 Correct 1645 ms 9048 KB Output is correct
25 Correct 50 ms 6488 KB Output is correct
26 Correct 34 ms 6748 KB Output is correct
27 Correct 41 ms 6412 KB Output is correct
28 Correct 37 ms 6744 KB Output is correct
29 Correct 1825 ms 9800 KB Output is correct
30 Correct 1920 ms 9768 KB Output is correct
31 Correct 2423 ms 12256 KB Output is correct
32 Correct 2237 ms 10452 KB Output is correct
33 Correct 2091 ms 10132 KB Output is correct
34 Correct 1028 ms 8136 KB Output is correct
35 Correct 1768 ms 9556 KB Output is correct
36 Correct 1937 ms 10320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 6748 KB Output is correct
2 Correct 37 ms 8908 KB Output is correct
3 Correct 36 ms 8792 KB Output is correct
4 Correct 38 ms 8784 KB Output is correct
5 Correct 2272 ms 14092 KB Output is correct
6 Correct 855 ms 10836 KB Output is correct
7 Correct 2297 ms 14292 KB Output is correct
8 Correct 1112 ms 11348 KB Output is correct
9 Correct 1355 ms 10796 KB Output is correct
10 Correct 2198 ms 13396 KB Output is correct
11 Correct 640 ms 9892 KB Output is correct
12 Correct 2145 ms 14676 KB Output is correct
13 Correct 1905 ms 12072 KB Output is correct
14 Correct 1231 ms 10796 KB Output is correct
15 Correct 2145 ms 14256 KB Output is correct
16 Correct 1979 ms 12368 KB Output is correct
17 Correct 1993 ms 12372 KB Output is correct
18 Correct 2024 ms 12532 KB Output is correct
19 Correct 2017 ms 12404 KB Output is correct
20 Correct 2005 ms 12444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4632 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 25 ms 5036 KB Output is correct
6 Correct 22 ms 4956 KB Output is correct
7 Correct 7 ms 4700 KB Output is correct
8 Correct 19 ms 4912 KB Output is correct
9 Correct 19 ms 4696 KB Output is correct
10 Correct 22 ms 4976 KB Output is correct
11 Correct 21 ms 4696 KB Output is correct
12 Correct 19 ms 4848 KB Output is correct
13 Correct 24 ms 4868 KB Output is correct
14 Correct 20 ms 4700 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 3 ms 4696 KB Output is correct
17 Correct 11 ms 4724 KB Output is correct
18 Correct 22 ms 4956 KB Output is correct
19 Correct 16 ms 4700 KB Output is correct
20 Correct 14 ms 4700 KB Output is correct
21 Correct 2033 ms 9812 KB Output is correct
22 Correct 2025 ms 12368 KB Output is correct
23 Correct 1998 ms 12372 KB Output is correct
24 Correct 2140 ms 12628 KB Output is correct
25 Correct 2260 ms 14640 KB Output is correct
26 Correct 2196 ms 14752 KB Output is correct
27 Correct 2035 ms 12540 KB Output is correct
28 Correct 1979 ms 12536 KB Output is correct
29 Correct 1994 ms 12500 KB Output is correct
30 Correct 1141 ms 11348 KB Output is correct
31 Correct 1438 ms 11600 KB Output is correct
32 Correct 2281 ms 13640 KB Output is correct
33 Correct 30 ms 6748 KB Output is correct
34 Correct 37 ms 8908 KB Output is correct
35 Correct 36 ms 8792 KB Output is correct
36 Correct 38 ms 8784 KB Output is correct
37 Correct 2272 ms 14092 KB Output is correct
38 Correct 855 ms 10836 KB Output is correct
39 Correct 2297 ms 14292 KB Output is correct
40 Correct 1112 ms 11348 KB Output is correct
41 Correct 1355 ms 10796 KB Output is correct
42 Correct 2198 ms 13396 KB Output is correct
43 Correct 640 ms 9892 KB Output is correct
44 Correct 2145 ms 14676 KB Output is correct
45 Correct 1905 ms 12072 KB Output is correct
46 Correct 1231 ms 10796 KB Output is correct
47 Correct 2145 ms 14256 KB Output is correct
48 Correct 1979 ms 12368 KB Output is correct
49 Correct 1993 ms 12372 KB Output is correct
50 Correct 2024 ms 12532 KB Output is correct
51 Correct 2017 ms 12404 KB Output is correct
52 Correct 2005 ms 12444 KB Output is correct
53 Correct 39 ms 8748 KB Output is correct
54 Correct 42 ms 8788 KB Output is correct
55 Correct 36 ms 8784 KB Output is correct
56 Correct 39 ms 8736 KB Output is correct
57 Correct 1579 ms 11744 KB Output is correct
58 Correct 610 ms 10592 KB Output is correct
59 Correct 2185 ms 12768 KB Output is correct
60 Correct 505 ms 8536 KB Output is correct
61 Correct 1856 ms 12132 KB Output is correct
62 Correct 2370 ms 14232 KB Output is correct
63 Correct 2437 ms 14468 KB Output is correct
64 Correct 2492 ms 14088 KB Output is correct
65 Correct 927 ms 10012 KB Output is correct
66 Correct 752 ms 9772 KB Output is correct
67 Correct 2177 ms 12412 KB Output is correct
68 Correct 1864 ms 11600 KB Output is correct
69 Correct 2250 ms 12524 KB Output is correct
70 Correct 2230 ms 12316 KB Output is correct
71 Correct 2288 ms 12372 KB Output is correct
72 Correct 2275 ms 12408 KB Output is correct
73 Correct 1129 ms 10244 KB Output is correct
74 Correct 1905 ms 11492 KB Output is correct
75 Correct 2527 ms 14784 KB Output is correct
76 Correct 2521 ms 14600 KB Output is correct
77 Correct 54 ms 8788 KB Output is correct
78 Correct 38 ms 8764 KB Output is correct
79 Correct 43 ms 8872 KB Output is correct
80 Correct 38 ms 8540 KB Output is correct
81 Correct 1827 ms 11348 KB Output is correct
82 Correct 1122 ms 10348 KB Output is correct
83 Correct 582 ms 9552 KB Output is correct
84 Correct 1660 ms 11500 KB Output is correct
85 Correct 2035 ms 12336 KB Output is correct
86 Correct 2067 ms 13040 KB Output is correct
87 Correct 1422 ms 10832 KB Output is correct
88 Correct 607 ms 9452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4632 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Correct 25 ms 5036 KB Output is correct
6 Correct 22 ms 4956 KB Output is correct
7 Correct 7 ms 4700 KB Output is correct
8 Correct 19 ms 4912 KB Output is correct
9 Correct 19 ms 4696 KB Output is correct
10 Correct 22 ms 4976 KB Output is correct
11 Correct 21 ms 4696 KB Output is correct
12 Correct 19 ms 4848 KB Output is correct
13 Correct 24 ms 4868 KB Output is correct
14 Correct 20 ms 4700 KB Output is correct
15 Correct 2 ms 4700 KB Output is correct
16 Correct 3 ms 4696 KB Output is correct
17 Correct 11 ms 4724 KB Output is correct
18 Correct 22 ms 4956 KB Output is correct
19 Correct 16 ms 4700 KB Output is correct
20 Correct 14 ms 4700 KB Output is correct
21 Correct 2033 ms 9812 KB Output is correct
22 Correct 2025 ms 12368 KB Output is correct
23 Correct 1998 ms 12372 KB Output is correct
24 Correct 2140 ms 12628 KB Output is correct
25 Correct 2260 ms 14640 KB Output is correct
26 Correct 2196 ms 14752 KB Output is correct
27 Correct 2035 ms 12540 KB Output is correct
28 Correct 1979 ms 12536 KB Output is correct
29 Correct 1994 ms 12500 KB Output is correct
30 Correct 1141 ms 11348 KB Output is correct
31 Correct 1438 ms 11600 KB Output is correct
32 Correct 2281 ms 13640 KB Output is correct
33 Correct 41 ms 6744 KB Output is correct
34 Correct 33 ms 6744 KB Output is correct
35 Correct 57 ms 6748 KB Output is correct
36 Correct 34 ms 6744 KB Output is correct
37 Correct 2330 ms 11348 KB Output is correct
38 Correct 2290 ms 10276 KB Output is correct
39 Correct 2318 ms 10980 KB Output is correct
40 Correct 2244 ms 12316 KB Output is correct
41 Correct 2160 ms 12112 KB Output is correct
42 Correct 2062 ms 10324 KB Output is correct
43 Correct 239 ms 7000 KB Output is correct
44 Correct 2017 ms 10848 KB Output is correct
45 Correct 1909 ms 9904 KB Output is correct
46 Correct 1128 ms 8600 KB Output is correct
47 Correct 980 ms 8272 KB Output is correct
48 Correct 728 ms 7568 KB Output is correct
49 Correct 2021 ms 9728 KB Output is correct
50 Correct 2185 ms 9848 KB Output is correct
51 Correct 2415 ms 9884 KB Output is correct
52 Correct 2211 ms 9844 KB Output is correct
53 Correct 336 ms 7388 KB Output is correct
54 Correct 1673 ms 8968 KB Output is correct
55 Correct 1977 ms 9524 KB Output is correct
56 Correct 1645 ms 9048 KB Output is correct
57 Correct 50 ms 6488 KB Output is correct
58 Correct 34 ms 6748 KB Output is correct
59 Correct 41 ms 6412 KB Output is correct
60 Correct 37 ms 6744 KB Output is correct
61 Correct 1825 ms 9800 KB Output is correct
62 Correct 1920 ms 9768 KB Output is correct
63 Correct 2423 ms 12256 KB Output is correct
64 Correct 2237 ms 10452 KB Output is correct
65 Correct 2091 ms 10132 KB Output is correct
66 Correct 1028 ms 8136 KB Output is correct
67 Correct 1768 ms 9556 KB Output is correct
68 Correct 1937 ms 10320 KB Output is correct
69 Correct 30 ms 6748 KB Output is correct
70 Correct 37 ms 8908 KB Output is correct
71 Correct 36 ms 8792 KB Output is correct
72 Correct 38 ms 8784 KB Output is correct
73 Correct 2272 ms 14092 KB Output is correct
74 Correct 855 ms 10836 KB Output is correct
75 Correct 2297 ms 14292 KB Output is correct
76 Correct 1112 ms 11348 KB Output is correct
77 Correct 1355 ms 10796 KB Output is correct
78 Correct 2198 ms 13396 KB Output is correct
79 Correct 640 ms 9892 KB Output is correct
80 Correct 2145 ms 14676 KB Output is correct
81 Correct 1905 ms 12072 KB Output is correct
82 Correct 1231 ms 10796 KB Output is correct
83 Correct 2145 ms 14256 KB Output is correct
84 Correct 1979 ms 12368 KB Output is correct
85 Correct 1993 ms 12372 KB Output is correct
86 Correct 2024 ms 12532 KB Output is correct
87 Correct 2017 ms 12404 KB Output is correct
88 Correct 2005 ms 12444 KB Output is correct
89 Correct 39 ms 8748 KB Output is correct
90 Correct 42 ms 8788 KB Output is correct
91 Correct 36 ms 8784 KB Output is correct
92 Correct 39 ms 8736 KB Output is correct
93 Correct 1579 ms 11744 KB Output is correct
94 Correct 610 ms 10592 KB Output is correct
95 Correct 2185 ms 12768 KB Output is correct
96 Correct 505 ms 8536 KB Output is correct
97 Correct 1856 ms 12132 KB Output is correct
98 Correct 2370 ms 14232 KB Output is correct
99 Correct 2437 ms 14468 KB Output is correct
100 Correct 2492 ms 14088 KB Output is correct
101 Correct 927 ms 10012 KB Output is correct
102 Correct 752 ms 9772 KB Output is correct
103 Correct 2177 ms 12412 KB Output is correct
104 Correct 1864 ms 11600 KB Output is correct
105 Correct 2250 ms 12524 KB Output is correct
106 Correct 2230 ms 12316 KB Output is correct
107 Correct 2288 ms 12372 KB Output is correct
108 Correct 2275 ms 12408 KB Output is correct
109 Correct 1129 ms 10244 KB Output is correct
110 Correct 1905 ms 11492 KB Output is correct
111 Correct 2527 ms 14784 KB Output is correct
112 Correct 2521 ms 14600 KB Output is correct
113 Correct 54 ms 8788 KB Output is correct
114 Correct 38 ms 8764 KB Output is correct
115 Correct 43 ms 8872 KB Output is correct
116 Correct 38 ms 8540 KB Output is correct
117 Correct 1827 ms 11348 KB Output is correct
118 Correct 1122 ms 10348 KB Output is correct
119 Correct 582 ms 9552 KB Output is correct
120 Correct 1660 ms 11500 KB Output is correct
121 Correct 2035 ms 12336 KB Output is correct
122 Correct 2067 ms 13040 KB Output is correct
123 Correct 1422 ms 10832 KB Output is correct
124 Correct 607 ms 9452 KB Output is correct
125 Correct 81 ms 11008 KB Output is correct
126 Correct 82 ms 11096 KB Output is correct
127 Correct 98 ms 11344 KB Output is correct
128 Correct 91 ms 11092 KB Output is correct
129 Correct 79 ms 11080 KB Output is correct
130 Correct 89 ms 11092 KB Output is correct
131 Correct 1982 ms 14928 KB Output is correct
132 Execution timed out 5039 ms 17744 KB Time limit exceeded
133 Halted 0 ms 0 KB -