Submission #1003016

# Submission time Handle Problem Language Result Execution time Memory
1003016 2024-06-20T01:09:31 Z hyakup Autobahn (COI21_autobahn) C++17
100 / 100
89 ms 16584 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
const int inf = 1e9 + 10;

struct evento{
  int x, type, id; evento( int x = -inf, int type = 0, int id = 0 ) : x(x), type(type), id(id) {}
  bool operator < ( evento e ){
    if( x == e.x ) type < e.type;
    return x < e.x;
  }
}; vector<evento> line(1);

const int maxn = 1e5 + 10;
vector<ll> resp( 2*maxn, -1 );

int main(){
  ios::sync_with_stdio(false); cin.tie(NULL);
  int n, k, x; cin >> n >> k >> x;
  for( int i = 1; i <= n; i++ ){
    int l, t, r; cin >> l >> t >> r;
    line.push_back( evento( l - 1, 1, 0 ) );
    line.push_back( evento( l + t - 1, 2, 0 ) );

    line.push_back( evento( r - x, 3, 2*i ) );
    line.push_back( evento( r, 3, 2*i ) );

    line.push_back( evento( l + t - 1, 3, 2*i + 1 ) );
    line.push_back( evento( l + t + x - 1, 3, 2*i + 1 ) );

    line.push_back( evento( r, 4, 0 ) );
  }
  sort( line.begin(), line.end() );

  ll ativos = 0, criticos = 0;
  ll sum = 0;
  ll ans = 0;
  for(int i = 1; i < line.size(); i++ ){
    if( ativos >= k ) sum += 1LL*criticos*(line[i].x - line[i - 1].x );
    auto cur = line[i];
    if( cur.type == 1 ) ativos++;
    if( cur.type == 2 ) criticos++;
    if( cur.type == 3 ){
      if( resp[cur.id] == -1 ) resp[cur.id] = sum;
      else ans = max( ans, sum - resp[cur.id] );
    }
    if( cur.type == 4 ){
        ativos--;
        criticos--;
    }
  }
  cout << ans << endl;
}

Compilation message

autobahn.cpp: In member function 'bool evento::operator<(evento)':
autobahn.cpp:10:25: warning: statement has no effect [-Wunused-value]
   10 |     if( x == e.x ) type < e.type;
      |                    ~~~~~^~~~~~~~
autobahn.cpp: In function 'int main()':
autobahn.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<evento>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for(int i = 1; i < line.size(); i++ ){
      |                  ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1880 KB Output is correct
10 Correct 1 ms 2036 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1880 KB Output is correct
10 Correct 1 ms 2036 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 2 ms 2140 KB Output is correct
13 Correct 1 ms 2140 KB Output is correct
14 Correct 1 ms 2140 KB Output is correct
15 Correct 2 ms 2040 KB Output is correct
16 Correct 1 ms 2140 KB Output is correct
17 Correct 1 ms 2140 KB Output is correct
18 Correct 1 ms 2140 KB Output is correct
19 Correct 1 ms 2140 KB Output is correct
20 Correct 1 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1884 KB Output is correct
2 Correct 1 ms 1884 KB Output is correct
3 Correct 1 ms 1884 KB Output is correct
4 Correct 1 ms 1884 KB Output is correct
5 Correct 1 ms 1884 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 1 ms 1884 KB Output is correct
8 Correct 1 ms 1884 KB Output is correct
9 Correct 1 ms 1880 KB Output is correct
10 Correct 1 ms 2036 KB Output is correct
11 Correct 1 ms 1884 KB Output is correct
12 Correct 2 ms 2140 KB Output is correct
13 Correct 1 ms 2140 KB Output is correct
14 Correct 1 ms 2140 KB Output is correct
15 Correct 2 ms 2040 KB Output is correct
16 Correct 1 ms 2140 KB Output is correct
17 Correct 1 ms 2140 KB Output is correct
18 Correct 1 ms 2140 KB Output is correct
19 Correct 1 ms 2140 KB Output is correct
20 Correct 1 ms 2140 KB Output is correct
21 Correct 89 ms 16584 KB Output is correct
22 Correct 85 ms 16584 KB Output is correct
23 Correct 80 ms 16480 KB Output is correct
24 Correct 81 ms 16576 KB Output is correct
25 Correct 81 ms 16584 KB Output is correct
26 Correct 81 ms 16572 KB Output is correct
27 Correct 76 ms 16576 KB Output is correct
28 Correct 81 ms 16464 KB Output is correct
29 Correct 80 ms 16564 KB Output is correct