Submission #866095

# Submission time Handle Problem Language Result Execution time Memory
866095 2023-10-25T12:09:12 Z byunjaewoo MP3 Player (CEOI10_mp3player) C++17
10 / 100
49 ms 13008 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int Nmax=100010, S=(1<<17);
int N, M, K, ans1, ans2;
int A[Nmax], B[Nmax];
vector<pair<int, int>> V;

class Seg {
public:
    struct Data {int l, r, lo, hi;}Tree[2*S];
    void Reset() { for(int i=1; i<2*S; i++) Tree[i]={0, M, 0, M}; }
    Data Merge(Data a, Data b) {
        Data ret;
        if(b.lo<=a.l) ret.lo=a.lo;
        else if(b.lo<=a.r) ret.lo=a.lo+(b.lo-a.l);
        else ret.lo=a.hi;
        if(b.hi<=a.l) ret.hi=a.lo;
        else if(b.hi<=a.r) ret.hi=a.lo+(b.hi-a.l);
        else ret.hi=a.hi;
        if(b.lo<=a.l) ret.l=b.l+(a.l-b.lo);
        else if(b.lo<=a.r) ret.l=b.l;
        else ret.l=1;
        ret.r=ret.l+(ret.hi-ret.lo);
        return ret;
    }
    void Update(int k, int v) {Update(1, 1, S, k, v);}
    void Update(int node, int s, int e, int k, int v) {
        if(s==e) {
            if(v==1) Tree[node]={0, M-1, 1, M};
            else Tree[node]={1, M, 0, M-1};
            return;
        }
        int lch=2*node, rch=lch+1, m=(s+e)/2;
        if(k<=m) Update(lch, s, m, k, v);
        else Update(rch, m+1, e, k, v);
        Tree[node]=Merge(Tree[rch], Tree[lch]);
    }
}T;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>M>>K;
    for(int i=1; i<=N; i++) {
        char op; cin>>op;
        if(op=='+') A[i]=1;
        else A[i]=-1;
        cin>>B[i];
    }
    for(int i=1; i<=N; i++) V.push_back({B[i]-B[i-1], i});
    sort(V.begin(), V.end());
    T.Reset();
    ans1=V[0].first-1, ans2=K;
    for(int i=0; i<V.size(); i++) {
        int p=i;
        for(int j=i; j<V.size() && V[i].first==V[j].first; j++) {
            T.Update(V[j].second, A[V[j].second]), p=j;
        }
        i=p;
        if(T.Tree[1].lo<=K && K<=T.Tree[1].hi) {
            if(i==V.size()-1) {
                cout<<"infinity"; return 0;
            }
            ans1=V[i+1].first-1;
            if(K==T.Tree[1].hi) ans2=M;
            else ans2=T.Tree[1].l+(K-T.Tree[1].lo);
        }
    }
    cout<<ans1<<" "<<ans2;
    return 0;
}

Compilation message

mp3player.cpp: In function 'int main()':
mp3player.cpp:55:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i=0; i<V.size(); i++) {
      |                  ~^~~~~~~~~
mp3player.cpp:57:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for(int j=i; j<V.size() && V[i].first==V[j].first; j++) {
      |                      ~^~~~~~~~~
mp3player.cpp:62:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             if(i==V.size()-1) {
      |                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 8792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 8964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 9696 KB Output is correct
2 Incorrect 9 ms 9696 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9692 KB Output is correct
2 Correct 9 ms 9828 KB Output is correct
3 Correct 9 ms 9692 KB Output is correct
4 Correct 10 ms 9704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 10204 KB Output is correct
2 Correct 12 ms 9944 KB Output is correct
3 Incorrect 12 ms 10204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 10712 KB Output is correct
2 Incorrect 16 ms 10616 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 13008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 13004 KB Output isn't correct
2 Halted 0 ms 0 KB -