Submission #1025295

# Submission time Handle Problem Language Result Execution time Memory
1025295 2024-07-16T19:22:18 Z Vanio Segments (IZhO18_segments) C++17
75 / 100
5000 ms 19536 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("avx2")

#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)+5;

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:3:28: warning: bad option '-favx2' to pragma 'optimize' [-Wpragmas]
    3 | #pragma GCC optimize("avx2")
      |                            ^
segments.cpp:12:30: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   12 | bool fff(segment p, segment q){
      |                              ^
segments.cpp:30:21: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   30 | void buildStructure(){
      |                     ^
segments.cpp:66:21: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   66 | void handleQt1(int k){
      |                     ^
segments.cpp:77:21: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   77 | void handleQt2(int k){
      |                     ^
segments.cpp:83:22: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
   83 | void handleQt3(int ti){
      |                      ^
segments.cpp:130:10: warning: bad option '-favx2' to attribute 'optimize' [-Wattributes]
  130 | int main()
      |          ^
segments.cpp: In function 'int main()':
segments.cpp:136:10: warning: unused variable 'l' [-Wunused-variable]
  136 | int i,qt,l,r,id,k,f=0,qbsz;
      |          ^
segments.cpp:136:12: warning: unused variable 'r' [-Wunused-variable]
  136 | int i,qt,l,r,id,k,f=0,qbsz;
      |            ^
segments.cpp:136:14: warning: unused variable 'id' [-Wunused-variable]
  136 | int i,qt,l,r,id,k,f=0,qbsz;
      |              ^~
segments.cpp:136:17: warning: unused variable 'k' [-Wunused-variable]
  136 | int i,qt,l,r,id,k,f=0,qbsz;
      |                 ^
segments.cpp:136:19: warning: unused variable 'f' [-Wunused-variable]
  136 | int i,qt,l,r,id,k,f=0,qbsz;
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 20 ms 828 KB Output is correct
6 Correct 20 ms 852 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 16 ms 604 KB Output is correct
9 Correct 19 ms 604 KB Output is correct
10 Correct 24 ms 860 KB Output is correct
11 Correct 16 ms 600 KB Output is correct
12 Correct 16 ms 2652 KB Output is correct
13 Correct 19 ms 860 KB Output is correct
14 Correct 15 ms 2648 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 10 ms 688 KB Output is correct
18 Correct 19 ms 856 KB Output is correct
19 Correct 13 ms 700 KB Output is correct
20 Correct 11 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2009 ms 5100 KB Output is correct
2 Correct 2000 ms 5204 KB Output is correct
3 Correct 2054 ms 8592 KB Output is correct
4 Correct 2132 ms 10072 KB Output is correct
5 Correct 2102 ms 12476 KB Output is correct
6 Correct 2007 ms 12372 KB Output is correct
7 Correct 1739 ms 9800 KB Output is correct
8 Correct 1765 ms 9832 KB Output is correct
9 Correct 1827 ms 9852 KB Output is correct
10 Correct 1042 ms 8272 KB Output is correct
11 Correct 1265 ms 8716 KB Output is correct
12 Correct 2130 ms 11088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 6880 KB Output is correct
2 Correct 34 ms 6748 KB Output is correct
3 Correct 76 ms 6872 KB Output is correct
4 Correct 34 ms 6744 KB Output is correct
5 Correct 2169 ms 11352 KB Output is correct
6 Correct 2156 ms 10116 KB Output is correct
7 Correct 2141 ms 11048 KB Output is correct
8 Correct 2117 ms 12368 KB Output is correct
9 Correct 1958 ms 12192 KB Output is correct
10 Correct 1910 ms 10408 KB Output is correct
11 Correct 207 ms 7000 KB Output is correct
12 Correct 1794 ms 10996 KB Output is correct
13 Correct 1663 ms 10048 KB Output is correct
14 Correct 1104 ms 8488 KB Output is correct
15 Correct 983 ms 8276 KB Output is correct
16 Correct 718 ms 7760 KB Output is correct
17 Correct 2033 ms 9812 KB Output is correct
18 Correct 2016 ms 9808 KB Output is correct
19 Correct 2116 ms 9836 KB Output is correct
20 Correct 1940 ms 9928 KB Output is correct
21 Correct 265 ms 7248 KB Output is correct
22 Correct 1343 ms 9200 KB Output is correct
23 Correct 1490 ms 9540 KB Output is correct
24 Correct 1293 ms 9048 KB Output is correct
25 Correct 36 ms 6748 KB Output is correct
26 Correct 32 ms 6840 KB Output is correct
27 Correct 35 ms 6748 KB Output is correct
28 Correct 31 ms 6748 KB Output is correct
29 Correct 1629 ms 9812 KB Output is correct
30 Correct 1667 ms 9808 KB Output is correct
31 Correct 1794 ms 12108 KB Output is correct
32 Correct 1696 ms 10320 KB Output is correct
33 Correct 1613 ms 10324 KB Output is correct
34 Correct 862 ms 8212 KB Output is correct
35 Correct 1466 ms 9452 KB Output is correct
36 Correct 1741 ms 10068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 6748 KB Output is correct
2 Correct 35 ms 6848 KB Output is correct
3 Correct 36 ms 6744 KB Output is correct
4 Correct 37 ms 6812 KB Output is correct
5 Correct 1948 ms 11596 KB Output is correct
6 Correct 695 ms 7764 KB Output is correct
7 Correct 1874 ms 11888 KB Output is correct
8 Correct 951 ms 8300 KB Output is correct
9 Correct 1134 ms 8684 KB Output is correct
10 Correct 1731 ms 11252 KB Output is correct
11 Correct 496 ms 7508 KB Output is correct
12 Correct 1800 ms 12380 KB Output is correct
13 Correct 1645 ms 9868 KB Output is correct
14 Correct 1100 ms 8632 KB Output is correct
15 Correct 1906 ms 11932 KB Output is correct
16 Correct 1648 ms 10192 KB Output is correct
17 Correct 1686 ms 9856 KB Output is correct
18 Correct 1819 ms 9812 KB Output is correct
19 Correct 1765 ms 9764 KB Output is correct
20 Correct 1866 ms 10076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 20 ms 828 KB Output is correct
6 Correct 20 ms 852 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 16 ms 604 KB Output is correct
9 Correct 19 ms 604 KB Output is correct
10 Correct 24 ms 860 KB Output is correct
11 Correct 16 ms 600 KB Output is correct
12 Correct 16 ms 2652 KB Output is correct
13 Correct 19 ms 860 KB Output is correct
14 Correct 15 ms 2648 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 10 ms 688 KB Output is correct
18 Correct 19 ms 856 KB Output is correct
19 Correct 13 ms 700 KB Output is correct
20 Correct 11 ms 604 KB Output is correct
21 Correct 2009 ms 5100 KB Output is correct
22 Correct 2000 ms 5204 KB Output is correct
23 Correct 2054 ms 8592 KB Output is correct
24 Correct 2132 ms 10072 KB Output is correct
25 Correct 2102 ms 12476 KB Output is correct
26 Correct 2007 ms 12372 KB Output is correct
27 Correct 1739 ms 9800 KB Output is correct
28 Correct 1765 ms 9832 KB Output is correct
29 Correct 1827 ms 9852 KB Output is correct
30 Correct 1042 ms 8272 KB Output is correct
31 Correct 1265 ms 8716 KB Output is correct
32 Correct 2130 ms 11088 KB Output is correct
33 Correct 34 ms 6748 KB Output is correct
34 Correct 35 ms 6848 KB Output is correct
35 Correct 36 ms 6744 KB Output is correct
36 Correct 37 ms 6812 KB Output is correct
37 Correct 1948 ms 11596 KB Output is correct
38 Correct 695 ms 7764 KB Output is correct
39 Correct 1874 ms 11888 KB Output is correct
40 Correct 951 ms 8300 KB Output is correct
41 Correct 1134 ms 8684 KB Output is correct
42 Correct 1731 ms 11252 KB Output is correct
43 Correct 496 ms 7508 KB Output is correct
44 Correct 1800 ms 12380 KB Output is correct
45 Correct 1645 ms 9868 KB Output is correct
46 Correct 1100 ms 8632 KB Output is correct
47 Correct 1906 ms 11932 KB Output is correct
48 Correct 1648 ms 10192 KB Output is correct
49 Correct 1686 ms 9856 KB Output is correct
50 Correct 1819 ms 9812 KB Output is correct
51 Correct 1765 ms 9764 KB Output is correct
52 Correct 1866 ms 10076 KB Output is correct
53 Correct 38 ms 6748 KB Output is correct
54 Correct 38 ms 6836 KB Output is correct
55 Correct 34 ms 6744 KB Output is correct
56 Correct 41 ms 6844 KB Output is correct
57 Correct 1354 ms 9052 KB Output is correct
58 Correct 559 ms 7572 KB Output is correct
59 Correct 1888 ms 10328 KB Output is correct
60 Correct 478 ms 5576 KB Output is correct
61 Correct 1656 ms 9808 KB Output is correct
62 Correct 1883 ms 11996 KB Output is correct
63 Correct 1845 ms 12112 KB Output is correct
64 Correct 1872 ms 11900 KB Output is correct
65 Correct 791 ms 8020 KB Output is correct
66 Correct 619 ms 7596 KB Output is correct
67 Correct 1761 ms 10064 KB Output is correct
68 Correct 1566 ms 9556 KB Output is correct
69 Correct 1808 ms 9620 KB Output is correct
70 Correct 1744 ms 9808 KB Output is correct
71 Correct 1725 ms 9732 KB Output is correct
72 Correct 1743 ms 9700 KB Output is correct
73 Correct 867 ms 8276 KB Output is correct
74 Correct 1502 ms 9412 KB Output is correct
75 Correct 1839 ms 12436 KB Output is correct
76 Correct 1850 ms 12264 KB Output is correct
77 Correct 36 ms 6804 KB Output is correct
78 Correct 35 ms 7084 KB Output is correct
79 Correct 38 ms 6824 KB Output is correct
80 Correct 40 ms 6488 KB Output is correct
81 Correct 1399 ms 9284 KB Output is correct
82 Correct 871 ms 8156 KB Output is correct
83 Correct 479 ms 7504 KB Output is correct
84 Correct 1427 ms 9300 KB Output is correct
85 Correct 1709 ms 10324 KB Output is correct
86 Correct 1774 ms 10960 KB Output is correct
87 Correct 1213 ms 8868 KB Output is correct
88 Correct 503 ms 7512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 20 ms 828 KB Output is correct
6 Correct 20 ms 852 KB Output is correct
7 Correct 6 ms 604 KB Output is correct
8 Correct 16 ms 604 KB Output is correct
9 Correct 19 ms 604 KB Output is correct
10 Correct 24 ms 860 KB Output is correct
11 Correct 16 ms 600 KB Output is correct
12 Correct 16 ms 2652 KB Output is correct
13 Correct 19 ms 860 KB Output is correct
14 Correct 15 ms 2648 KB Output is correct
15 Correct 2 ms 2396 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 10 ms 688 KB Output is correct
18 Correct 19 ms 856 KB Output is correct
19 Correct 13 ms 700 KB Output is correct
20 Correct 11 ms 604 KB Output is correct
21 Correct 2009 ms 5100 KB Output is correct
22 Correct 2000 ms 5204 KB Output is correct
23 Correct 2054 ms 8592 KB Output is correct
24 Correct 2132 ms 10072 KB Output is correct
25 Correct 2102 ms 12476 KB Output is correct
26 Correct 2007 ms 12372 KB Output is correct
27 Correct 1739 ms 9800 KB Output is correct
28 Correct 1765 ms 9832 KB Output is correct
29 Correct 1827 ms 9852 KB Output is correct
30 Correct 1042 ms 8272 KB Output is correct
31 Correct 1265 ms 8716 KB Output is correct
32 Correct 2130 ms 11088 KB Output is correct
33 Correct 42 ms 6880 KB Output is correct
34 Correct 34 ms 6748 KB Output is correct
35 Correct 76 ms 6872 KB Output is correct
36 Correct 34 ms 6744 KB Output is correct
37 Correct 2169 ms 11352 KB Output is correct
38 Correct 2156 ms 10116 KB Output is correct
39 Correct 2141 ms 11048 KB Output is correct
40 Correct 2117 ms 12368 KB Output is correct
41 Correct 1958 ms 12192 KB Output is correct
42 Correct 1910 ms 10408 KB Output is correct
43 Correct 207 ms 7000 KB Output is correct
44 Correct 1794 ms 10996 KB Output is correct
45 Correct 1663 ms 10048 KB Output is correct
46 Correct 1104 ms 8488 KB Output is correct
47 Correct 983 ms 8276 KB Output is correct
48 Correct 718 ms 7760 KB Output is correct
49 Correct 2033 ms 9812 KB Output is correct
50 Correct 2016 ms 9808 KB Output is correct
51 Correct 2116 ms 9836 KB Output is correct
52 Correct 1940 ms 9928 KB Output is correct
53 Correct 265 ms 7248 KB Output is correct
54 Correct 1343 ms 9200 KB Output is correct
55 Correct 1490 ms 9540 KB Output is correct
56 Correct 1293 ms 9048 KB Output is correct
57 Correct 36 ms 6748 KB Output is correct
58 Correct 32 ms 6840 KB Output is correct
59 Correct 35 ms 6748 KB Output is correct
60 Correct 31 ms 6748 KB Output is correct
61 Correct 1629 ms 9812 KB Output is correct
62 Correct 1667 ms 9808 KB Output is correct
63 Correct 1794 ms 12108 KB Output is correct
64 Correct 1696 ms 10320 KB Output is correct
65 Correct 1613 ms 10324 KB Output is correct
66 Correct 862 ms 8212 KB Output is correct
67 Correct 1466 ms 9452 KB Output is correct
68 Correct 1741 ms 10068 KB Output is correct
69 Correct 34 ms 6748 KB Output is correct
70 Correct 35 ms 6848 KB Output is correct
71 Correct 36 ms 6744 KB Output is correct
72 Correct 37 ms 6812 KB Output is correct
73 Correct 1948 ms 11596 KB Output is correct
74 Correct 695 ms 7764 KB Output is correct
75 Correct 1874 ms 11888 KB Output is correct
76 Correct 951 ms 8300 KB Output is correct
77 Correct 1134 ms 8684 KB Output is correct
78 Correct 1731 ms 11252 KB Output is correct
79 Correct 496 ms 7508 KB Output is correct
80 Correct 1800 ms 12380 KB Output is correct
81 Correct 1645 ms 9868 KB Output is correct
82 Correct 1100 ms 8632 KB Output is correct
83 Correct 1906 ms 11932 KB Output is correct
84 Correct 1648 ms 10192 KB Output is correct
85 Correct 1686 ms 9856 KB Output is correct
86 Correct 1819 ms 9812 KB Output is correct
87 Correct 1765 ms 9764 KB Output is correct
88 Correct 1866 ms 10076 KB Output is correct
89 Correct 38 ms 6748 KB Output is correct
90 Correct 38 ms 6836 KB Output is correct
91 Correct 34 ms 6744 KB Output is correct
92 Correct 41 ms 6844 KB Output is correct
93 Correct 1354 ms 9052 KB Output is correct
94 Correct 559 ms 7572 KB Output is correct
95 Correct 1888 ms 10328 KB Output is correct
96 Correct 478 ms 5576 KB Output is correct
97 Correct 1656 ms 9808 KB Output is correct
98 Correct 1883 ms 11996 KB Output is correct
99 Correct 1845 ms 12112 KB Output is correct
100 Correct 1872 ms 11900 KB Output is correct
101 Correct 791 ms 8020 KB Output is correct
102 Correct 619 ms 7596 KB Output is correct
103 Correct 1761 ms 10064 KB Output is correct
104 Correct 1566 ms 9556 KB Output is correct
105 Correct 1808 ms 9620 KB Output is correct
106 Correct 1744 ms 9808 KB Output is correct
107 Correct 1725 ms 9732 KB Output is correct
108 Correct 1743 ms 9700 KB Output is correct
109 Correct 867 ms 8276 KB Output is correct
110 Correct 1502 ms 9412 KB Output is correct
111 Correct 1839 ms 12436 KB Output is correct
112 Correct 1850 ms 12264 KB Output is correct
113 Correct 36 ms 6804 KB Output is correct
114 Correct 35 ms 7084 KB Output is correct
115 Correct 38 ms 6824 KB Output is correct
116 Correct 40 ms 6488 KB Output is correct
117 Correct 1399 ms 9284 KB Output is correct
118 Correct 871 ms 8156 KB Output is correct
119 Correct 479 ms 7504 KB Output is correct
120 Correct 1427 ms 9300 KB Output is correct
121 Correct 1709 ms 10324 KB Output is correct
122 Correct 1774 ms 10960 KB Output is correct
123 Correct 1213 ms 8868 KB Output is correct
124 Correct 503 ms 7512 KB Output is correct
125 Correct 78 ms 6744 KB Output is correct
126 Correct 79 ms 6748 KB Output is correct
127 Correct 92 ms 6996 KB Output is correct
128 Correct 75 ms 6748 KB Output is correct
129 Correct 74 ms 6744 KB Output is correct
130 Correct 77 ms 6888 KB Output is correct
131 Correct 1727 ms 8784 KB Output is correct
132 Correct 4926 ms 12592 KB Output is correct
133 Execution timed out 5049 ms 19536 KB Time limit exceeded
134 Halted 0 ms 0 KB -