답안 #986578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986578 2024-05-20T20:05:43 Z activedeltorre Interval Collection (CCO20_day2problem2) C++14
3 / 25
7000 ms 1048576 KB
#include <iostream>
#include <vector>
#include <set>

using namespace std;
struct ura
{
    int a,b;
};
vector<ura>vecus[500005];
vector<ura>vec;
const int nmax=10000005;
int aint[nmax*4];
int aint2[nmax*4];
int inf=1e9+5;
int inter(int i,int j)
{
    return max(0,min(vec[i].b,vec[j].b)-max(vec[i].a,vec[j].a));
}
int reun(int i,int j)
{
    return max(vec[i].b,vec[j].b)-min(vec[i].a,vec[j].a);
}
long long distsol,cost;
multiset<int>lfend;
multiset<int>rgend;
/// qr1 pe partea dreapta
struct undos
{
    int unde,pozupdate,delacat;
};
vector<undos>oper;
int qr1(int node,int st,int dr,int qst,int qdr)
{
    if(st>qdr || st>dr || qst>dr || qst>qdr)
    {
        return inf;
    }
    if(qst<=st && dr<=qdr)
    {
        return aint[node];
    }
    int mij=(st+dr)/2;
    return min(qr1(node*2,st,mij,qst,qdr),qr1(node*2+1,mij+1,dr,qst,qdr));
}
int qr2(int node,int st,int dr,int qst,int qdr)
{
    if(st>qdr || st>dr || qst>dr || qst>qdr)
    {
        return -inf;
    }
    if(qst<=st && dr<=qdr)
    {
        return aint2[node];
    }
    int mij=(st+dr)/2;
    return max(qr2(node*2,st,mij,qst,qdr),qr2(node*2+1,mij+1,dr,qst,qdr));
}
void update1(int node,int st,int dr,int poz,int val,int smech)
{
    if(st>poz || poz>dr)
    {
        return ;
    }
    if(poz<=st && dr<=poz)
    {
        if(smech==1)
        {
            aint[node]=val;
        }
        else
        {
            oper.push_back({1,poz,aint[node]});
            aint[node]=min(aint[node],val);
        }
        return;
    }
    int mij=(st+dr)/2;
    update1(node*2,st,mij,poz,val,smech);
    update1(node*2+1,mij+1,dr,poz,val,smech);
    aint[node]=min(aint[node*2],aint[node*2+1]);
}
void update2(int node,int st,int dr,int poz,int val,int smech)
{
    if(st>poz || poz>dr)
    {
        return ;
    }
    if(poz<=st && dr<=poz)
    {
        if(smech==1)
        {
            aint2[node]=val;
        }
        else
        {
            oper.push_back({2,poz,aint2[node]});
            aint2[node]=max(aint2[node],val);
        }
        return;
    }
    int mij=(st+dr)/2;
    update2(node*2,st,mij,poz,val,smech);
    update2(node*2+1,mij+1,dr,poz,val,smech);
    aint2[node]=max(aint2[node*2],aint2[node*2+1]);
}
void clr(int node,int st,int dr)
{
    aint2[node]=-inf;
    aint[node]=inf;
    if(st!=dr)
    {
        int mij=(st+dr)/2;
        clr(node*2,st,mij);
        clr(node*2+1,mij+1,dr);
    }
}
multiset<pair<int,int> >solutii;
void undo()
{
    undos a;
    a=oper.back();
    if(a.unde==1)
    {
        update1(1,1,nmax,a.pozupdate,a.delacat,1);
    }
    else
    {
        update2(1,1,nmax,a.pozupdate,a.delacat,1);
    }
    oper.pop_back();
}
void add(ura x)
{
    int sol=inf,cost=inf,supra=inf,nosupra=inf,supra1=inf,nosupra1=inf;
    if(lfend.size() && x.b>*prev(lfend.end()))
    {
        supra=x.b-*prev(lfend.end());
        nosupra=qr1(1,1,nmax,*prev(lfend.end()),nmax)-x.a;
    }
    else if(lfend.size())
    {
        supra=0;
        nosupra=qr1(1,1,nmax,x.b,nmax)-x.a;
    }
    lfend.insert(x.a);
    update1(1,1,nmax,x.a,x.b,0);
    if(rgend.size() && x.a<=*rgend.begin())
    {
        supra1=*rgend.begin()-x.a;
        nosupra1=x.b-qr2(1,1,nmax,1,*rgend.begin());
    }
    else if(rgend.size())
    {
        supra1=0;
        nosupra1=x.b-qr2(1,1,nmax,1,x.a);
    }
    rgend.insert(x.b);
    update2(1,1,nmax,x.b,x.a,0);
    if(supra1<supra)
    {
        swap(supra1,supra);
        swap(nosupra1,nosupra);
    }
    else if(supra1==supra)
    {
        nosupra=min(nosupra1,nosupra);
    }
    if(supra>x.b-x.a)
    {
        supra=x.b-x.a;
        nosupra=x.b-x.a;
    }
    solutii.insert({supra,nosupra});
}
int main()
{
    int n,i,j,k,l,r,z;
    cin>>n;
    char tip;
    for(i=1; i<=n; i++)
    {
        cin>>tip;
        if(tip=='A')
        {
            cin>>l>>r;
            vec.push_back({l,r});
        }
        else if(tip=='R')
        {
            cin>>l>>r;
            for(j=0; j<vec.size(); j++)
            {
                if(vec[j].a==l && vec[j].b==r)
                {
                    vec.erase(vec.begin()+j);
                    break;
                }
            }
        }
        for(j=0; j<vec.size(); j++)
            vecus[i].push_back({vec[j]});
    }
    clr(1,1,nmax);
    for(i=1; i<=n; i++)
    {
        distsol=inf;
        cost=0;
        lfend.clear();
        rgend.clear();
        solutii.clear();
        for(j=0; j<vecus[i].size(); j++)
        {
            add(vecus[i][j]);
        }
        cout<<solutii.begin()->second<<'\n';
        while(oper.size()>0)
        {
            undo();
        }
    }
    return 0;
}

