Submission #54129

# Submission time Handle Problem Language Result Execution time Memory
54129 2018-07-02T12:25:33 Z Bodo171 New Home (APIO18_new_home) C++14
12 / 100
3737 ms 59324 KB
#include <iostream>
#include <set>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
const int nmax=100005;
multiset<int> s[1000];
multiset<int>::iterator it1;
vector<int> v[3*nmax];
map<int,int> m;
int dp[10*nmax],norm[10*nmax],qq[10*nmax];
struct event
{
    int val,wh,mag,tip;
}ev[3*nmax];
int ans[nmax];
int ap[nmax];
int n,k,q,i,j,x,t,a,b,nr,X,mn;
bool compev(event unu,event doi)
{
    if(unu.val==doi.val) return unu.tip<doi.tip;
    return unu.val<doi.val;
}
int main()
{
    //freopen("data.in","r",stdin);
    cin>>n>>k>>q;
    if(n<=60000&&k<=400)
    {
        for(i=1; i<=n; i++)
        {
            cin>>x>>t>>a>>b;
            ev[++nr]= {a,x,t,1};
            ev[++nr]= {b+1,x,t,-1};
        }
        for(i=1; i<=q; i++)
        {
            cin>>x>>t;
            ev[++nr]= {t,x,i,2};
        }
        sort(ev+1,ev+nr+1,compev);
        for(i=1; i<=nr; i++)
        {
            if(ev[i].tip==1)
            {
                s[ev[i].mag].insert(ev[i].wh);
            }
            if(ev[i].tip==-1)
            {
                s[ev[i].mag].erase(s[ev[i].mag].lower_bound(ev[i].wh));
            }
            if(ev[i].tip==2)
            {
                X=ev[i].wh;
                for(j=1; j<=k&&ans[ev[i].mag]!=-1; j++)
                {
                    if(s[j].empty()) ans[ev[i].mag]=-1;
                    else
                    {
                        mn=1000*1000*100+1;
                        it1=s[j].lower_bound(X);
                        if(it1!=s[j].end()) mn=min(mn,(*it1)-X);
                        if(it1!=s[j].begin())
                        {
                            it1--;
                            mn=min(mn,X-(*it1));
                        }
                        ans[ev[i].mag]=max(ans[ev[i].mag],mn);
                    }
                }
            }
        }
        for(i=1; i<=q; i++)
            cout<<ans[i]<<'\n';
        return 0;
    }
    for(i=1;i<=n;i++)
    {
        cin>>x>>t>>a>>b;
        v[t].push_back(x);
        norm[++nr]=x;
    }
    for(i=1;i<=q;i++)
    {
        cin>>qq[i]>>t;
        norm[++nr]=t;
    }
    sort(norm+1,norm+nr+1);
    for(i=1;i<=nr;i++)
        m[norm[i]]=i;
    bool bus=0;
    int st,dr,poz,p,med;
    for(i=1;i<=k;i++)
    {
        if(v[i].empty())
          bus=1;
        else
        {
            sort(v[i].begin(),v[i].end());
            dp[1]=max(dp[1],v[i][0]-norm[1]);
            dp[nr]=max(dp[nr],norm[nr]-v[i].back());
            for(j=0;j<v[i].size()-1;j++)
            {
                st=v[i][j];dr=v[i][j+1];
                med=(v[i][j]+v[i][j+1])/2;poz=0;
                for(p=20;p>=0;p--)
                {
                    if(poz+(1<<p)<=nr&&norm[poz+(1<<p)]<=med) poz+=(1<<p);
                }
                dp[poz]=max(dp[poz],min(dr-norm[poz],norm[poz]-st));
                poz++;
                if(poz>=m[st]&&poz<=m[dr])dp[poz]=max(dp[poz],min(dr-norm[poz],norm[poz]-st));
                poz-=2;
               if(poz>=m[st]&&poz<=m[dr])dp[poz]=max(dp[poz],min(dr-norm[poz],norm[poz]-st));
            }
        }
    }
    for(i=2;i<=nr;i++)
        dp[i]=max(dp[i-1]-(norm[i]-norm[i-1]),dp[i]);
    for(i=nr-1;i>=1;i--)
        dp[i]=max(dp[i+1]-(norm[i+1]-norm[i]),dp[i]);
    for(i=1;i<=q;i++)
    {
        qq[i]=m[qq[i]];
        if(bus) cout<<"-1\n";
        else cout<<dp[qq[i]]<<'\n';
    }
    return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:104:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(j=0;j<v[i].size()-1;j++)
                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 7 ms 7448 KB Output is correct
3 Correct 9 ms 7452 KB Output is correct
4 Correct 7 ms 7640 KB Output is correct
5 Correct 10 ms 7664 KB Output is correct
6 Correct 9 ms 7664 KB Output is correct
7 Correct 10 ms 7672 KB Output is correct
8 Correct 10 ms 7672 KB Output is correct
9 Correct 9 ms 7672 KB Output is correct
10 Correct 9 ms 7672 KB Output is correct
11 Correct 9 ms 7672 KB Output is correct
12 Correct 9 ms 7672 KB Output is correct
13 Correct 9 ms 7676 KB Output is correct
14 Correct 12 ms 7680 KB Output is correct
15 Correct 9 ms 7680 KB Output is correct
16 Correct 10 ms 7680 KB Output is correct
17 Correct 12 ms 7680 KB Output is correct
18 Correct 9 ms 7680 KB Output is correct
19 Correct 10 ms 7680 KB Output is correct
20 Correct 9 ms 7680 KB Output is correct
21 Correct 10 ms 7680 KB Output is correct
22 Correct 9 ms 7680 KB Output is correct
23 Correct 9 ms 7680 KB Output is correct
24 Correct 10 ms 7680 KB Output is correct
25 Correct 10 ms 7680 KB Output is correct
26 Correct 10 ms 7724 KB Output is correct
27 Correct 10 ms 7724 KB Output is correct
28 Correct 10 ms 7724 KB Output is correct
29 Correct 10 ms 7724 KB Output is correct
30 Correct 9 ms 7724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 7 ms 7448 KB Output is correct
3 Correct 9 ms 7452 KB Output is correct
4 Correct 7 ms 7640 KB Output is correct
5 Correct 10 ms 7664 KB Output is correct
6 Correct 9 ms 7664 KB Output is correct
7 Correct 10 ms 7672 KB Output is correct
8 Correct 10 ms 7672 KB Output is correct
9 Correct 9 ms 7672 KB Output is correct
10 Correct 9 ms 7672 KB Output is correct
11 Correct 9 ms 7672 KB Output is correct
12 Correct 9 ms 7672 KB Output is correct
13 Correct 9 ms 7676 KB Output is correct
14 Correct 12 ms 7680 KB Output is correct
15 Correct 9 ms 7680 KB Output is correct
16 Correct 10 ms 7680 KB Output is correct
17 Correct 12 ms 7680 KB Output is correct
18 Correct 9 ms 7680 KB Output is correct
19 Correct 10 ms 7680 KB Output is correct
20 Correct 9 ms 7680 KB Output is correct
21 Correct 10 ms 7680 KB Output is correct
22 Correct 9 ms 7680 KB Output is correct
23 Correct 9 ms 7680 KB Output is correct
24 Correct 10 ms 7680 KB Output is correct
25 Correct 10 ms 7680 KB Output is correct
26 Correct 10 ms 7724 KB Output is correct
27 Correct 10 ms 7724 KB Output is correct
28 Correct 10 ms 7724 KB Output is correct
29 Correct 10 ms 7724 KB Output is correct
30 Correct 9 ms 7724 KB Output is correct
31 Correct 3737 ms 14088 KB Output is correct
32 Correct 204 ms 14088 KB Output is correct
33 Correct 348 ms 14088 KB Output is correct
34 Correct 2719 ms 14088 KB Output is correct
35 Correct 1595 ms 14252 KB Output is correct
36 Correct 387 ms 14252 KB Output is correct
37 Correct 314 ms 14252 KB Output is correct
38 Correct 228 ms 14252 KB Output is correct
39 Correct 213 ms 14252 KB Output is correct
40 Correct 267 ms 14252 KB Output is correct
41 Correct 488 ms 14252 KB Output is correct
42 Correct 398 ms 14252 KB Output is correct
43 Correct 590 ms 14268 KB Output is correct
44 Correct 460 ms 14268 KB Output is correct
45 Correct 278 ms 14268 KB Output is correct
46 Correct 202 ms 14268 KB Output is correct
47 Correct 193 ms 14268 KB Output is correct
48 Correct 192 ms 14268 KB Output is correct
49 Correct 207 ms 14268 KB Output is correct
50 Correct 440 ms 14268 KB Output is correct
51 Correct 270 ms 14268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2442 ms 59324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2376 ms 59324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 7 ms 7448 KB Output is correct
3 Correct 9 ms 7452 KB Output is correct
4 Correct 7 ms 7640 KB Output is correct
5 Correct 10 ms 7664 KB Output is correct
6 Correct 9 ms 7664 KB Output is correct
7 Correct 10 ms 7672 KB Output is correct
8 Correct 10 ms 7672 KB Output is correct
9 Correct 9 ms 7672 KB Output is correct
10 Correct 9 ms 7672 KB Output is correct
11 Correct 9 ms 7672 KB Output is correct
12 Correct 9 ms 7672 KB Output is correct
13 Correct 9 ms 7676 KB Output is correct
14 Correct 12 ms 7680 KB Output is correct
15 Correct 9 ms 7680 KB Output is correct
16 Correct 10 ms 7680 KB Output is correct
17 Correct 12 ms 7680 KB Output is correct
18 Correct 9 ms 7680 KB Output is correct
19 Correct 10 ms 7680 KB Output is correct
20 Correct 9 ms 7680 KB Output is correct
21 Correct 10 ms 7680 KB Output is correct
22 Correct 9 ms 7680 KB Output is correct
23 Correct 9 ms 7680 KB Output is correct
24 Correct 10 ms 7680 KB Output is correct
25 Correct 10 ms 7680 KB Output is correct
26 Correct 10 ms 7724 KB Output is correct
27 Correct 10 ms 7724 KB Output is correct
28 Correct 10 ms 7724 KB Output is correct
29 Correct 10 ms 7724 KB Output is correct
30 Correct 9 ms 7724 KB Output is correct
31 Correct 3737 ms 14088 KB Output is correct
32 Correct 204 ms 14088 KB Output is correct
33 Correct 348 ms 14088 KB Output is correct
34 Correct 2719 ms 14088 KB Output is correct
35 Correct 1595 ms 14252 KB Output is correct
36 Correct 387 ms 14252 KB Output is correct
37 Correct 314 ms 14252 KB Output is correct
38 Correct 228 ms 14252 KB Output is correct
39 Correct 213 ms 14252 KB Output is correct
40 Correct 267 ms 14252 KB Output is correct
41 Correct 488 ms 14252 KB Output is correct
42 Correct 398 ms 14252 KB Output is correct
43 Correct 590 ms 14268 KB Output is correct
44 Correct 460 ms 14268 KB Output is correct
45 Correct 278 ms 14268 KB Output is correct
46 Correct 202 ms 14268 KB Output is correct
47 Correct 193 ms 14268 KB Output is correct
48 Correct 192 ms 14268 KB Output is correct
49 Correct 207 ms 14268 KB Output is correct
50 Correct 440 ms 14268 KB Output is correct
51 Correct 270 ms 14268 KB Output is correct
52 Incorrect 323 ms 59324 KB Output isn't correct
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 7 ms 7448 KB Output is correct
3 Correct 9 ms 7452 KB Output is correct
4 Correct 7 ms 7640 KB Output is correct
5 Correct 10 ms 7664 KB Output is correct
6 Correct 9 ms 7664 KB Output is correct
7 Correct 10 ms 7672 KB Output is correct
8 Correct 10 ms 7672 KB Output is correct
9 Correct 9 ms 7672 KB Output is correct
10 Correct 9 ms 7672 KB Output is correct
11 Correct 9 ms 7672 KB Output is correct
12 Correct 9 ms 7672 KB Output is correct
13 Correct 9 ms 7676 KB Output is correct
14 Correct 12 ms 7680 KB Output is correct
15 Correct 9 ms 7680 KB Output is correct
16 Correct 10 ms 7680 KB Output is correct
17 Correct 12 ms 7680 KB Output is correct
18 Correct 9 ms 7680 KB Output is correct
19 Correct 10 ms 7680 KB Output is correct
20 Correct 9 ms 7680 KB Output is correct
21 Correct 10 ms 7680 KB Output is correct
22 Correct 9 ms 7680 KB Output is correct
23 Correct 9 ms 7680 KB Output is correct
24 Correct 10 ms 7680 KB Output is correct
25 Correct 10 ms 7680 KB Output is correct
26 Correct 10 ms 7724 KB Output is correct
27 Correct 10 ms 7724 KB Output is correct
28 Correct 10 ms 7724 KB Output is correct
29 Correct 10 ms 7724 KB Output is correct
30 Correct 9 ms 7724 KB Output is correct
31 Correct 3737 ms 14088 KB Output is correct
32 Correct 204 ms 14088 KB Output is correct
33 Correct 348 ms 14088 KB Output is correct
34 Correct 2719 ms 14088 KB Output is correct
35 Correct 1595 ms 14252 KB Output is correct
36 Correct 387 ms 14252 KB Output is correct
37 Correct 314 ms 14252 KB Output is correct
38 Correct 228 ms 14252 KB Output is correct
39 Correct 213 ms 14252 KB Output is correct
40 Correct 267 ms 14252 KB Output is correct
41 Correct 488 ms 14252 KB Output is correct
42 Correct 398 ms 14252 KB Output is correct
43 Correct 590 ms 14268 KB Output is correct
44 Correct 460 ms 14268 KB Output is correct
45 Correct 278 ms 14268 KB Output is correct
46 Correct 202 ms 14268 KB Output is correct
47 Correct 193 ms 14268 KB Output is correct
48 Correct 192 ms 14268 KB Output is correct
49 Correct 207 ms 14268 KB Output is correct
50 Correct 440 ms 14268 KB Output is correct
51 Correct 270 ms 14268 KB Output is correct
52 Incorrect 2442 ms 59324 KB Output isn't correct
53 Halted 0 ms 0 KB -