Submission #570635

#TimeUsernameProblemLanguageResultExecution timeMemory
570635cadmiumskyMP3 Player (CEOI10_mp3player)C++14
50 / 100
120 ms6656 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...