Compilation message

Main.cpp: In function 'void add(ura)':
Main.cpp:135:9: warning: unused variable 'sol' [-Wunused-variable]
  135 |     int sol=inf,cost=inf,supra=inf,nosupra=inf,supra1=inf,nosupra1=inf;
      |         ^~~
Main.cpp:135:17: warning: unused variable 'cost' [-Wunused-variable]
  135 |     int sol=inf,cost=inf,supra=inf,nosupra=inf,supra1=inf,nosupra1=inf;
      |                 ^~~~
Main.cpp: In function 'int main()':
Main.cpp:192:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  192 |             for(j=0; j<vec.size(); j++)
      |                      ~^~~~~~~~~~~
Main.cpp:201:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  201 |         for(j=0; j<vec.size(); j++)
      |                  ~^~~~~~~~~~~
Main.cpp:212:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  212 |         for(j=0; j<vecus[i].size(); j++)
      |                  ~^~~~~~~~~~~~~~~~
Main.cpp:178:15: warning: unused variable 'k' [-Wunused-variable]
  178 |     int n,i,j,k,l,r,z;
      |               ^
Main.cpp:178:21: warning: unused variable 'z' [-Wunused-variable]
  178 |     int n,i,j,k,l,r,z;
      |                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 276756 KB Output is correct
