Submission #1108444

# Submission time Handle Problem Language Result Execution time Memory
1108444 2024-11-04T07:02:34 Z simona1230 New Home (APIO18_new_home) C++17
12 / 100
5000 ms 48828 KB
#include <bits/stdc++.h>
using namespace std;

struct store
{
    int x,t,a,b;
    store() {}
    store(int _x,int _t,int _a,int _b)
    {
        x=_x;
        t=_t;
        a=_a;
        b=_b;
    }
};

struct hour
{
    int x,t,h,p;
    hour() {}
    hour(int _x,int _t,int _h,int _p)
    {
        x=_x;
        t=_t;
        h=_h;
        p=_p;
    }
};

int n,q,k;
store a[300001];
multiset<int> s[300001];
vector<hour> v;

bool cmp(hour h1,hour h2)
{
    if(h1.h==h2.h)return h1.p<h2.p;
    return h1.h<h2.h;
}

void read()
{
    cin>>n>>k>>q;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i].x>>a[i].t>>a[i].a>>a[i].b;
        v.push_back({a[i].x,a[i].t,a[i].a,1});
        v.push_back({a[i].x,a[i].t,a[i].b,3});
    }

    for(int i=1; i<=q; i++)
    {
        int x,y;
        cin>>x>>y;
        v.push_back({x,i,y,2});
    }

    sort(v.begin(),v.end(),cmp);
}

int ans[300001];

void solve()
{
    for(int i=0; i<v.size(); i++)
    {
        hour h=v[i];
        //cout<<h.x<<" "<<h.t<<" "<<h.p<<" "<<h.h<<endl;
        if(h.p==1)s[h.t].insert(h.x);
        else if(h.p==3)s[h.t].erase(s[h.t].find(h.x));
        else
        {
            int maxx=0;
            for(int j=1; j<=k; j++)
            {
                if(s[j].size()==0)
                {
                    maxx=-1;
                    break;
                }
                else
                {
                    auto it=s[j].end();it--;
                    //cout<<"! "<<j<<" "<<*it<<endl;
                    if(h.x>=*it)maxx=max(maxx,h.x-*it);
                    else
                    {
                        it=s[j].lower_bound(h.x);
                        int d=*it-h.x;
                        //cout<<"! "<<j<<" "<<*it<<" "<<h.x<<endl;
                        if(it!=s[j].begin())
                        {
                            it--;
                            d=min(d,h.x-*it);
                        }

                        maxx=max(maxx,d);
                    }
                }
            }

            ans[h.t]=maxx;
        }
    }

    for(int i=1; i<=q; i++)
        cout<<ans[i]<<endl;
}

int main()
{
    read();
    solve();
    return 0;
}

/*
4 2 1
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
9 4
*/

Compilation message

new_home.cpp: In function 'void solve()':
new_home.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<hour>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for(int i=0; i<v.size(); i++)
      |                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16840 KB Output is correct
