162822025-04-20 09:59:19horkaÚtvonalakcpp17Wrong answer 0/10079ms6088 KiB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)x.size()
const int c=10005;
int mx[4*c];
array<int, 3> mn[4*c];
map<int, int> val[4*c];
const int inf=1e8,minf=-500;
const array<int, 3> nagy{inf,-1};
array<int, 3> combine(array<int, 3> a, array<int, 3> b)
{
    array<int, 3> x;
    x[0]=min(a[0],b[0]);
    if(a[0]<b[0]) x[1]=a[1],x[2]=a[2];
    else x[1]=b[1],x[2]=b[2];
    return x;
}
void valt(int cs, int pos)
{
    mn[cs][1]=pos;
    mn[cs][2]=cs;
    if(val[cs].empty())
    {
        mn[cs][0]=inf,mx[cs]=minf;
    }
    else
    {
        mn[cs][0]=val[cs].begin()->first;
        mx[cs]=val[cs].rbegin()->first;

    }
}
void be(int cs, int tl, int tr, int pos, int ert)
{
    if(tl==tr)
    {
        val[cs][ert]++;
        valt(cs,pos);
        return;
    }
    int mid=(tl+tr)/2;
    if(pos<=mid) be(2*cs,tl,mid,pos,ert);
    else be(2*cs+1,mid+1,tr,pos,ert);
    mn[cs]=combine(mn[2*cs],mn[2*cs+1]);
    mx[cs]=max(mx[2*cs],mx[2*cs+1]);
}
int mxquery(int cs, int tl, int tr, int l, int r)
{
    if(l>r) return minf;
    if(l==tl && r==tr) return mx[cs];
    int mid=(tl+tr)/2;
    return max(mxquery(2*cs,tl,mid,l,min(r,mid)),mxquery(2*cs+1,mid+1,tr,max(mid+1,l),r));
}
array<int, 3> mnquery(int cs, int tl, int tr, int l, int r)
{
    if(l>r) return nagy;
    if(l==tl && r==tr) return mn[cs];
    int mid=(tl+tr)/2;
    return combine(mnquery(2*cs,tl,mid,l,min(r,mid)),mnquery(2*cs+1,mid+1,tr,max(mid+1,l),r));
}
void ki(int cs, int tl, int tr, int pos)
{
    if(tl==tr)
    {
        int x=val[cs].begin()->first;
        val[cs][x]--;
        if(val[cs][x]==0) val[cs].erase(x);
        valt(cs,pos);
        return;
    }
    int mid=(tl+tr)/2;
    if(pos<=mid) ki(2*cs,tl,mid,pos);
    else ki(2*cs+1,mid+1,tr,pos);
    mx[cs]=max(mx[2*cs],mx[2*cs+1]);
    mn[cs]=combine(mn[2*cs],mn[2*cs+1]);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    for(int i=0; i<4*c; i++)
        mn[i][0]=inf,mx[i]=minf;
    int n; cin>>n;
    vector<int> pontok;
    vector<array<int, 2>> v(n);
    for(auto &[a,b]:v)
    {
        cin>>a>>b;
        pontok.push_back(a);
        pontok.push_back(b);
    }
    sort(all(pontok));
    pontok.erase(unique(all(pontok)),pontok.end());
    for(auto &[a,b]:v)
    {
        a=lower_bound(all(pontok),a)-pontok.begin();
        b=lower_bound(all(pontok),b)-pontok.begin();
    }
    int mer=sz(pontok)-1;
    int cnt=0;
    for(auto &[a,b]:v)
    {
        if(mxquery(1,0,mer,a+1,mer)>b)
        {
            cout<<cnt<<"\n";
            continue;
        }
        be(1,0,mer,a,b);
        cnt++;
        while(1)
        {
            array<int, 3> x=mnquery(1,0,mer,0,a-1);
            if(x[0]>=b) break;
            ki(1,0,mer,x[1]);
            cnt--;
        }
        cout<<cnt<<"\n";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms2868 KiB
2Runtime error67ms6052 KiB
subtask20/15
3Wrong answer4ms3052 KiB
4Wrong answer4ms3060 KiB
5Wrong answer7ms2868 KiB
6Wrong answer14ms3380 KiB
7Runtime error34ms4616 KiB
8Runtime error65ms5880 KiB
subtask30/15
9Wrong answer4ms2868 KiB
10Wrong answer4ms2856 KiB
11Wrong answer7ms2868 KiB
12Wrong answer13ms3316 KiB
13Runtime error39ms4536 KiB
14Runtime error79ms6060 KiB
15Runtime error74ms6088 KiB
subtask40/15
16Wrong answer4ms3060 KiB
17Wrong answer8ms3124 KiB
18Wrong answer13ms3380 KiB
19Runtime error32ms4532 KiB
20Runtime error65ms6060 KiB
subtask50/15
21Wrong answer4ms2872 KiB
22Wrong answer3ms2868 KiB
23Wrong answer4ms2868 KiB
24Wrong answer4ms2868 KiB
25Wrong answer3ms2976 KiB
26Wrong answer4ms2868 KiB
subtask60/40
27Wrong answer3ms3060 KiB
28Runtime error65ms4784 KiB
29Wrong answer4ms3052 KiB
30Wrong answer4ms3060 KiB
31Wrong answer7ms2868 KiB
32Wrong answer14ms3380 KiB
33Runtime error34ms4616 KiB
34Runtime error65ms5880 KiB
35Wrong answer4ms2868 KiB
36Wrong answer4ms2856 KiB
37Wrong answer7ms2868 KiB
38Wrong answer13ms3316 KiB
39Runtime error39ms4536 KiB
40Runtime error79ms6060 KiB
41Runtime error74ms6088 KiB
42Wrong answer4ms3060 KiB
43Wrong answer8ms3124 KiB
44Wrong answer13ms3380 KiB
45Runtime error32ms4532 KiB
46Runtime error65ms6060 KiB
47Wrong answer4ms2872 KiB
48Wrong answer3ms2868 KiB
49Wrong answer4ms2868 KiB
50Wrong answer4ms2868 KiB
51Wrong answer3ms2976 KiB
52Wrong answer4ms2868 KiB
53Runtime error72ms6060 KiB
54Wrong answer4ms3064 KiB
55Wrong answer7ms2868 KiB
56Wrong answer10ms3564 KiB
57Runtime error34ms4612 KiB
58Runtime error39ms4724 KiB
59Runtime error72ms5976 KiB
60Runtime error67ms6060 KiB
61Runtime error65ms5804 KiB
62Runtime error67ms5860 KiB