2 Correct 143 ms 276044 KB Output is correct
3 Correct 125 ms 275732 KB Output is correct
4 Correct 123 ms 275800 KB Output is correct
5 Correct 273 ms 277076 KB Output is correct
6 Correct 148 ms 275960 KB Output is correct
7 Correct 127 ms 275916 KB Output is correct
8 Correct 143 ms 276000 KB Output is correct
9 Correct 300 ms 277076 KB Output is correct
10 Correct 248 ms 277064 KB Output is correct
11 Correct 235 ms 276560 KB Output is correct
12 Correct 290 ms 276864 KB Output is correct
13 Correct 498 ms 277372 KB Output is correct
14 Correct 328 ms 277212 KB Output is correct
15 Correct 328 ms 277288 KB Output is correct
16 Correct 348 ms 277072 KB Output is correct
17 Correct 270 ms 276560 KB Output is correct
18 Correct 161 ms 276052 KB Output is correct
19 Correct 119 ms 275828 KB Output is correct
20 Correct 123 ms 275692 KB Output is correct
21 Correct 268 ms 276820 KB Output is correct
22 Correct 158 ms 276336 KB Output is correct
23 Correct 123 ms 275792 KB Output is correct
24 Correct 124 ms 275796 KB Output is correct
25 Correct 298 ms 277332 KB Output is correct
26 Correct 249 ms 276780 KB Output is correct
27 Correct 256 ms 276564 KB Output is correct
28 Correct 235 ms 276788 KB Output is correct
29 Correct 323 ms 277276 KB Output is correct
30 Correct 370 ms 277300 KB Output is correct
31 Correct 321 ms 277272 KB Output is correct
32 Correct 329 ms 277264 KB Output is correct
33 Correct 136 ms 275796 KB Output is correct
34 Correct 120 ms 275792 KB Output is correct
35 Correct 125 ms 275780 KB Output is correct
36 Correct 123 ms 275868 KB Output is correct
37 Correct 126 ms 275796 KB Output is correct
38 Correct 122 ms 275872 KB Output is correct
39 Correct 121 ms 275700 KB Output is correct
40 Correct 119 ms 275832 KB Output is correct
41 Correct 224 ms 276560 KB Output is correct
42 Correct 135 ms 275796 KB Output is correct
43 Correct 119 ms 275756 KB Output is correct
44 Correct 123 ms 275828 KB Output is correct
45 Correct 218 ms 276828 KB Output is correct
46 Correct 134 ms 275792 KB Output is correct
47 Correct 120 ms 275832 KB Output is correct
48 Correct 118 ms 275664 KB Output is correct
49 Correct 241 ms 276752 KB Output is correct
50 Correct 243 ms 276560 KB Output is correct
51 Correct 232 ms 276560 KB Output is correct
52 Correct 238 ms 276564 KB Output is correct
53 Correct 233 ms 276676 KB Output is correct
54 Correct 249 ms 276772 KB Output is correct
55 Correct 235 ms 276576 KB Output is correct
56 Correct 242 ms 276756 KB Output is correct
57 Correct 230 ms 276560 KB Output is correct
58 Correct 241 ms 276560 KB Output is correct
59 Correct 307 ms 277284 KB Output is correct
60 Correct 288 ms 277276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 276756 KB Output is correct
2 Correct 143 ms 276044 KB Output is correct
3 Correct 125 ms 275732 KB Output is correct
4 Correct 123 ms 275800 KB Output is correct
5 Correct 273 ms 277076 KB Output is correct
6 Correct 148 ms 275960 KB Output is correct
7 Correct 127 ms 275916 KB Output is correct
8 Correct 143 ms 276000 KB Output is correct
9 Correct 300 ms 277076 KB Output is correct
10 Correct 248 ms 277064 KB Output is correct
11 Correct 235 ms 276560 KB Output is correct
12 Correct 290 ms 276864 KB Output is correct
13 Correct 498 ms 277372 KB Output is correct
14 Correct 328 ms 277212 KB Output is correct
15 Correct 328 ms 277288 KB Output is correct
16 Correct 348 ms 277072 KB Output is correct
17 Correct 270 ms 276560 KB Output is correct
18 Correct 161 ms 276052 KB Output is correct
19 Correct 119 ms 275828 KB Output is correct
20 Correct 123 ms 275692 KB Output is correct
21 Correct 268 ms 276820 KB Output is correct
22 Correct 158 ms 276336 KB Output is correct
23 Correct 123 ms 275792 KB Output is correct
24 Correct 124 ms 275796 KB Output is correct
25 Correct 298 ms 277332 KB Output is correct
26 Correct 249 ms 276780 KB Output is correct
27 Correct 256 ms 276564 KB Output is correct
28 Correct 235 ms 276788 KB Output is correct
29 Correct 323 ms 277276 KB Output is correct
30 Correct 370 ms 277300 KB Output is correct
31 Correct 321 ms 277272 KB Output is correct
32 Correct 329 ms 277264 KB Output is correct
33 Correct 136 ms 275796 KB Output is correct
34 Correct 120 ms 275792 KB Output is correct
35 Correct 125 ms 275780 KB Output is correct
36 Correct 123 ms 275868 KB Output is correct
37 Correct 126 ms 275796 KB Output is correct
38 Correct 122 ms 275872 KB Output is correct
39 Correct 121 ms 275700 KB Output is correct
40 Correct 119 ms 275832 KB Output is correct
41 Correct 224 ms 276560 KB Output is correct
42 Correct 135 ms 275796 KB Output is correct
43 Correct 119 ms 275756 KB Output is correct
44 Correct 123 ms 275828 KB Output is correct
45 Correct 218 ms 276828 KB Output is correct
46 Correct 134 ms 275792 KB Output is correct
47 Correct 120 ms 275832 KB Output is correct
48 Correct 118 ms 275664 KB Output is correct
49 Correct 241 ms 276752 KB Output is correct
50 Correct 243 ms 276560 KB Output is correct
51 Correct 232 ms 276560 KB Output is correct
52 Correct 238 ms 276564 KB Output is correct
53 Correct 233 ms 276676 KB Output is correct
54 Correct 249 ms 276772 KB Output is correct
55 Correct 235 ms 276576 KB Output is correct
56 Correct 242 ms 276756 KB Output is correct
57 Correct 230 ms 276560 KB Output is correct
58 Correct 241 ms 276560 KB Output is correct
59 Correct 307 ms 277284 KB Output is correct
60 Correct 288 ms 277276 KB Output is correct
61 Correct 135 ms 275792 KB Output is correct
62 Correct 119 ms 276308 KB Output is correct
63 Correct 120 ms 275796 KB Output is correct
64 Execution timed out 7067 ms 743128 KB Time limit exceeded
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 276756 KB Output is correct
2 Correct 143 ms 276044 KB Output is correct
3 Correct 125 ms 275732 KB Output is correct
4 Correct 123 ms 275800 KB Output is correct
5 Correct 273 ms 277076 KB Output is correct
6 Correct 148 ms 275960 KB Output is correct
7 Correct 127 ms 275916 KB Output is correct
8 Correct 143 ms 276000 KB Output is correct
9 Correct 300 ms 277076 KB Output is correct
10 Correct 248 ms 277064 KB Output is correct
11 Correct 235 ms 276560 KB Output is correct
12 Correct 290 ms 276864 KB Output is correct
13 Correct 498 ms 277372 KB Output is correct
14 Correct 328 ms 277212 KB Output is correct
15 Correct 328 ms 277288 KB Output is correct
16 Correct 348 ms 277072 KB Output is correct
17 Correct 270 ms 276560 KB Output is correct
18 Correct 161 ms 276052 KB Output is correct
19 Correct 119 ms 275828 KB Output is correct
20 Correct 123 ms 275692 KB Output is correct
21 Correct 268 ms 276820 KB Output is correct
22 Correct 158 ms 276336 KB Output is correct
23 Correct 123 ms 275792 KB Output is correct
24 Correct 124 ms 275796 KB Output is correct
25 Correct 298 ms 277332 KB Output is correct
26 Correct 249 ms 276780 KB Output is correct
27 Correct 256 ms 276564 KB Output is correct
28 Correct 235 ms 276788 KB Output is correct
29 Correct 323 ms 277276 KB Output is correct
30 Correct 370 ms 277300 KB Output is correct
31 Correct 321 ms 277272 KB Output is correct
32 Correct 329 ms 277264 KB Output is correct
33 Correct 136 ms 275796 KB Output is correct
34 Correct 120 ms 275792 KB Output is correct
35 Correct 125 ms 275780 KB Output is correct
36 Correct 123 ms 275868 KB Output is correct
37 Correct 126 ms 275796 KB Output is correct
38 Correct 122 ms 275872 KB Output is correct
39 Correct 121 ms 275700 KB Output is correct
40 Correct 119 ms 275832 KB Output is correct
41 Correct 224 ms 276560 KB Output is correct
42 Correct 135 ms 275796 KB Output is correct
43 Correct 119 ms 275756 KB Output is correct
44 Correct 123 ms 275828 KB Output is correct
45 Correct 218 ms 276828 KB Output is correct
46 Correct 134 ms 275792 KB Output is correct
47 Correct 120 ms 275832 KB Output is correct
48 Correct 118 ms 275664 KB Output is correct
49 Correct 241 ms 276752 KB Output is correct
50 Correct 243 ms 276560 KB Output is correct
51 Correct 232 ms 276560 KB Output is correct
52 Correct 238 ms 276564 KB Output is correct
53 Correct 233 ms 276676 KB Output is correct
54 Correct 249 ms 276772 KB Output is correct
55 Correct 235 ms 276576 KB Output is correct
56 Correct 242 ms 276756 KB Output is correct
57 Correct 230 ms 276560 KB Output is correct
58 Correct 241 ms 276560 KB Output is correct
59 Correct 307 ms 277284 KB Output is correct
60 Correct 288 ms 277276 KB Output is correct
61 Correct 135 ms 275792 KB Output is correct
62 Correct 119 ms 276308 KB Output is correct
63 Correct 120 ms 275796 KB Output is correct
64 Execution timed out 7067 ms 743128 KB Time limit exceeded
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 536 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 276756 KB Output is correct
2 Correct 143 ms 276044 KB Output is correct
3 Correct 125 ms 275732 KB Output is correct
4 Correct 123 ms 275800 KB Output is correct
5 Correct 273 ms 277076 KB Output is correct
6 Correct 148 ms 275960 KB Output is correct
7 Correct 127 ms 275916 KB Output is correct
8 Correct 143 ms 276000 KB Output is correct
9 Correct 300 ms 277076 KB Output is correct
10 Correct 248 ms 277064 KB Output is correct
11 Correct 235 ms 276560 KB Output is correct
12 Correct 290 ms 276864 KB Output is correct
13 Correct 498 ms 277372 KB Output is correct
14 Correct 328 ms 277212 KB Output is correct
15 Correct 328 ms 277288 KB Output is correct
16 Correct 348 ms 277072 KB Output is correct
17 Correct 270 ms 276560 KB Output is correct
18 Correct 161 ms 276052 KB Output is correct
19 Correct 119 ms 275828 KB Output is correct
20 Correct 123 ms 275692 KB Output is correct
21 Correct 268 ms 276820 KB Output is correct
22 Correct 158 ms 276336 KB Output is correct
23 Correct 123 ms 275792 KB Output is correct
24 Correct 124 ms 275796 KB Output is correct
25 Correct 298 ms 277332 KB Output is correct
26 Correct 249 ms 276780 KB Output is correct
27 Correct 256 ms 276564 KB Output is correct
28 Correct 235 ms 276788 KB Output is correct
29 Correct 323 ms 277276 KB Output is correct
30 Correct 370 ms 277300 KB Output is correct
31 Correct 321 ms 277272 KB Output is correct
32 Correct 329 ms 277264 KB Output is correct
33 Correct 136 ms 275796 KB Output is correct
34 Correct 120 ms 275792 KB Output is correct
35 Correct 125 ms 275780 KB Output is correct
36 Correct 123 ms 275868 KB Output is correct
37 Correct 126 ms 275796 KB Output is correct
38 Correct 122 ms 275872 KB Output is correct
39 Correct 121 ms 275700 KB Output is correct
40 Correct 119 ms 275832 KB Output is correct
41 Correct 224 ms 276560 KB Output is correct
42 Correct 135 ms 275796 KB Output is correct
43 Correct 119 ms 275756 KB Output is correct
44 Correct 123 ms 275828 KB Output is correct
45 Correct 218 ms 276828 KB Output is correct
46 Correct 134 ms 275792 KB Output is correct
47 Correct 120 ms 275832 KB Output is correct
48 Correct 118 ms 275664 KB Output is correct
49 Correct 241 ms 276752 KB Output is correct
50 Correct 243 ms 276560 KB Output is correct
51 Correct 232 ms 276560 KB Output is correct
52 Correct 238 ms 276564 KB Output is correct
53 Correct 233 ms 276676 KB Output is correct
54 Correct 249 ms 276772 KB Output is correct
55 Correct 235 ms 276576 KB Output is correct
56 Correct 242 ms 276756 KB Output is correct
57 Correct 230 ms 276560 KB Output is correct
58 Correct 241 ms 276560 KB Output is correct
59 Correct 307 ms 277284 KB Output is correct
60 Correct 288 ms 277276 KB Output is correct
61 Correct 135 ms 275792 KB Output is correct
62 Correct 119 ms 276308 KB Output is correct
63 Correct 120 ms 275796 KB Output is correct
64 Execution timed out 7067 ms 743128 KB Time limit exceeded
65 Halted 0 ms 0 KB -