2 Correct 4 ms 16820 KB Output is correct
3 Correct 3 ms 16720 KB Output is correct
4 Correct 4 ms 16888 KB Output is correct
5 Correct 5 ms 16720 KB Output is correct
6 Correct 6 ms 16848 KB Output is correct
7 Correct 5 ms 16720 KB Output is correct
8 Correct 6 ms 16720 KB Output is correct
9 Correct 5 ms 16720 KB Output is correct
10 Correct 4 ms 16720 KB Output is correct
11 Correct 5 ms 16720 KB Output is correct
12 Correct 5 ms 16720 KB Output is correct
13 Correct 4 ms 16720 KB Output is correct
14 Correct 5 ms 17008 KB Output is correct
15 Correct 7 ms 16720 KB Output is correct
16 Correct 5 ms 16836 KB Output is correct
17 Correct 4 ms 16720 KB Output is correct
18 Correct 4 ms 16736 KB Output is correct
19 Correct 4 ms 16720 KB Output is correct
20 Correct 5 ms 16892 KB Output is correct
21 Correct 5 ms 16844 KB Output is correct
22 Correct 4 ms 16720 KB Output is correct
23 Correct 4 ms 16720 KB Output is correct
24 Correct 5 ms 16720 KB Output is correct
25 Correct 5 ms 16888 KB Output is correct
26 Correct 5 ms 16832 KB Output is correct
27 Correct 4 ms 16720 KB Output is correct
28 Correct 6 ms 16720 KB Output is correct
29 Correct 6 ms 16720 KB Output is correct
30 Correct 5 ms 16720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16840 KB Output is correct
2 Correct 4 ms 16820 KB Output is correct
3 Correct 3 ms 16720 KB Output is correct
4 Correct 4 ms 16888 KB Output is correct
5 Correct 5 ms 16720 KB Output is correct
6 Correct 6 ms 16848 KB Output is correct
7 Correct 5 ms 16720 KB Output is correct
8 Correct 6 ms 16720 KB Output is correct
9 Correct 5 ms 16720 KB Output is correct
10 Correct 4 ms 16720 KB Output is correct
11 Correct 5 ms 16720 KB Output is correct
12 Correct 5 ms 16720 KB Output is correct
13 Correct 4 ms 16720 KB Output is correct
14 Correct 5 ms 17008 KB Output is correct
15 Correct 7 ms 16720 KB Output is correct
16 Correct 5 ms 16836 KB Output is correct
17 Correct 4 ms 16720 KB Output is correct
18 Correct 4 ms 16736 KB Output is correct
19 Correct 4 ms 16720 KB Output is correct
20 Correct 5 ms 16892 KB Output is correct
21 Correct 5 ms 16844 KB Output is correct
22 Correct 4 ms 16720 KB Output is correct
23 Correct 4 ms 16720 KB Output is correct
24 Correct 5 ms 16720 KB Output is correct
25 Correct 5 ms 16888 KB Output is correct
26 Correct 5 ms 16832 KB Output is correct
27 Correct 4 ms 16720 KB Output is correct
28 Correct 6 ms 16720 KB Output is correct
29 Correct 6 ms 16720 KB Output is correct
30 Correct 5 ms 16720 KB Output is correct
31 Correct 1853 ms 24344 KB Output is correct
32 Correct 161 ms 24000 KB Output is correct
33 Correct 258 ms 24784 KB Output is correct
34 Correct 1352 ms 25480 KB Output is correct
35 Correct 924 ms 26032 KB Output is correct
36 Correct 318 ms 25072 KB Output is correct
37 Correct 259 ms 24760 KB Output is correct
38 Correct 201 ms 22968 KB Output is correct
39 Correct 194 ms 24936 KB Output is correct
40 Correct 204 ms 24504 KB Output is correct
41 Correct 290 ms 23224 KB Output is correct
42 Correct 262 ms 24760 KB Output is correct
43 Correct 348 ms 26620 KB Output is correct
44 Correct 309 ms 24324 KB Output is correct
45 Correct 224 ms 24804 KB Output is correct
46 Correct 188 ms 25088 KB Output is correct
47 Correct 179 ms 23840 KB Output is correct
48 Correct 188 ms 25272 KB Output is correct
49 Correct 190 ms 25016 KB Output is correct
50 Correct 310 ms 25016 KB Output is correct
51 Correct 200 ms 25016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5051 ms 48828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5063 ms 48668 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16840 KB Output is correct
2 Correct 4 ms 16820 KB Output is correct
3 Correct 3 ms 16720 KB Output is correct
4 Correct 4 ms 16888 KB Output is correct
5 Correct 5 ms 16720 KB Output is correct
6 Correct 6 ms 16848 KB Output is correct
7 Correct 5 ms 16720 KB Output is correct
8 Correct 6 ms 16720 KB Output is correct
9 Correct 5 ms 16720 KB Output is correct
10 Correct 4 ms 16720 KB Output is correct
11 Correct 5 ms 16720 KB Output is correct
12 Correct 5 ms 16720 KB Output is correct
13 Correct 4 ms 16720 KB Output is correct
14 Correct 5 ms 17008 KB Output is correct
15 Correct 7 ms 16720 KB Output is correct
16 Correct 5 ms 16836 KB Output is correct
17 Correct 4 ms 16720 KB Output is correct
18 Correct 4 ms 16736 KB Output is correct
19 Correct 4 ms 16720 KB Output is correct
20 Correct 5 ms 16892 KB Output is correct
21 Correct 5 ms 16844 KB Output is correct
22 Correct 4 ms 16720 KB Output is correct
23 Correct 4 ms 16720 KB Output is correct
24 Correct 5 ms 16720 KB Output is correct
25 Correct 5 ms 16888 KB Output is correct
26 Correct 5 ms 16832 KB Output is correct
27 Correct 4 ms 16720 KB Output is correct
28 Correct 6 ms 16720 KB Output is correct
29 Correct 6 ms 16720 KB Output is correct
30 Correct 5 ms 16720 KB Output is correct
31 Correct 1853 ms 24344 KB Output is correct
32 Correct 161 ms 24000 KB Output is correct
33 Correct 258 ms 24784 KB Output is correct
34 Correct 1352 ms 25480 KB Output is correct
35 Correct 924 ms 26032 KB Output is correct
36 Correct 318 ms 25072 KB Output is correct
37 Correct 259 ms 24760 KB Output is correct
38 Correct 201 ms 22968 KB Output is correct
39 Correct 194 ms 24936 KB Output is correct
40 Correct 204 ms 24504 KB Output is correct
41 Correct 290 ms 23224 KB Output is correct
42 Correct 262 ms 24760 KB Output is correct
43 Correct 348 ms 26620 KB Output is correct
44 Correct 309 ms 24324 KB Output is correct
45 Correct 224 ms 24804 KB Output is correct
46 Correct 188 ms 25088 KB Output is correct
47 Correct 179 ms 23840 KB Output is correct
48 Correct 188 ms 25272 KB Output is correct
49 Correct 190 ms 25016 KB Output is correct
50 Correct 310 ms 25016 KB Output is correct
51 Correct 200 ms 25016 KB Output is correct
52 Correct 205 ms 25928 KB Output is correct
53 Correct 205 ms 24516 KB Output is correct
54 Correct 239 ms 23984 KB Output is correct
55 Execution timed out 5070 ms 25272 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16840 KB Output is correct
2 Correct 4 ms 16820 KB Output is correct
3 Correct 3 ms 16720 KB Output is correct
4 Correct 4 ms 16888 KB Output is correct
5 Correct 5 ms 16720 KB Output is correct
6 Correct 6 ms 16848 KB Output is correct
7 Correct 5 ms 16720 KB Output is correct
8 Correct 6 ms 16720 KB Output is correct
9 Correct 5 ms 16720 KB Output is correct
10 Correct 4 ms 16720 KB Output is correct
11 Correct 5 ms 16720 KB Output is correct
12 Correct 5 ms 16720 KB Output is correct
13 Correct 4 ms 16720 KB Output is correct
14 Correct 5 ms 17008 KB Output is correct
15 Correct 7 ms 16720 KB Output is correct
16 Correct 5 ms 16836 KB Output is correct
17 Correct 4 ms 16720 KB Output is correct
18 Correct 4 ms 16736 KB Output is correct
19 Correct 4 ms 16720 KB Output is correct
20 Correct 5 ms 16892 KB Output is correct
21 Correct 5 ms 16844 KB Output is correct
22 Correct 4 ms 16720 KB Output is correct
23 Correct 4 ms 16720 KB Output is correct
24 Correct 5 ms 16720 KB Output is correct
25 Correct 5 ms 16888 KB Output is correct
26 Correct 5 ms 16832 KB Output is correct
27 Correct 4 ms 16720 KB Output is correct
28 Correct 6 ms 16720 KB Output is correct
29 Correct 6 ms 16720 KB Output is correct
30 Correct 5 ms 16720 KB Output is correct
31 Correct 1853 ms 24344 KB Output is correct
32 Correct 161 ms 24000 KB Output is correct
33 Correct 258 ms 24784 KB Output is correct
34 Correct 1352 ms 25480 KB Output is correct
35 Correct 924 ms 26032 KB Output is correct
36 Correct 318 ms 25072 KB Output is correct
37 Correct 259 ms 24760 KB Output is correct
38 Correct 201 ms 22968 KB Output is correct
39 Correct 194 ms 24936 KB Output is correct
40 Correct 204 ms 24504 KB Output is correct
41 Correct 290 ms 23224 KB Output is correct
42 Correct 262 ms 24760 KB Output is correct
43 Correct 348 ms 26620 KB Output is correct
44 Correct 309 ms 24324 KB Output is correct
45 Correct 224 ms 24804 KB Output is correct
46 Correct 188 ms 25088 KB Output is correct
47 Correct 179 ms 23840 KB Output is correct
48 Correct 188 ms 25272 KB Output is correct
49 Correct 190 ms 25016 KB Output is correct
50 Correct 310 ms 25016 KB Output is correct
51 Correct 200 ms 25016 KB Output is correct
52 Execution timed out 5051 ms 48828 KB Time limit exceeded
53 Halted 0 ms 0 KB -