답안 #1002801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002801 2024-06-19T19:48:06 Z Cabralbonzao Autobahn (COI21_autobahn) C++17
100 / 100
119 ms 35448 KB
#include<bits/stdc++.h>
using namespace std;

#define N 200010
#define M 2000000020
#define pb push_back

typedef long long ll;
typedef pair<ll,ll> pll;

vector<pll>range;
set<ll>tests;
vector<ll>test;

struct event{
ll l,r,s;
};

vector<event>soma;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll n,k,x,i=0,l,t,r,pos,val,cur=0,s=0,ans=0,sz,curl,curr,resp=0,ql,qr;
 
    cin >> n >> k >> x;
    while(i<n)
    {
        cin >> l >> t >> r;
        range.pb({l,1});
        range.pb({r+1,-1});
        range.pb({l+t,2});
        range.pb({r+1,-2});
        i++;
    }
    sort(range.begin(),range.end());
    i=0;
    n*=4;
    range.pb({-1,0});
    while(i<n)
    {
        pos=range[i].first;
        while(range[i].first==pos)
        {
            val=range[i].second;
            if(val==1)
                cur++;
            if(val==-1)
                cur--;
            if(val==2)
                s++;
            if(val==-2)
                s--;
            i++;
        }
        if(cur>=k)
        {
            r=range[i].first-1;
            soma.pb({pos,r,s});
            tests.insert(pos);
            tests.insert(max(1LL,r-x+1));
        }
    }
    for(auto t : tests)
        test.pb(t);
    curl=0;
    curr=0;
    ql=0;
    qr=0;
    t=0;
    cur=0;
    soma.pb({0,M,0});
    sz=tests.size();
    while(t<sz)
    {
        l=test[t]-1;
        r=test[t]+x-1;
        while(curr<r)
        {
            if(soma[qr].r>r)
            {
                resp+=max(0LL,(r-max(soma[qr].l-1,curr))*soma[qr].s);
                curr=r;
                break;
            }
            resp+=max(0LL,(soma[qr].r-max(soma[qr].l-1,curr))*soma[qr].s);
            curr=soma[qr].r;
            qr++;
        }
        while(curl<l)
        {
            if(soma[ql].r>l)
            {
                resp-=max(0LL,(l-max(soma[ql].l-1,curl))*soma[ql].s);
                curl=l;
                break;
            }
            resp-=max(0LL,(soma[ql].r-max(soma[ql].l-1,curl))*soma[ql].s);
            curl=soma[ql].r;
            ql++;
        }
        ans=max(ans,resp);
        t++;
    }
    cout << ans << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 110 ms 35448 KB Output is correct
22 Correct 105 ms 35248 KB Output is correct
23 Correct 104 ms 35252 KB Output is correct
24 Correct 93 ms 27828 KB Output is correct
25 Correct 119 ms 31824 KB Output is correct
26 Correct 92 ms 27064 KB Output is correct
27 Correct 86 ms 24752 KB Output is correct
28 Correct 91 ms 24752 KB Output is correct
29 Correct 91 ms 24680 KB Output is correct