답안 #898500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898500 2024-01-04T18:51:01 Z Denkata Segments (IZhO18_segments) C++17
0 / 100
199 ms 3152 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+3;
const int crit = 3;
int i,j,p,q,n,m,k,L,R,A,B,lans,id,lb[maxn],rb[maxn],block[maxn],minlen[maxn],t,curlen;
vector < pair <int,int> > cur,all;
vector < pair <int,int> > levi[100],desni[100];//n/crit
int removed[maxn];
void insert(int l,int r,int nom)
{
    cur.push_back({r-l+1,nom});
    if(cur.size()==crit)
    {
        vector <pair <int,int>> neww;

        for(i=0; i<=all.size()/crit+2; i++)
            levi[i].clear(),desni[i].clear(),minlen[i] = -1;
        for(auto i:cur)
            neww.push_back(i);
        for(auto i:all)
            neww.push_back(i);
        cur.clear();
        all.clear();
        for(auto i:neww)
        {
            if(!removed[i.second])
                all.push_back(i);
        }

        ///build the structure
        sort(all.rbegin(),all.rend());
        int bl = 0;
        int br = 0;
        int Min = 1e7;
        for(auto i:all)
        {
            levi[bl].push_back({lb[i.second],i.second});
            desni[bl].push_back({rb[i.second],i.second});
            Min = min(Min,i.first);
            block[i.second] = bl;
            br++;
            if(br==crit)
            {
                minlen[bl] = Min;
                Min = 1e7;
                bl++;
                br = 0;
            }
        }

        for(i=0; i<=all.size()/crit+2; i++)
        {
            if(levi[i].empty())break;
            sort(levi[i].begin(),levi[i].end());
            sort(desni[i].begin(),desni[i].end());
        }
    }
}
void remove(int id)
{
    removed[id] = true;
    if(block[id]==-1)
        return ;

    p = block[id];

    vector < pair <int,int> > newws;
    for(auto i:levi[p])
        if(i.second!=id)newws.push_back(i);
    levi[p] = newws;

    newws.clear();
    for(auto i:desni[p])
        if(i.second!=id)newws.push_back(i);
    desni[p] = newws;

    block[id] = -1;
}
int solve(int l,int r,int k)
{
    int ans = 0;
    for(auto i:cur)
    {
        if(removed[i.second])
            continue;
        //cout<<lb[i.second]<<" "<<rb[i.second]<<"    "<<l<<" "<<r<<" "<<k<<endl;
        if(min(rb[i.second],r)-max(lb[i.second],l)+1>=k)
            ans++;
    }
    for(i=0; i<=all.size()/crit+1; i++)
    {
        if(minlen[i]==-1)break;
        if(minlen[i]<k)
        {
            ///iterative check
            j = i;
            for(auto i:levi[j])
            {
                if(removed[i.second])
                    continue;
                if(min(rb[i.second],r)-max(lb[i.second],l)+1>=k)
                    ans++;
            }
            break;
        }
        ans+=levi[i].size();
        p = 0;
        ///indexed from 0
        p += upper_bound(desni[i].begin(),desni[i].end(), make_pair(l+k-2,-1))-desni[i].begin();
        p += levi[i].size()-(lower_bound(levi[i].begin(),levi[i].end(), make_pair(r-k+2,-1))-levi[i].begin());
        ans-=p;
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>t;
    for(i=0; i<=n; i++)
        block[i] = -1,minlen[i] = -1;
    lans = 0;
    while(n--)
    {
        int type;
        cin>>type;
        if(type==1)
        {
            cin>>A>>B;
            L = A^(t*lans);
            R = B^(t*lans);
            if(L>R)swap(L,R);
            curlen++;
            lb[curlen] = L;
            rb[curlen] = R;
            insert(L,R,curlen);
        }
        else if(type==2)
        {
            cin>>id;
            remove(id);
        }
        else
        {
            cin>>A>>B>>k;
            L = A^(t*lans);
            R = B^(t*lans);
            if(L>R)swap(L,R);
            lans = solve(L,R,k);
            cout<<lans<<endl;
        }
    }
    return 0;
}
/**
6 1
1 1 2
3 2 4 2
1 3 5
3 2 3 1
2 1
3 0 3 1



6 0
1 3 10
1 3 5
3 6 10 6
2 1
1 3 10
3 6 4 2
*/

Compilation message

segments.cpp: In function 'void insert(int, int, int)':
segments.cpp:16:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         for(i=0; i<=all.size()/crit+2; i++)
      |                  ~^~~~~~~~~~~~~~~~~~~
segments.cpp:51:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(i=0; i<=all.size()/crit+2; i++)
      |                  ~^~~~~~~~~~~~~~~~~~~
segments.cpp: In function 'int solve(int, int, int)':
segments.cpp:90:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     for(i=0; i<=all.size()/crit+1; i++)
      |              ~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 199 ms 2968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 137 ms 3152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 90 ms 2892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Halted 0 ms 0 KB -