Submission #423583

# Submission time Handle Problem Language Result Execution time Memory
423583 2021-06-11T09:55:19 Z JvThunder Autobahn (COI21_autobahn) C++14
100 / 100
949 ms 64520 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
typedef long long ll;

using namespace std;

int n,k,z;
multiset<pair<pair<int,int>,int>> s;
vector<pair<pair<int,int>,int>> val;
void solve()
{
    cin >> n >> k >> z;
    set<int> all;
    for(int i=0;i<n;i++)
    {
        int l,t,r;
        cin >> l >> t >> r;
        s.insert({{l,l+t-1},0});
        s.insert({{l+t,r},1});
        all.insert(l-1);
        all.insert(max(1,l-z));
        all.insert(l);
        all.insert(max(1,l+t-z));
        all.insert(l+t-1);
        all.insert(l+t);
        all.insert(max(1,r-z+1));
        all.insert(r);
        all.insert(r+1);
    }

    priority_queue<pair<int,int>> pq;
    int cnt = 0;
    auto itr = s.begin();
    int prv = 0;
    for(auto x:all)
    {
        if(pq.size()>=k) val.pb({{prv,x-1},cnt});
        prv = x;

        while(itr!=s.end() && (*itr).fir.fir<=x)
        {
            if((*itr).sec==1) cnt++;
            pq.push({-(*itr).fir.sec,(*itr).sec});
            itr++;
        }

        while(!pq.empty() && -pq.top().fir<x)
        {
            if(pq.top().sec==1) cnt--;
            pq.pop();
        }
    }

    ll sum = 0;
    ll mxsum = 0;
    int ptr2 = -1;
    for(int ptr=0;ptr<val.size();ptr++)
    {
        while(ptr2+1<val.size() && val[ptr2+1].fir.sec<val[ptr].fir.fir+z)
        {
            ptr2++;
            sum += (ll)val[ptr2].sec*(val[ptr2].fir.sec-val[ptr2].fir.fir+1);
        }
        mxsum = max(mxsum,sum);
        sum -= (ll)val[ptr].sec*(val[ptr].fir.sec-val[ptr].fir.fir+1);
    }
    cout << mxsum << endl;

    return;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int tc=1;
	//cin>>tc;
	for(int i=1;i<=tc;i++) solve();
 	return 0;
}

Compilation message

autobahn.cpp: In function 'void solve()':
autobahn.cpp:40:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |         if(pq.size()>=k) val.pb({{prv,x-1},cnt});
      |            ~~~~~~~~~^~~
autobahn.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(int ptr=0;ptr<val.size();ptr++)
      |                   ~~~^~~~~~~~~~~
autobahn.cpp:62:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         while(ptr2+1<val.size() && val[ptr2+1].fir.sec<val[ptr].fir.fir+z)
      |               ~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 3 ms 408 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 3 ms 408 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 949 ms 61256 KB Output is correct
22 Correct 945 ms 63196 KB Output is correct
23 Correct 903 ms 64520 KB Output is correct
24 Correct 759 ms 56248 KB Output is correct
25 Correct 782 ms 58204 KB Output is correct
26 Correct 748 ms 55732 KB Output is correct
27 Correct 617 ms 50980 KB Output is correct
28 Correct 643 ms 51848 KB Output is correct
29 Correct 699 ms 52792 KB Output is correct