Submission #570635

# Submission time Handle Problem Language Result Execution time Memory
570635 2022-05-30T20:11:31 Z cadmiumsky MP3 Player (CEOI10_mp3player) C++14
50 / 100
120 ms 6656 KB
#include <bits/stdc++.h>

using namespace std;

const int nmax = 1e5 + 5;
int v[nmax], dt[nmax];
int n, vmax, v2;

namespace AINT {
  struct Node {
    int pmax = 0, pmin = 0, sum = 0; 
    Node(int val = 0): pmax(max(val, 0)), pmin(min(0, val)), sum(val) {;} 
    Node(int a, int b, int c): pmax(a), pmin(b), sum(c) {;}    
    Node operator + (const Node& x) const {
      return Node(min(vmax, max(pmax, x.pmax + sum)), max(-vmax, min(pmin, x.pmin + sum)), min(vmax, max(-vmax,sum + x.sum)));
    }
  };
  Node aint[nmax * 4];
  void upd(int poz, int node = 1, int cl = 1, int cr = n) {
    if(cl == cr) {
      aint[node] = Node(0);
      return;
    }
    int mid = cl + cr >> 1;
    if(poz <= mid)
      upd(poz, 2 * node, cl, mid);
    else
      upd(poz, 2 * node + 1, mid + 1, cr);
    aint[node] = aint[2 * node] + aint[2 * node + 1];
  }
  Node construct(int node = 1, int cl = 1, int cr = n) {
    if(cl == cr)
      return aint[node] = Node(v[cl]);
    int mid = cl + cr >> 1;
    return aint[node] = construct(2 * node, cl, mid) + construct(2 * node + 1, mid + 1, cr);
  }
  int getans() {
    int l = -aint[1].pmin, r = vmax - aint[1].pmax, delta = aint[1].sum;
    if(l > r && vmax + delta == v2)
      return vmax;
    if(l <= v2 - delta && v2 - delta <= r)
      return (v2 - delta == r? vmax : v2 - delta);
    return -1;
  }
};
int main() {
  cin >> n >> vmax >> v2;
  char ch;
  int lastt = 0;
  for(int i = 0, t; i < n; i++) {
    cin >> ch >> t;
    v[i] = (ch == '-'? -1 : 1);
    dt[i] = t - lastt;
    lastt = t;
  }
  --n;
  AINT::construct();
  
  vector<int> index(n), values(n);
  iota(index.begin(),  index.end(), 1);
  sort(index.begin(), index.end(), [&](int a, int b) { return dt[a] > dt[b]; });
  iota(values.begin(),  values.end(), 1);
  for(auto &x : values)
    x = dt[x];
  sort(values.begin(), values.end(), greater<int>());
  values.resize(unique(values.begin(), values.end()) - values.begin());
  //for(auto x : values)
    //cout << x << ' ';
  //cout << '\n';
  
  int ptr = 0, inf = 0;
  for(auto x : values) {
    while(ptr < index.size() && dt[index[ptr]] == x)
      AINT::upd(index[ptr]), ptr++;
    int temp = AINT::getans();
    if(temp != -1) {
      if(inf == 0)
        cout << "infinity\n";
      else
        cout << x - 1 << ' ' << temp << '\n';
      return 0;
    }
    inf = 1;
  }
  cout << "0 " << v2 << '\n';
}

Compilation message

mp3player.cpp: In function 'void AINT::upd(int, int, int, int)':
mp3player.cpp:24:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
mp3player.cpp: In function 'AINT::Node AINT::construct(int, int, int)':
mp3player.cpp:34:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
mp3player.cpp: In function 'int main()':
mp3player.cpp:73:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     while(ptr < index.size() && dt[index[ptr]] == x)
      |           ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4948 KB Output is correct
2 Correct 5 ms 4948 KB Output is correct
3 Correct 5 ms 5024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Incorrect 3 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4948 KB Output is correct
2 Correct 9 ms 5076 KB Output is correct
3 Correct 6 ms 5004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 5296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 5396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 5452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 5700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 6656 KB Output is correct
2 Correct 100 ms 6552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 6460 KB Output is correct
2 Correct 80 ms 6452 KB Output is correct