Submission #277351

# Submission time Handle Problem Language Result Execution time Memory
277351 2020-08-21T04:51:40 Z 최은수(#5116) Interval Collection (CCO20_day2problem2) C++17
7 / 25
793 ms 48376 KB
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int q;
    cin>>q;
    if(q<=500)
    {
        vector<pi>v;
        while(q-->0)
        {
            char c;
            int l,r;
            cin>>c>>l>>r;
            if(c=='A')
                v.eb(l,r);
            else
                v.erase(find(all(v),pi(l,r)));
            int n=v.size();
            int ml=-inf,mr=inf;
            for(pi&t:v)
                ml=max(ml,t.fi),mr=min(mr,t.se);
            int ans=inf;
            if(ml>=mr)
            {
                for(int i=0;i<n;i++)
                    for(int j=i+1;j<n;j++)
                        if(v[i].fi>=v[j].se||v[j].fi>=v[i].se)
                            ans=min(ans,max(v[i].se,v[j].se)-min(v[i].fi,v[j].fi));
            }
            else
            {
                for(int i=0;i<n;i++)
                    for(int j=i;j<n;j++)
                        if((v[i].fi==ml||v[j].fi==ml)&&(v[i].se==mr||v[j].se==mr))
                            ans=min(ans,max(v[i].se,v[j].se)-min(v[i].fi,v[j].fi));
            }
            cout<<ans<<'\n';
        }
        cout.flush();
        return 0;
    }
    set<pi>st;
    multiset<int>ast;
    while(q-->0)
    {
        char c;
        int l,r;
        cin>>c>>l>>r;
        if(c=='A')
        {
            auto it=st.lower_bound(pi(l,r));
            if(it!=st.end())
            {
                int cr=it->se;
                ast.ep(cr-l);
                if(it!=st.begin())
                {
                    it--;
                    ast.erase(ast.find(cr-it->fi));
                    ast.ep(r-it->fi);
                }
            }
            else if(it!=st.begin())
            {
                it--;
                ast.ep(r-it->fi);
            }
            st.ep(l,r);
        }
        else
        {
            st.erase(pi(l,r));
            auto it=st.lower_bound(pi(l,r));
            if(it!=st.end())
            {
                int cr=it->se;
                ast.erase(ast.find(cr-l));
                if(it!=st.begin())
                {
                    it--;
                    ast.ep(cr-it->fi);
                    ast.erase(ast.find(r-it->fi));
                }
            }
            else if(it!=st.begin())
            {
                it--;
                ast.erase(ast.find(r-it->fi));
            }
        }
        if((int)st.size()==1)
            cout<<(st.begin()->se-st.begin()->fi)<<'\n';        
        else
            cout<<*ast.begin()<<'\n';
    }
    cout.flush();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 24 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 36 ms 384 KB Output is correct
10 Correct 19 ms 384 KB Output is correct
11 Correct 15 ms 384 KB Output is correct
12 Correct 21 ms 384 KB Output is correct
13 Correct 46 ms 384 KB Output is correct
14 Correct 50 ms 384 KB Output is correct
15 Correct 48 ms 504 KB Output is correct
16 Correct 48 ms 384 KB Output is correct
17 Correct 27 ms 396 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 29 ms 504 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 41 ms 512 KB Output is correct
26 Correct 23 ms 384 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 18 ms 384 KB Output is correct
29 Correct 53 ms 384 KB Output is correct
30 Correct 53 ms 384 KB Output is correct
31 Correct 50 ms 384 KB Output is correct
32 Correct 54 ms 392 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 13 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 12 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 13 ms 384 KB Output is correct
50 Correct 24 ms 384 KB Output is correct
51 Correct 13 ms 384 KB Output is correct
52 Correct 23 ms 288 KB Output is correct
53 Correct 13 ms 384 KB Output is correct
54 Correct 25 ms 384 KB Output is correct
55 Correct 13 ms 384 KB Output is correct
56 Correct 27 ms 384 KB Output is correct
57 Correct 13 ms 384 KB Output is correct
58 Correct 25 ms 384 KB Output is correct
59 Correct 36 ms 384 KB Output is correct
60 Correct 41 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 24 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 36 ms 384 KB Output is correct
10 Correct 19 ms 384 KB Output is correct
11 Correct 15 ms 384 KB Output is correct
12 Correct 21 ms 384 KB Output is correct
13 Correct 46 ms 384 KB Output is correct
14 Correct 50 ms 384 KB Output is correct
15 Correct 48 ms 504 KB Output is correct
16 Correct 48 ms 384 KB Output is correct
17 Correct 27 ms 396 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 29 ms 504 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 41 ms 512 KB Output is correct
26 Correct 23 ms 384 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 18 ms 384 KB Output is correct
29 Correct 53 ms 384 KB Output is correct
30 Correct 53 ms 384 KB Output is correct
31 Correct 50 ms 384 KB Output is correct
32 Correct 54 ms 392 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 13 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 12 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 13 ms 384 KB Output is correct
50 Correct 24 ms 384 KB Output is correct
51 Correct 13 ms 384 KB Output is correct
52 Correct 23 ms 288 KB Output is correct
53 Correct 13 ms 384 KB Output is correct
54 Correct 25 ms 384 KB Output is correct
55 Correct 13 ms 384 KB Output is correct
56 Correct 27 ms 384 KB Output is correct
57 Correct 13 ms 384 KB Output is correct
58 Correct 25 ms 384 KB Output is correct
59 Correct 36 ms 384 KB Output is correct
60 Correct 41 ms 384 KB Output is correct
61 Correct 0 ms 384 KB Output is correct
62 Correct 0 ms 288 KB Output is correct
63 Correct 0 ms 384 KB Output is correct
64 Incorrect 17 ms 1024 KB Output isn't correct
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 24 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 36 ms 384 KB Output is correct
10 Correct 19 ms 384 KB Output is correct
11 Correct 15 ms 384 KB Output is correct
12 Correct 21 ms 384 KB Output is correct
13 Correct 46 ms 384 KB Output is correct
14 Correct 50 ms 384 KB Output is correct
15 Correct 48 ms 504 KB Output is correct
16 Correct 48 ms 384 KB Output is correct
17 Correct 27 ms 396 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 29 ms 504 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 41 ms 512 KB Output is correct
26 Correct 23 ms 384 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 18 ms 384 KB Output is correct
29 Correct 53 ms 384 KB Output is correct
30 Correct 53 ms 384 KB Output is correct
31 Correct 50 ms 384 KB Output is correct
32 Correct 54 ms 392 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 13 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 12 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 13 ms 384 KB Output is correct
50 Correct 24 ms 384 KB Output is correct
51 Correct 13 ms 384 KB Output is correct
52 Correct 23 ms 288 KB Output is correct
53 Correct 13 ms 384 KB Output is correct
54 Correct 25 ms 384 KB Output is correct
55 Correct 13 ms 384 KB Output is correct
56 Correct 27 ms 384 KB Output is correct
57 Correct 13 ms 384 KB Output is correct
58 Correct 25 ms 384 KB Output is correct
59 Correct 36 ms 384 KB Output is correct
60 Correct 41 ms 384 KB Output is correct
61 Correct 0 ms 384 KB Output is correct
62 Correct 0 ms 288 KB Output is correct
63 Correct 0 ms 384 KB Output is correct
64 Incorrect 17 ms 1024 KB Output isn't correct
65 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 180 ms 19628 KB Output is correct
2 Correct 185 ms 19576 KB Output is correct
3 Correct 376 ms 38904 KB Output is correct
4 Correct 384 ms 38776 KB Output is correct
5 Correct 479 ms 48376 KB Output is correct
6 Correct 485 ms 48376 KB Output is correct
7 Correct 683 ms 2808 KB Output is correct
8 Correct 514 ms 1912 KB Output is correct
9 Correct 488 ms 1788 KB Output is correct
10 Correct 755 ms 4472 KB Output is correct
11 Correct 509 ms 2040 KB Output is correct
12 Correct 486 ms 1948 KB Output is correct
13 Correct 793 ms 5268 KB Output is correct
14 Correct 538 ms 1976 KB Output is correct
15 Correct 491 ms 1856 KB Output is correct
16 Correct 353 ms 2040 KB Output is correct
17 Correct 342 ms 1912 KB Output is correct
18 Correct 353 ms 1964 KB Output is correct
19 Correct 374 ms 1940 KB Output is correct
20 Correct 358 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 24 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 36 ms 384 KB Output is correct
10 Correct 19 ms 384 KB Output is correct
11 Correct 15 ms 384 KB Output is correct
12 Correct 21 ms 384 KB Output is correct
13 Correct 46 ms 384 KB Output is correct
14 Correct 50 ms 384 KB Output is correct
15 Correct 48 ms 504 KB Output is correct
16 Correct 48 ms 384 KB Output is correct
17 Correct 27 ms 396 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 29 ms 504 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 41 ms 512 KB Output is correct
26 Correct 23 ms 384 KB Output is correct
27 Correct 17 ms 384 KB Output is correct
28 Correct 18 ms 384 KB Output is correct
29 Correct 53 ms 384 KB Output is correct
30 Correct 53 ms 384 KB Output is correct
31 Correct 50 ms 384 KB Output is correct
32 Correct 54 ms 392 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 13 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 12 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 13 ms 384 KB Output is correct
50 Correct 24 ms 384 KB Output is correct
51 Correct 13 ms 384 KB Output is correct
52 Correct 23 ms 288 KB Output is correct
53 Correct 13 ms 384 KB Output is correct
54 Correct 25 ms 384 KB Output is correct
55 Correct 13 ms 384 KB Output is correct
56 Correct 27 ms 384 KB Output is correct
57 Correct 13 ms 384 KB Output is correct
58 Correct 25 ms 384 KB Output is correct
59 Correct 36 ms 384 KB Output is correct
60 Correct 41 ms 384 KB Output is correct
61 Correct 0 ms 384 KB Output is correct
62 Correct 0 ms 288 KB Output is correct
63 Correct 0 ms 384 KB Output is correct
64 Incorrect 17 ms 1024 KB Output isn't correct
65 Halted 0 ms 0 KB -