답안 #570618

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570618 2022-05-30T18:11:29 Z cadmiumsky MP3 Player (CEOI10_mp3player) C++14
50 / 100
95 ms 7848 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(max(pmax, x.pmax + sum), min(pmin, x.pmin + sum), 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 <= 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:71:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     while(ptr < index.size() && dt[index[ptr]] == x)
      |           ~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 5004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5012 KB Output is correct
2 Correct 5 ms 5040 KB Output is correct
3 Correct 6 ms 5012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Incorrect 4 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5076 KB Output is correct
2 Correct 6 ms 5076 KB Output is correct
3 Correct 6 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 5544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 5656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 5780 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 6284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 7608 KB Output is correct
2 Correct 91 ms 7848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 7692 KB Output is correct
2 Correct 81 ms 7828 KB Output is correct