답안 #986579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986579 2024-05-20T20:06:49 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;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    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:194:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  194 |             for(j=0; j<vec.size(); j++)
      |                      ~^~~~~~~~~~~
Main.cpp:203:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  203 |         for(j=0; j<vec.size(); j++)
      |                  ~^~~~~~~~~~~
Main.cpp:214:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ura>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  214 |         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 285 ms 276772 KB Output is correct
2 Correct 142 ms 276052 KB Output is correct
3 Correct 119 ms 275796 KB Output is correct
4 Correct 114 ms 275792 KB Output is correct
5 Correct 274 ms 276888 KB Output is correct
6 Correct 145 ms 275920 KB Output is correct
7 Correct 121 ms 275868 KB Output is correct
8 Correct 154 ms 275912 KB Output is correct
9 Correct 452 ms 277252 KB Output is correct
10 Correct 262 ms 276820 KB Output is correct
11 Correct 236 ms 276796 KB Output is correct
12 Correct 240 ms 276820 KB Output is correct
13 Correct 373 ms 277272 KB Output is correct
14 Correct 330 ms 277072 KB Output is correct
15 Correct 322 ms 277268 KB Output is correct
16 Correct 325 ms 277056 KB Output is correct
17 Correct 275 ms 276768 KB Output is correct
18 Correct 147 ms 276064 KB Output is correct
19 Correct 125 ms 275796 KB Output is correct
20 Correct 116 ms 275668 KB Output is correct
21 Correct 265 ms 276860 KB Output is correct
22 Correct 181 ms 276132 KB Output is correct
23 Correct 129 ms 275980 KB Output is correct
24 Correct 122 ms 275780 KB Output is correct
25 Correct 310 ms 277120 KB Output is correct
26 Correct 271 ms 277332 KB Output is correct
27 Correct 229 ms 276692 KB Output is correct
28 Correct 255 ms 277008 KB Output is correct
29 Correct 321 ms 277184 KB Output is correct
30 Correct 322 ms 277272 KB Output is correct
31 Correct 322 ms 277292 KB Output is correct
32 Correct 328 ms 277280 KB Output is correct
33 Correct 122 ms 275908 KB Output is correct
34 Correct 116 ms 275808 KB Output is correct
35 Correct 114 ms 275732 KB Output is correct
36 Correct 116 ms 275852 KB Output is correct
37 Correct 128 ms 275792 KB Output is correct
38 Correct 123 ms 275952 KB Output is correct
39 Correct 136 ms 275844 KB Output is correct
40 Correct 121 ms 275708 KB Output is correct
41 Correct 221 ms 276644 KB Output is correct
42 Correct 131 ms 275932 KB Output is correct
43 Correct 122 ms 276088 KB Output is correct
44 Correct 116 ms 275692 KB Output is correct
45 Correct 215 ms 276592 KB Output is correct
46 Correct 128 ms 276020 KB Output is correct
47 Correct 119 ms 275852 KB Output is correct
48 Correct 117 ms 275864 KB Output is correct
49 Correct 234 ms 276728 KB Output is correct
50 Correct 249 ms 276768 KB Output is correct
51 Correct 239 ms 276760 KB Output is correct
52 Correct 239 ms 276764 KB Output is correct
53 Correct 232 ms 276764 KB Output is correct
54 Correct 237 ms 276560 KB Output is correct
55 Correct 232 ms 276532 KB Output is correct
56 Correct 265 ms 276644 KB Output is correct
57 Correct 233 ms 276804 KB Output is correct
58 Correct 242 ms 277076 KB Output is correct
59 Correct 291 ms 277164 KB Output is correct
60 Correct 310 ms 277528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 276772 KB Output is correct
2 Correct 142 ms 276052 KB Output is correct
3 Correct 119 ms 275796 KB Output is correct
4 Correct 114 ms 275792 KB Output is correct
5 Correct 274 ms 276888 KB Output is correct
6 Correct 145 ms 275920 KB Output is correct
7 Correct 121 ms 275868 KB Output is correct
8 Correct 154 ms 275912 KB Output is correct
9 Correct 452 ms 277252 KB Output is correct
10 Correct 262 ms 276820 KB Output is correct
11 Correct 236 ms 276796 KB Output is correct
12 Correct 240 ms 276820 KB Output is correct
13 Correct 373 ms 277272 KB Output is correct
14 Correct 330 ms 277072 KB Output is correct
15 Correct 322 ms 277268 KB Output is correct
16 Correct 325 ms 277056 KB Output is correct
17 Correct 275 ms 276768 KB Output is correct
18 Correct 147 ms 276064 KB Output is correct
19 Correct 125 ms 275796 KB Output is correct
20 Correct 116 ms 275668 KB Output is correct
21 Correct 265 ms 276860 KB Output is correct
22 Correct 181 ms 276132 KB Output is correct
23 Correct 129 ms 275980 KB Output is correct
24 Correct 122 ms 275780 KB Output is correct
25 Correct 310 ms 277120 KB Output is correct
26 Correct 271 ms 277332 KB Output is correct
27 Correct 229 ms 276692 KB Output is correct
28 Correct 255 ms 277008 KB Output is correct
29 Correct 321 ms 277184 KB Output is correct
30 Correct 322 ms 277272 KB Output is correct
31 Correct 322 ms 277292 KB Output is correct
32 Correct 328 ms 277280 KB Output is correct
33 Correct 122 ms 275908 KB Output is correct
34 Correct 116 ms 275808 KB Output is correct
35 Correct 114 ms 275732 KB Output is correct
36 Correct 116 ms 275852 KB Output is correct
37 Correct 128 ms 275792 KB Output is correct
38 Correct 123 ms 275952 KB Output is correct
39 Correct 136 ms 275844 KB Output is correct
40 Correct 121 ms 275708 KB Output is correct
41 Correct 221 ms 276644 KB Output is correct
42 Correct 131 ms 275932 KB Output is correct
43 Correct 122 ms 276088 KB Output is correct
44 Correct 116 ms 275692 KB Output is correct
45 Correct 215 ms 276592 KB Output is correct
46 Correct 128 ms 276020 KB Output is correct
47 Correct 119 ms 275852 KB Output is correct
48 Correct 117 ms 275864 KB Output is correct
49 Correct 234 ms 276728 KB Output is correct
50 Correct 249 ms 276768 KB Output is correct
51 Correct 239 ms 276760 KB Output is correct
52 Correct 239 ms 276764 KB Output is correct
53 Correct 232 ms 276764 KB Output is correct
54 Correct 237 ms 276560 KB Output is correct
55 Correct 232 ms 276532 KB Output is correct
56 Correct 265 ms 276644 KB Output is correct
57 Correct 233 ms 276804 KB Output is correct
58 Correct 242 ms 277076 KB Output is correct
59 Correct 291 ms 277164 KB Output is correct
60 Correct 310 ms 277528 KB Output is correct
61 Correct 114 ms 275876 KB Output is correct
62 Correct 115 ms 275796 KB Output is correct
63 Correct 122 ms 275680 KB Output is correct
64 Execution timed out 7126 ms 742856 KB Time limit exceeded
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 276772 KB Output is correct
2 Correct 142 ms 276052 KB Output is correct
3 Correct 119 ms 275796 KB Output is correct
4 Correct 114 ms 275792 KB Output is correct
5 Correct 274 ms 276888 KB Output is correct
6 Correct 145 ms 275920 KB Output is correct
7 Correct 121 ms 275868 KB Output is correct
8 Correct 154 ms 275912 KB Output is correct
9 Correct 452 ms 277252 KB Output is correct
10 Correct 262 ms 276820 KB Output is correct
11 Correct 236 ms 276796 KB Output is correct
12 Correct 240 ms 276820 KB Output is correct
13 Correct 373 ms 277272 KB Output is correct
14 Correct 330 ms 277072 KB Output is correct
15 Correct 322 ms 277268 KB Output is correct
16 Correct 325 ms 277056 KB Output is correct
17 Correct 275 ms 276768 KB Output is correct
18 Correct 147 ms 276064 KB Output is correct
19 Correct 125 ms 275796 KB Output is correct
20 Correct 116 ms 275668 KB Output is correct
21 Correct 265 ms 276860 KB Output is correct
22 Correct 181 ms 276132 KB Output is correct
23 Correct 129 ms 275980 KB Output is correct
24 Correct 122 ms 275780 KB Output is correct
25 Correct 310 ms 277120 KB Output is correct
26 Correct 271 ms 277332 KB Output is correct
27 Correct 229 ms 276692 KB Output is correct
28 Correct 255 ms 277008 KB Output is correct
29 Correct 321 ms 277184 KB Output is correct
30 Correct 322 ms 277272 KB Output is correct
31 Correct 322 ms 277292 KB Output is correct
32 Correct 328 ms 277280 KB Output is correct
33 Correct 122 ms 275908 KB Output is correct
34 Correct 116 ms 275808 KB Output is correct
35 Correct 114 ms 275732 KB Output is correct
36 Correct 116 ms 275852 KB Output is correct
37 Correct 128 ms 275792 KB Output is correct
38 Correct 123 ms 275952 KB Output is correct
39 Correct 136 ms 275844 KB Output is correct
40 Correct 121 ms 275708 KB Output is correct
41 Correct 221 ms 276644 KB Output is correct
42 Correct 131 ms 275932 KB Output is correct
43 Correct 122 ms 276088 KB Output is correct
44 Correct 116 ms 275692 KB Output is correct
45 Correct 215 ms 276592 KB Output is correct
46 Correct 128 ms 276020 KB Output is correct
47 Correct 119 ms 275852 KB Output is correct
48 Correct 117 ms 275864 KB Output is correct
49 Correct 234 ms 276728 KB Output is correct
50 Correct 249 ms 276768 KB Output is correct
51 Correct 239 ms 276760 KB Output is correct
52 Correct 239 ms 276764 KB Output is correct
53 Correct 232 ms 276764 KB Output is correct
54 Correct 237 ms 276560 KB Output is correct
55 Correct 232 ms 276532 KB Output is correct
56 Correct 265 ms 276644 KB Output is correct
57 Correct 233 ms 276804 KB Output is correct
58 Correct 242 ms 277076 KB Output is correct
59 Correct 291 ms 277164 KB Output is correct
60 Correct 310 ms 277528 KB Output is correct
61 Correct 114 ms 275876 KB Output is correct
62 Correct 115 ms 275796 KB Output is correct
63 Correct 122 ms 275680 KB Output is correct
64 Execution timed out 7126 ms 742856 KB Time limit exceeded
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 584 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 276772 KB Output is correct
2 Correct 142 ms 276052 KB Output is correct
3 Correct 119 ms 275796 KB Output is correct
4 Correct 114 ms 275792 KB Output is correct
5 Correct 274 ms 276888 KB Output is correct
6 Correct 145 ms 275920 KB Output is correct
7 Correct 121 ms 275868 KB Output is correct
8 Correct 154 ms 275912 KB Output is correct
9 Correct 452 ms 277252 KB Output is correct
10 Correct 262 ms 276820 KB Output is correct
11 Correct 236 ms 276796 KB Output is correct
12 Correct 240 ms 276820 KB Output is correct
13 Correct 373 ms 277272 KB Output is correct
14 Correct 330 ms 277072 KB Output is correct
15 Correct 322 ms 277268 KB Output is correct
16 Correct 325 ms 277056 KB Output is correct
17 Correct 275 ms 276768 KB Output is correct
18 Correct 147 ms 276064 KB Output is correct
19 Correct 125 ms 275796 KB Output is correct
20 Correct 116 ms 275668 KB Output is correct
21 Correct 265 ms 276860 KB Output is correct
22 Correct 181 ms 276132 KB Output is correct
23 Correct 129 ms 275980 KB Output is correct
24 Correct 122 ms 275780 KB Output is correct
25 Correct 310 ms 277120 KB Output is correct
26 Correct 271 ms 277332 KB Output is correct
27 Correct 229 ms 276692 KB Output is correct
28 Correct 255 ms 277008 KB Output is correct
29 Correct 321 ms 277184 KB Output is correct
30 Correct 322 ms 277272 KB Output is correct
31 Correct 322 ms 277292 KB Output is correct
32 Correct 328 ms 277280 KB Output is correct
33 Correct 122 ms 275908 KB Output is correct
34 Correct 116 ms 275808 KB Output is correct
35 Correct 114 ms 275732 KB Output is correct
36 Correct 116 ms 275852 KB Output is correct
37 Correct 128 ms 275792 KB Output is correct
38 Correct 123 ms 275952 KB Output is correct
39 Correct 136 ms 275844 KB Output is correct
40 Correct 121 ms 275708 KB Output is correct
41 Correct 221 ms 276644 KB Output is correct
42 Correct 131 ms 275932 KB Output is correct
43 Correct 122 ms 276088 KB Output is correct
44 Correct 116 ms 275692 KB Output is correct
45 Correct 215 ms 276592 KB Output is correct
46 Correct 128 ms 276020 KB Output is correct
47 Correct 119 ms 275852 KB Output is correct
48 Correct 117 ms 275864 KB Output is correct
49 Correct 234 ms 276728 KB Output is correct
50 Correct 249 ms 276768 KB Output is correct
51 Correct 239 ms 276760 KB Output is correct
52 Correct 239 ms 276764 KB Output is correct
53 Correct 232 ms 276764 KB Output is correct
54 Correct 237 ms 276560 KB Output is correct
55 Correct 232 ms 276532 KB Output is correct
56 Correct 265 ms 276644 KB Output is correct
57 Correct 233 ms 276804 KB Output is correct
58 Correct 242 ms 277076 KB Output is correct
59 Correct 291 ms 277164 KB Output is correct
60 Correct 310 ms 277528 KB Output is correct
61 Correct 114 ms 275876 KB Output is correct
62 Correct 115 ms 275796 KB Output is correct
63 Correct 122 ms 275680 KB Output is correct
64 Execution timed out 7126 ms 742856 KB Time limit exceeded
65 Halted 0 ms 0 KB -